Skip to content

Instantly share code, notes, and snippets.

@devpie
Created February 18, 2021 12:53
Show Gist options
  • Save devpie/69bbcd78fad67953b6b2114b26fe0245 to your computer and use it in GitHub Desktop.
Save devpie/69bbcd78fad67953b6b2114b26fe0245 to your computer and use it in GitHub Desktop.
Run cucumber based cypress feature files in serial processes. (Who knows why i needed this :D)
#!/usr/bin/env node
/* tslint:disable:no-console */
const proc = require("child_process");
const find = require("find");
const path = require("path");
const projectDirectory = path.resolve(__dirname, "..");
let returnCodeSum = 0
const runFeatureTest = (featureFilename) => {
return proc.exec(
`npm t -- --spec ${featureFilename}`,
);
};
const runFeatureTests = (featureFiles) => {
const featureFilename = featureFiles.shift();
if (featureFilename) {
console.log(`Running Feature File: ${featureFilename}`)
const process = runFeatureTest(featureFilename);
process.on('exit', (code) => {
console.log(`Feature File ${featureFilename} ended with exit code ${code}`);
returnCodeSum = returnCodeSum + code;
runFeatureTests(featureFiles);
});
process.on('error', (error) => {
console.log(`${error}`);
});
process.stdout.on('data', (data) => {
console.log(data);
});
process.stderr.on('data', (data) => {
console.error(data);
})
} else {
if (returnCodeSum > 0) {
console.log(`Exiting with return code 1 because the returnCodeSum was ${returnCodeSum}`);
process.exit(1);
}
}
}
const main = (dir) => {
console.log("Sequential Test Runner");
let files = find.fileSync(/\.feature$/, `${dir}/cypress/integration`).sort();
runFeatureTests(files);
};
main(projectDirectory);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment