Skip to content

Commit

Permalink
ci: use afterEach hook to fail fast
Browse files Browse the repository at this point in the history
  • Loading branch information
fgnass committed Dec 24, 2024
1 parent 790e824 commit 137b289
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
43 changes: 21 additions & 22 deletions cypress/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,40 @@ 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 =
machineIndex === machineCount
? 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();
6 changes: 6 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ addMatchImageSnapshotCommand({
Cypress.on('uncaught:exception', () => false);

import './commands';

afterEach(function () {
if (this.currentTest.state === 'failed') {
Cypress.runner.stop();
}
});

0 comments on commit 137b289

Please sign in to comment.