Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"extends": ["airbnb-base", "plugin:prettier/recommended"],
"plugins": [
"cypress",
"prettier"
],
"plugins": ["cypress", "prettier"],
"env": {
"browser": true,
"cypress/globals": true
"cypress/globals": true,
"jest": true
},
"rules": {
"prettier/prettier": "error"
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ First please use [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) to
```
inside your package.json. (this will become the default option in a future version)

Option | Default value | Description
------------ | ------------- | -------------
commonPath | a common folder inside the step_definitions folder | Define the path to a folder containing all common step definitions of your tests
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
step_definitions | | Path to the folder containing our step definitions

###### Step definitions creation
Then put your step definitions in cypress/integration with the folder name matching the .feature filename.
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:
Expand Down
5 changes: 4 additions & 1 deletion lib/getStepDefinitionsPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const getStepDefinitionsPaths = filePath => {
const nonGlobalPattern = `${getStepDefinitionPathsFrom(
filePath
)}/**/*.+(js|ts)`;
const commonDefinitionsPattern = `${stepDefinitionPath()}/common/**/*.+(js|ts)`;

const commonPath =
loaded.config.commonPath || `${stepDefinitionPath()}/common/`;
const commonDefinitionsPattern = `${commonPath}**/*.+(js|ts)`;
paths = paths.concat(glob.sync(nonGlobalPattern));
paths = paths.concat(glob.sync(commonDefinitionsPattern));
} else {
Expand Down
44 changes: 44 additions & 0 deletions lib/getStepDefinitionsPaths.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
jest.mock("./stepDefinitionPath.js", () => () => "stepDefinitionPath");
jest.mock("glob", () => ({
sync(pattern) {
return pattern;
}
}));

describe("getStepDefinitionsPaths", () => {
it("should return the default common folder", () => {
jest.resetModules();
jest.mock("cosmiconfig", () => () => ({
load: () => ({
config: {
nonGlobalStepDefinitions: true
}
})
}));
// eslint-disable-next-line global-require
const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths");

const actual = getStepDefinitionsPaths("/path");
const expected = "stepDefinitionPath/common/**/*.+(js|ts)";

expect(actual).to.include(expected);
});
it("should return the common folder defined by the developper", () => {
jest.resetModules();
jest.mock("cosmiconfig", () => () => ({
load: () => ({
config: {
nonGlobalStepDefinitions: true,
commonPath: "myPath/"
}
})
}));
// eslint-disable-next-line global-require
const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths");

const actual = getStepDefinitionsPaths("/path");
const expected = "myPath/**/*.+(js|ts)";

expect(actual).to.include(expected);
});
});
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"eslint-plugin-cypress": "^2.0.1",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-prettier": "^2.6.0",
"jest": "^23.6.0",
"husky": "^1.1.1",
"jest": "^23.6.0",
"lint-staged": "^7.3.0",
"prettier": "^1.13.5",
"semantic-release": "^15.12.3"
Expand Down