Skip to content

Commit df8066a

Browse files
arichard-infolgandecki
authored andcommitted
feat(tags): improve the tags behavior, to base the glob on the cypress.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
1 parent 7f4395b commit df8066a

File tree

1 file changed

+48
-8
lines changed

1 file changed

+48
-8
lines changed

cypress-tags.js

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const { Parser } = require("gherkin");
44
const glob = require("glob");
5+
const path = require("path");
56
const fs = require("fs");
67
const { execFileSync } = require("child_process");
78

@@ -28,17 +29,56 @@ function parseArgsOrDefault(argPrefix, defaultValue) {
2829
return argValue !== "" ? argValue : defaultValue;
2930
}
3031

31-
// TODO currently we only work with feature files in cypress/integration folder.
32-
// It should be easy to base this on the cypress.json configuration - we are happy to take a PR
33-
// here if you need this functionality!
34-
const defaultGlob = "cypress/integration/**/*.feature";
35-
36-
const specGlob = parseArgsOrDefault("GLOB", defaultGlob);
37-
debug("Found glob", specGlob);
32+
const envGlob = parseArgsOrDefault("GLOB", false);
33+
debug("Found glob", envGlob);
3834
const envTags = parseArgsOrDefault("TAGS", "");
3935
debug("Found tag expression", envTags);
4036

41-
const paths = glob.sync(specGlob);
37+
let defaultGlob = "cypress/integration/**/*.feature";
38+
let ignoreGlob = "";
39+
let usingCypressConf = true;
40+
41+
try {
42+
// TODO : curently we don't allow the override of the cypress.json path
43+
// maybe we can set this path in the plugin conf (package.json : "cypressConf": "test/cypress.json")
44+
const cypressConf = JSON.parse(fs.readFileSync(path.resolve("cypress.json")));
45+
const integrationFolder =
46+
cypressConf && cypressConf.integrationFolder
47+
? cypressConf.integrationFolder.replace(/\/$/, "")
48+
: "cypress/integration";
49+
50+
if (cypressConf && cypressConf.ignoreTestFiles) {
51+
ignoreGlob = cypressConf.ignoreTestFiles;
52+
}
53+
54+
if (cypressConf && cypressConf.testFiles) {
55+
let testFiles = !Array.isArray(cypressConf.testFiles)
56+
? cypressConf.testFiles.split(",")
57+
: cypressConf.testFiles;
58+
testFiles = testFiles.map(pattern => `${integrationFolder}/${pattern}`);
59+
defaultGlob = `{${testFiles.join(",")}}`;
60+
} else {
61+
defaultGlob = `${integrationFolder}/**/*.feature`;
62+
}
63+
} catch (err) {
64+
usingCypressConf = false;
65+
defaultGlob = "cypress/integration/**/*.feature";
66+
}
67+
68+
if (envGlob) usingCypressConf = false; // in this case, we ignore the Cypress conf
69+
70+
const specGlob = envGlob ? envGlob.replace(/.*=/, "") : defaultGlob;
71+
72+
if (envGlob) {
73+
debug("Found glob", specGlob);
74+
}
75+
76+
const paths = glob
77+
.sync(specGlob, {
78+
nodir: true,
79+
ignore: usingCypressConf ? ignoreGlob : ""
80+
})
81+
.filter(pathName => pathName.endsWith(".feature"));
4282

4383
const featuresToRun = [];
4484

0 commit comments

Comments
 (0)