Skip to content

Commit

Permalink
Corrected parsing of passed environment variables for GLOB and TAGS (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
ojizero authored Jun 1, 2020
1 parent ff9d006 commit 8a5f032
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 104 deletions.
31 changes: 19 additions & 12 deletions cypress-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,35 @@ const debug = (message, ...rest) =>
? console.log(`DEBUG: ${message}`, rest.length ? rest : "")
: null;

function parseArgsOrDefault(argPrefix, defaultValue) {
const matchedArg = process.argv
.slice(2)
.find(arg => arg.includes(`${argPrefix}=`));

// Cypress requires env vars to be passed as comma separated list
// otherwise it only accepts the last provided variable,
// the way we replace here accomodates for that.
const argValue = matchedArg
? matchedArg.replace(new RegExp(`.*${argPrefix}=`), "").replace(/,.*/, "")
: "";

return argValue !== "" ? argValue : defaultValue;
}

// 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 defaultGlob = "cypress/integration/**/*.feature";

const specArg = process.argv.slice(2).find(arg => arg.indexOf("GLOB=") === 0);

const specGlob = specArg ? specArg.replace(/.*=/, "") : defaultGlob;

if (specArg) {
debug("Found glob", specGlob);
}
const specGlob = parseArgsOrDefault("GLOB", defaultGlob);
debug("Found glob", specGlob);
const envTags = parseArgsOrDefault("TAGS", "");
debug("Found tag expression", envTags);

const paths = glob.sync(specGlob);

const featuresToRun = [];

const found = process.argv.slice(2).find(arg => arg.indexOf("TAGS=") === 0);

const envTags = found ? found.replace(/.*=/, "") : "";
debug("Found tag expression", envTags);

paths.forEach(featurePath => {
const spec = `${fs.readFileSync(featurePath)}`;
const parsedFeature = new Parser().parse(spec);
Expand Down
Loading

0 comments on commit 8a5f032

Please sign in to comment.