forked from Klaveness-Digital/cypress-cucumber-preprocessor
-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from TheBrainFamily/pr/217
Add Ability to combine multiple feature files into one spec by Darrinholst
- Loading branch information
Showing
13 changed files
with
157 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
exports.cucumberTemplate = ` | ||
const { | ||
resolveAndRunStepDefinition, | ||
defineParameterType, | ||
given, | ||
when, | ||
then, | ||
and, | ||
but, | ||
Before, | ||
After, | ||
defineStep | ||
} = require("cypress-cucumber-preprocessor/lib/resolveStepDefinition"); | ||
const Given = (window.Given = window.given = given); | ||
const When = (window.When = window.when = when); | ||
const Then = (window.Then = window.then = then); | ||
const And = (window.And = window.and = and); | ||
const But = (window.But = window.but = but); | ||
window.defineParameterType = defineParameterType; | ||
window.defineStep = defineStep; | ||
const { | ||
createTestsFromFeature | ||
} = require("cypress-cucumber-preprocessor/lib/createTestsFromFeature"); | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const glob = require("glob"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const { Parser } = require("gherkin"); | ||
const log = require("debug")("cypress:cucumber"); | ||
|
||
const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths"); | ||
const { cucumberTemplate } = require("./cucumberTemplate"); | ||
const { getCucumberJsonConfig } = require("./getCucumberJsonConfig"); | ||
const { | ||
isNonGlobalStepDefinitionsMode | ||
} = require("./isNonGlobalStepDefinitionsMode"); | ||
|
||
const createCucumber = ( | ||
specs, | ||
globalToRequire, | ||
nonGlobalToRequire, | ||
cucumberJson | ||
) => | ||
` | ||
${cucumberTemplate} | ||
window.cucumberJson = ${JSON.stringify(cucumberJson)}; | ||
${globalToRequire.join("\n")} | ||
${specs | ||
.map( | ||
({ spec, filePath, name }) => ` | ||
describe(\`${name}\`, function() { | ||
${nonGlobalToRequire && | ||
nonGlobalToRequire | ||
.find(fileSteps => fileSteps[filePath]) | ||
[filePath].join("\n")} | ||
createTestsFromFeature('${path.basename(filePath)}', \`${spec}\`); | ||
}) | ||
` | ||
) | ||
.join("\n")} | ||
`; | ||
|
||
module.exports = function(_, filePath) { | ||
log("compiling", filePath); | ||
|
||
const features = glob.sync(`${path.dirname(filePath)}/**/*.feature`); | ||
|
||
let globalStepDefinitionsToRequire = []; | ||
let nonGlobalStepDefinitionsToRequire; | ||
|
||
if (isNonGlobalStepDefinitionsMode()) { | ||
nonGlobalStepDefinitionsToRequire = features.map(featurePath => ({ | ||
[featurePath]: getStepDefinitionsPaths(featurePath).map( | ||
sdPath => `require('${sdPath}')` | ||
) | ||
})); | ||
} else { | ||
globalStepDefinitionsToRequire = [ | ||
...new Set( | ||
features.reduce( | ||
requires => | ||
requires.concat( | ||
getStepDefinitionsPaths(filePath).map( | ||
sdPath => `require('${sdPath}')` | ||
) | ||
), | ||
[] | ||
) | ||
) | ||
]; | ||
} | ||
|
||
const specs = features | ||
.map(featurePath => ({ | ||
spec: fs.readFileSync(featurePath).toString(), | ||
filePath: featurePath | ||
})) | ||
.map(feature => | ||
Object.assign({}, feature, { | ||
name: new Parser().parse(feature.spec.toString()).feature.name | ||
}) | ||
); | ||
|
||
return createCucumber( | ||
specs, | ||
globalStepDefinitionsToRequire, | ||
nonGlobalStepDefinitionsToRequire, | ||
getCucumberJsonConfig() | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const cosmiconfig = require("cosmiconfig"); | ||
const log = require("debug")("cypress:cucumber"); | ||
|
||
exports.getCucumberJsonConfig = () => { | ||
const explorer = cosmiconfig("cypress-cucumber-preprocessor", { sync: true }); | ||
const loaded = explorer.load(); | ||
|
||
const cucumberJson = | ||
loaded && loaded.config && loaded.config.cucumberJson | ||
? loaded.config.cucumberJson | ||
: { generate: false }; | ||
log("cucumber.json", JSON.stringify(cucumberJson)); | ||
|
||
return cucumberJson; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const cosmiconfig = require("cosmiconfig"); | ||
|
||
exports.isNonGlobalStepDefinitionsMode = () => { | ||
const explorer = cosmiconfig("cypress-cucumber-preprocessor", { sync: true }); | ||
const loaded = explorer.load(); | ||
return loaded && loaded.config && loaded.config.nonGlobalStepDefinitions; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters