diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index e63dc9a40c2e..15d945ebcfc0 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -46,7 +46,7 @@ jobs: run: npm run build:demo - name: run e2e tests if: matrix.os == 'ubuntu-latest' && matrix.node-version == '20.x' - run: npm run test:e2e:run-ci -- --bail + run: npm run test:e2e:run-ci env: IS_FORK: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true || github.repository_owner != 'decaporg' }} CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} diff --git a/cypress/run.mjs b/cypress/run.mjs index 5046f662d0a0..dfc8235840b4 100644 --- a/cypress/run.mjs +++ b/cypress/run.mjs @@ -2,10 +2,17 @@ import execa from 'execa'; import { globby } from 'globby'; async function runCypress() { + const args = ['run', '--browser', 'chrome', '--headless']; + + const specs = await globby(['cypress/e2e/*spec*.js']); + if (specs.length === 0) { + console.log('No test files found in cypress/e2e/*spec*.js'); + process.exit(1); + } + if (process.env.IS_FORK === 'true') { const machineIndex = parseInt(process.env.MACHINE_INDEX); const machineCount = parseInt(process.env.MACHINE_COUNT); - const specs = await globby(['cypress/integration/*spec*.js']); const specsPerMachine = Math.floor(specs.length / machineCount); const start = (machineIndex - 1) * specsPerMachine; const machineSpecs = @@ -13,30 +20,22 @@ async function runCypress() { ? specs.slice(start) : specs.slice(start, start + specsPerMachine); - await execa( - 'cypress', - ['run', '--browser', 'chrome', '--headless', '--bail', '--spec', machineSpecs.join(',')], - { stdio: 'inherit', preferLocal: true }, - ); + args.push('--spec', machineSpecs.join(',')); } else { - await execa( - 'cypress', - [ - 'run', - '--browser', - 'chrome', - '--headless', - '--bail', - '--record', - '--parallel', - '--ci-build-id', - process.env.GITHUB_SHA, - '--group', - 'GitHub CI', - ], - { stdio: 'inherit', preferLocal: true }, + args.push( + '--record', + '--parallel', + '--ci-build-id', + process.env.GITHUB_SHA, + '--group', + 'GitHub CI', + '--spec', + specs.join(','), ); } + + console.log('Running Cypress with args:', args.join(' ')); + await execa('cypress', args, { stdio: 'inherit', preferLocal: true }); } runCypress(); diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 6504113e81ee..80fcca6176c2 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -26,3 +26,9 @@ addMatchImageSnapshotCommand({ Cypress.on('uncaught:exception', () => false); import './commands'; + +afterEach(function () { + if (this.currentTest.state === 'failed') { + Cypress.runner.stop(); + } +});