22
33const { Parser } = require ( "gherkin" ) ;
44const glob = require ( "glob" ) ;
5+ const path = require ( "path" ) ;
56const fs = require ( "fs" ) ;
67const { 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 ) ;
3834const envTags = parseArgsOrDefault ( "TAGS" , "" ) ;
3935debug ( "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
4383const featuresToRun = [ ] ;
4484
0 commit comments