forked from Klaveness-Digital/cypress-cucumber-preprocessor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cypress-tags.js
executable file
·61 lines (50 loc) · 1.88 KB
/
cypress-tags.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
const { Parser } = require("gherkin");
const glob = require("glob");
const fs = require("fs");
const { execFileSync } = require("child_process");
const { shouldProceedCurrentStep } = require("./lib/tagsHelper");
// TODO currently we only work with feature files in cypress/integration folder.
// It should be easy to base this on the cypress.json configuration - we are happy to take a PR
// here if you need this functionality!
const paths = glob.sync("cypress/integration/**/*.feature");
const featuresToRun = [];
const debug = (message, ...rest) =>
process.env.DEBUG
? console.log(`DEBUG: ${message}`, rest.length ? rest : "")
: null;
const found = process.argv.slice(2).find(arg => arg.indexOf("TAGS=") === 0);
const envTags = found.replace(/.*=/, "");
debug("Found tag expression", envTags);
paths.forEach(featurePath => {
const spec = `${fs.readFileSync(featurePath)}`;
const parsedFeature = new Parser().parse(spec);
const featureTags = parsedFeature.feature.tags;
const featureShouldRun = shouldProceedCurrentStep(featureTags, envTags);
const taggedScenarioShouldRun = parsedFeature.feature.children.some(
section =>
section.tags &&
section.tags.length &&
shouldProceedCurrentStep(section.tags.concat(featureTags), envTags)
);
debug(
`Feature: ${featurePath}, featureShouldRun: ${featureShouldRun}, taggedScenarioShouldRun: ${taggedScenarioShouldRun}`
);
if (featureShouldRun || taggedScenarioShouldRun) {
featuresToRun.push(featurePath);
}
});
try {
execFileSync(
process.platform === "win32"
? `${__dirname}/../.bin/cypress.cmd`
: `${__dirname}/../.bin/cypress`,
[...process.argv.slice(2), "--spec", featuresToRun.join(",")],
{
stdio: [process.stdin, process.stdout, process.stderr]
}
);
} catch (e) {
debug("Error while running cypress (or just a test failure)", e);
process.exit(1);
}