chore: improve cypress runs on forks (#4924)

This commit is contained in:
Erez Rokah
2021-02-07 06:21:15 -08:00
committed by GitHub
parent 6998348de4
commit b913c8f745
3 changed files with 51 additions and 46 deletions

41
cypress/run.js Normal file
View File

@ -0,0 +1,41 @@
const execa = require('execa');
const globby = require('globby');
const runCypress = async () => {
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', '--spec', machineSpecs.join(',')],
{ stdio: 'inherit', preferLocal: true },
);
} else {
await execa(
'cypress',
[
'run',
'--browser',
'chrome',
'--headless',
'--record',
'--parallel',
'--ci-build-id',
process.env.GITHUB_SHA,
'--group',
'GitHub CI',
],
{ stdio: 'inherit', preferLocal: true },
);
}
};
runCypress().catch(error => console.error(error));