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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
61 additions
and
54 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
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,36 @@ | ||
/* eslint-disable no-eval */ | ||
const log = require("debug")("cypress:cucumber"); | ||
const glob = require("glob"); | ||
const stepDefinitionPath = require("./stepDefinitionPath.js"); | ||
|
||
// This is the template for the file that we will send back to cypress instead of the text of a | ||
// feature file | ||
const createCucumber = (spec, toRequire) => | ||
` | ||
const {resolveAndRunStepDefinition, defineParameterType, given, when, then} = require('cypress-cucumber-preprocessor/resolveStepDefinition'); | ||
const Given = window.Given = window.given = given; | ||
const When = window.When = window.when = when; | ||
const Then = window.Then = window.then = then; | ||
window.defineParameterType = defineParameterType; | ||
const { createTestsFromFeature } = require('cypress-cucumber-preprocessor/createTestsFromFeature'); | ||
${eval(toRequire).join("\n")} | ||
const {Parser, Compiler} = require('gherkin'); | ||
const spec = \`${spec}\` | ||
const gherkinAst = new Parser().parse(spec); | ||
createTestsFromFeature(gherkinAst); | ||
`; | ||
|
||
const createPattern = () => `${stepDefinitionPath()}/**/*.+(js|ts)`; | ||
|
||
const pattern = createPattern(); | ||
|
||
const getStepDefinitionsPaths = () => [].concat(glob.sync(pattern)); | ||
|
||
module.exports = spec => { | ||
log("compiling", spec); | ||
const stepDefinitionsToRequire = getStepDefinitionsPaths().map( | ||
sdPath => `require('${sdPath}')` | ||
); | ||
return createCucumber(spec, stepDefinitionsToRequire); | ||
}; |
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,23 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const cosmiconfig = require("cosmiconfig"); | ||
|
||
module.exports = () => { | ||
const appRoot = process.cwd(); | ||
|
||
const explorer = cosmiconfig("cypress-cucumber-preprocessor", { sync: true }); | ||
const loaded = explorer.load(); | ||
if (loaded && loaded.config && loaded.config.step_definitions) { | ||
return path.resolve(appRoot, loaded.config.step_definitions); | ||
} | ||
|
||
// XXX Deprecated, left here for backward compability | ||
const cypressOptions = JSON.parse( | ||
fs.readFileSync(`${appRoot}/cypress.json`, "utf-8") | ||
); | ||
if (cypressOptions && cypressOptions.fileServerFolder) { | ||
return `${cypressOptions.fileServerFolder}/support/step_definitions`; | ||
} | ||
|
||
return `${appRoot}/cypress/support/step_definitions`; | ||
}; |