Skip to content

Commit 8a5f032

Browse files
authored
Corrected parsing of passed environment variables for GLOB and TAGS (#352)
* fix(cypress-tags): corrected parsing of passed environment variables for GLOB and TAGS This sets it to respect how Cypress expect and behaves with this flag allowing us to pass environment varibles along side TAGS and GLOB and have all variables be properly passed to Cypress. fixes #335 * fix: corrected argument parsing * chore: apply @dallevon comments
1 parent ff9d006 commit 8a5f032

File tree

2 files changed

+53
-104
lines changed

2 files changed

+53
-104
lines changed

cypress-tags.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,35 @@ const debug = (message, ...rest) =>
1212
? console.log(`DEBUG: ${message}`, rest.length ? rest : "")
1313
: null;
1414

15+
function parseArgsOrDefault(argPrefix, defaultValue) {
16+
const matchedArg = process.argv
17+
.slice(2)
18+
.find(arg => arg.includes(`${argPrefix}=`));
19+
20+
// Cypress requires env vars to be passed as comma separated list
21+
// otherwise it only accepts the last provided variable,
22+
// the way we replace here accomodates for that.
23+
const argValue = matchedArg
24+
? matchedArg.replace(new RegExp(`.*${argPrefix}=`), "").replace(/,.*/, "")
25+
: "";
26+
27+
return argValue !== "" ? argValue : defaultValue;
28+
}
29+
1530
// TODO currently we only work with feature files in cypress/integration folder.
1631
// It should be easy to base this on the cypress.json configuration - we are happy to take a PR
1732
// here if you need this functionality!
1833
const defaultGlob = "cypress/integration/**/*.feature";
1934

20-
const specArg = process.argv.slice(2).find(arg => arg.indexOf("GLOB=") === 0);
21-
22-
const specGlob = specArg ? specArg.replace(/.*=/, "") : defaultGlob;
23-
24-
if (specArg) {
25-
debug("Found glob", specGlob);
26-
}
35+
const specGlob = parseArgsOrDefault("GLOB", defaultGlob);
36+
debug("Found glob", specGlob);
37+
const envTags = parseArgsOrDefault("TAGS", "");
38+
debug("Found tag expression", envTags);
2739

2840
const paths = glob.sync(specGlob);
2941

3042
const featuresToRun = [];
3143

32-
const found = process.argv.slice(2).find(arg => arg.indexOf("TAGS=") === 0);
33-
34-
const envTags = found ? found.replace(/.*=/, "") : "";
35-
debug("Found tag expression", envTags);
36-
3744
paths.forEach(featurePath => {
3845
const spec = `${fs.readFileSync(featurePath)}`;
3946
const parsedFeature = new Parser().parse(spec);

0 commit comments

Comments
 (0)