|
1 | 1 | /* eslint-disable no-eval */ |
2 | 2 | const fs = require("fs"); |
3 | 3 | const through = require("through"); |
4 | | -const path = require("path"); |
5 | 4 | const browserify = require("@cypress/browserify-preprocessor"); |
6 | 5 | const log = require("debug")("cypress:cucumber"); |
7 | | -const glob = require("glob"); |
8 | | -const cosmiconfig = require("cosmiconfig"); |
9 | 6 | const chokidar = require("chokidar"); |
10 | | - |
11 | | -// This is the template for the file that we will send back to cypress instead of the text of a |
12 | | -// feature file |
13 | | -const createCucumber = (spec, toRequire) => |
14 | | - ` |
15 | | - const {resolveAndRunStepDefinition, defineParameterType, given, when, then} = require('cypress-cucumber-preprocessor/resolveStepDefinition'); |
16 | | - const Given = window.Given = window.given = given; |
17 | | - const When = window.When = window.when = when; |
18 | | - const Then = window.Then = window.then = then; |
19 | | - window.defineParameterType = defineParameterType; |
20 | | - const { createTestsFromFeature } = require('cypress-cucumber-preprocessor/createTestsFromFeature'); |
21 | | - ${eval(toRequire).join("\n")} |
22 | | - const {Parser, Compiler} = require('gherkin'); |
23 | | - const spec = \`${spec}\` |
24 | | - const gherkinAst = new Parser().parse(spec); |
25 | | - |
26 | | - createTestsFromFeature(gherkinAst); |
27 | | - `; |
28 | | - |
29 | | -const stepDefinitionPath = () => { |
30 | | - const appRoot = process.cwd(); |
31 | | - |
32 | | - const explorer = cosmiconfig("cypress-cucumber-preprocessor", { sync: true }); |
33 | | - const loaded = explorer.load(); |
34 | | - if (loaded && loaded.config && loaded.config.step_definitions) { |
35 | | - return path.resolve(appRoot, loaded.config.step_definitions); |
36 | | - } |
37 | | - |
38 | | - // XXX Deprecated, left here for backward compability |
39 | | - const cypressOptions = JSON.parse( |
40 | | - fs.readFileSync(`${appRoot}/cypress.json`, "utf-8") |
41 | | - ); |
42 | | - if (cypressOptions && cypressOptions.fileServerFolder) { |
43 | | - return `${cypressOptions.fileServerFolder}/support/step_definitions`; |
44 | | - } |
45 | | - |
46 | | - return `${appRoot}/cypress/support/step_definitions`; |
47 | | -}; |
48 | | -const createPattern = () => `${stepDefinitionPath()}/**/*.+(js|ts)`; |
49 | | - |
50 | | -const pattern = createPattern(); |
51 | | - |
52 | | -const getStepDefinitionsPaths = () => [].concat(glob.sync(pattern)); |
53 | | - |
54 | | -const compile = spec => { |
55 | | - log("compiling", spec); |
56 | | - const stepDefinitionsToRequire = getStepDefinitionsPaths().map( |
57 | | - sdPath => `require('${sdPath}')` |
58 | | - ); |
59 | | - return createCucumber(spec, stepDefinitionsToRequire); |
60 | | -}; |
| 7 | +const compile = require("./loader.js"); |
| 8 | +const stepDefinitionPath = require("./stepDefinitionPath.js"); |
61 | 9 |
|
62 | 10 | const transform = file => { |
63 | 11 | let data = ""; |
|
0 commit comments