Skip to content

Instantly share code, notes, and snippets.

@vincenting
Created December 16, 2019 07:27
Show Gist options
  • Save vincenting/64f2ffc3cec318e099d9649c56a5c375 to your computer and use it in GitHub Desktop.
Save vincenting/64f2ffc3cec318e099d9649c56a5c375 to your computer and use it in GitHub Desktop.
Run cypress tests concurrently.
/* eslint-disable import/no-extraneous-dependencies */
const path = require('path');
const fs = require('fs');
const glob = require('glob');
const concurrently = require('concurrently');
const { promisify } = require('util');
const rand = `${Math.random()}`.substring(0, 10);
const CYPRESS_TMP_FILE = `./cypress.${rand}.json`;
const cypressArgv = process.argv
.slice(process.argv.indexOf(__filename) + 1)
.join(' ');
const removeTmpCypressFile = async () => {
try {
await promisify(fs.unlink)(CYPRESS_TMP_FILE);
// eslint-disable-next-line no-empty
} catch (e) {}
};
(async () => {
const cypressConfiguration = JSON.parse(
await promisify(fs.readFile)(path.join(process.cwd(), './cypress.json'))
);
await promisify(fs.writeFile)(
CYPRESS_TMP_FILE,
JSON.stringify({
...cypressConfiguration,
testFiles: undefined
})
);
const matchedFiles = glob.sync(cypressConfiguration.testFiles);
await concurrently(
matchedFiles.map(
testFile =>
`npx cypress ${cypressArgv} -C ${CYPRESS_TMP_FILE} --spec "${testFile}"`
)
);
removeTmpCypressFile();
process.exit(0);
})().catch(err => {
removeTmpCypressFile();
console.error(err); // eslint-disable-line no-console
process.exit(-1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment