Skip to content

Commit

Permalink
feat(tags): improve the tags behavior, to base the glob on the cypres…
Browse files Browse the repository at this point in the history
…s.json configuration

BREAKING CHANGE: Glob pattern is no longer "cypress/integration/**/*.feature", but is now based on
cypress.json configuration, and takes into account the ignoreTestFiles
  • Loading branch information
arichard-info authored and lgandecki committed Oct 16, 2020
1 parent 7f4395b commit df8066a
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions cypress-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { Parser } = require("gherkin");
const glob = require("glob");
const path = require("path");
const fs = require("fs");
const { execFileSync } = require("child_process");

Expand All @@ -28,17 +29,56 @@ function parseArgsOrDefault(argPrefix, defaultValue) {
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 specGlob = parseArgsOrDefault("GLOB", defaultGlob);
debug("Found glob", specGlob);
const envGlob = parseArgsOrDefault("GLOB", false);
debug("Found glob", envGlob);
const envTags = parseArgsOrDefault("TAGS", "");
debug("Found tag expression", envTags);

const paths = glob.sync(specGlob);
let defaultGlob = "cypress/integration/**/*.feature";
let ignoreGlob = "";
let usingCypressConf = true;

try {
// TODO : curently we don't allow the override of the cypress.json path
// maybe we can set this path in the plugin conf (package.json : "cypressConf": "test/cypress.json")
const cypressConf = JSON.parse(fs.readFileSync(path.resolve("cypress.json")));
const integrationFolder =
cypressConf && cypressConf.integrationFolder
? cypressConf.integrationFolder.replace(/\/$/, "")
: "cypress/integration";

if (cypressConf && cypressConf.ignoreTestFiles) {
ignoreGlob = cypressConf.ignoreTestFiles;
}

if (cypressConf && cypressConf.testFiles) {
let testFiles = !Array.isArray(cypressConf.testFiles)
? cypressConf.testFiles.split(",")
: cypressConf.testFiles;
testFiles = testFiles.map(pattern => `${integrationFolder}/${pattern}`);
defaultGlob = `{${testFiles.join(",")}}`;
} else {
defaultGlob = `${integrationFolder}/**/*.feature`;
}
} catch (err) {
usingCypressConf = false;
defaultGlob = "cypress/integration/**/*.feature";
}

if (envGlob) usingCypressConf = false; // in this case, we ignore the Cypress conf

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

if (envGlob) {
debug("Found glob", specGlob);
}

const paths = glob
.sync(specGlob, {
nodir: true,
ignore: usingCypressConf ? ignoreGlob : ""
})
.filter(pathName => pathName.endsWith(".feature"));

const featuresToRun = [];

Expand Down

0 comments on commit df8066a

Please sign in to comment.