Skip to content

Commit a8d3df6

Browse files
EmmanuelDemeylgandecki
authored andcommitted
feat(step_definition): Add option to define path for the common folder (#138)
* feat(step_definition): Add option to define path for the common folder 136 * feat: add doc about step_definition and nonGlobalStepDefinitions options
1 parent 4e05e6b commit a8d3df6

File tree

6 files changed

+97
-7
lines changed

6 files changed

+97
-7
lines changed

.eslintrc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{
22
"extends": ["airbnb-base", "plugin:prettier/recommended"],
3-
"plugins": [
4-
"cypress",
5-
"prettier"
6-
],
3+
"plugins": ["cypress", "prettier"],
74
"env": {
85
"browser": true,
9-
"cypress/globals": true
6+
"cypress/globals": true,
7+
"jest": true
108
},
119
"rules": {
1210
"prettier/prettier": "error"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ First please use [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) to
5959
```
6060
inside your package.json. (this will become the default option in a future version)
6161

62+
Option | Default value | Description
63+
------------ | ------------- | -------------
64+
commonPath | a common folder inside the step_definitions folder | Define the path to a folder containing all common step definitions of your tests
65+
nonGlobalStepDefinitions | true | If true use the Cypress Cucumber Preprocessor Style pattern for placing step definitions files. If false, we will use the "oldschool" (everything is global) Cucumber style
66+
step_definitions | | Path to the folder containing our step definitions
67+
6268
###### Step definitions creation
6369
Then put your step definitions in cypress/integration with the folder name matching the .feature filename.
6470
Easier to show than to explain, so, assuming the feature file is in cypress/integration/Google.feature , as proposed above, the preprocessor will read all the files inside cypress/integration/Google/, so:

lib/getStepDefinitionsPaths.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ const getStepDefinitionsPaths = filePath => {
1111
const nonGlobalPattern = `${getStepDefinitionPathsFrom(
1212
filePath
1313
)}/**/*.+(js|ts)`;
14-
const commonDefinitionsPattern = `${stepDefinitionPath()}/common/**/*.+(js|ts)`;
14+
15+
const commonPath =
16+
loaded.config.commonPath || `${stepDefinitionPath()}/common/`;
17+
const commonDefinitionsPattern = `${commonPath}**/*.+(js|ts)`;
1518
paths = paths.concat(glob.sync(nonGlobalPattern));
1619
paths = paths.concat(glob.sync(commonDefinitionsPattern));
1720
} else {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
jest.mock("./stepDefinitionPath.js", () => () => "stepDefinitionPath");
2+
jest.mock("glob", () => ({
3+
sync(pattern) {
4+
return pattern;
5+
}
6+
}));
7+
8+
describe("getStepDefinitionsPaths", () => {
9+
it("should return the default common folder", () => {
10+
jest.resetModules();
11+
jest.mock("cosmiconfig", () => () => ({
12+
load: () => ({
13+
config: {
14+
nonGlobalStepDefinitions: true
15+
}
16+
})
17+
}));
18+
// eslint-disable-next-line global-require
19+
const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths");
20+
21+
const actual = getStepDefinitionsPaths("/path");
22+
const expected = "stepDefinitionPath/common/**/*.+(js|ts)";
23+
24+
expect(actual).to.include(expected);
25+
});
26+
it("should return the common folder defined by the developper", () => {
27+
jest.resetModules();
28+
jest.mock("cosmiconfig", () => () => ({
29+
load: () => ({
30+
config: {
31+
nonGlobalStepDefinitions: true,
32+
commonPath: "myPath/"
33+
}
34+
})
35+
}));
36+
// eslint-disable-next-line global-require
37+
const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths");
38+
39+
const actual = getStepDefinitionsPaths("/path");
40+
const expected = "myPath/**/*.+(js|ts)";
41+
42+
expect(actual).to.include(expected);
43+
});
44+
});

package-lock.json

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
"eslint-plugin-cypress": "^2.0.1",
5757
"eslint-plugin-import": "^2.12.0",
5858
"eslint-plugin-prettier": "^2.6.0",
59-
"jest": "^23.6.0",
6059
"husky": "^1.1.1",
60+
"jest": "^23.6.0",
6161
"lint-staged": "^7.3.0",
6262
"prettier": "^1.13.5",
6363
"semantic-release": "^15.12.3"

0 commit comments

Comments
 (0)