Skip to content

Commit

Permalink
refactor: e2e flaky tests #3477 (#3489)
Browse files Browse the repository at this point in the history
  • Loading branch information
benfurber authored May 8, 2024
2 parents 65a09f6 + 472a102 commit 084f6c4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/components/src/Loader/Loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const Loader = ({ label }: Props) => {
{logo && (
<RotatingLogo
loading="lazy"
data-cy="loader"
src={logo}
sx={{ width: [75, 75, 100] }}
/>
Expand Down
14 changes: 2 additions & 12 deletions packages/cypress/scripts/start.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ts-node
import { spawn, spawnSync } from 'child_process'

import { generateAlphaNumeric } from '../src/utils/TestUtils'
import PATHS from './paths'

const e2eEnv = require('dotenv').config()
Expand Down Expand Up @@ -53,7 +54,7 @@ function runTests() {
const CYPRESS_ENV = `DUMMY_VAR=1`
// use workflow ID so that jobs running in parallel can be assigned to same cypress build
// cypress will use this to split tests between parallel runs
const buildId = e.CIRCLE_WORKFLOW_ID || randomString(8)
const buildId = e.CIRCLE_WORKFLOW_ID || generateAlphaNumeric(8)

// main testing command, depending on whether running on ci machine or interactive local
// call with path to bin as to ensure locally installed used
Expand Down Expand Up @@ -134,14 +135,3 @@ async function startAppServer() {
const timeout = 5 * 60 * 1000
await waitOn({ resources: ['http-get://127.0.0.1:3456'], timeout })
}

function randomString(length) {
let result = ''
const characters =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
const charactersLength = characters.length
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength))
}
return result
}
2 changes: 2 additions & 0 deletions packages/cypress/src/integration/howto/write.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ describe('[How To]', () => {
const categoryGuidanceFiles = guidance.moulds.files

cy.login(creatorEmail, creatorPassword)
cy.get('[data-cy=loader]').should('not.exist')
cy.step('Access the create-how-to')
cy.get('[data-cy=create]').click()
cy.contains('Create a How-To').should('exist')
Expand Down Expand Up @@ -326,6 +327,7 @@ describe('[How To]', () => {
cy.on('window:confirm', stub)

cy.login(creatorEmail, creatorPassword)
cy.get('[data-cy=loader]').should('not.exist')
cy.step('Access the create-how-to')
cy.get('[data-cy=create]').click()
cy.get('[data-cy=intro-title]')
Expand Down
1 change: 1 addition & 0 deletions packages/cypress/src/integration/questions/write.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('[Question]', () => {
cy.login(creatorEmail, creatorPassword)

cy.step('Go to create page')
cy.get('[data-cy=loader]').should('not.exist')
cy.get('[data-cy=create]').click()
cy.get('[data-cy=question-create-title]')

Expand Down
2 changes: 2 additions & 0 deletions packages/cypress/src/integration/research/write.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('[Research]', () => {
it('[By Authenticated]', () => {
cy.login(researcherEmail, researcherPassword)
cy.step('Create the research article')
cy.get('[data-cy=loader]').should('not.exist')
cy.get('[data-cy=create]').click()
cy.step('Warn if title is identical to an existing one')
cy.get('[data-cy=intro-title]').type('qwerty').blur({ force: true })
Expand Down Expand Up @@ -108,6 +109,7 @@ describe('[Research]', () => {

cy.login(researcherEmail, researcherPassword)
cy.step('Access the create research article')
cy.get('[data-cy=loader]').should('not.exist')
cy.get('[data-cy=create]').click()
cy.get('[data-cy=intro-title')
.clear()
Expand Down
1 change: 1 addition & 0 deletions shared/mocks/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { questions } from './questions'
export { research } from './research'
export { tags } from './tags'
export { users } from './users'
export { messages } from './messages'
10 changes: 10 additions & 0 deletions shared/mocks/data/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const messages = {
'36hWyk3OckrLSH1ehdIE': {
_modified: '2012-10-27T01:47:57.948Z',
_id: '36hWyk3OckrLSH1ehdIE',
email: '[email protected]',
name: 'Bob',
text: 'Message test',
toUserName: 'settings_machine_new',
},
}

0 comments on commit 084f6c4

Please sign in to comment.