Skip to content

Commit 47f360a

Browse files
Song-Nan17lgandecki
authored andcommitted
fix: define commonPath based on nonGlobalStepBaseDir.
1 parent 8b92ed3 commit 47f360a

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

lib/getStepDefinitionsPaths.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ const getStepDefinitionsPaths = filePath => {
2020
if (config.nonGlobalStepBaseDir) {
2121
const stepBase = `${appRoot}/${config.nonGlobalStepBaseDir}`;
2222
nonGlobalPath = nonGlobalPath.replace(stepDefinitionPath(), stepBase);
23-
commonPath = `${nonGlobalPath}/${config.commonPath ||
24-
`${stepBase}/common/`}`;
23+
commonPath = `${nonGlobalPath}/../${config.commonPath || "common/"}`;
2524
}
2625

2726
const nonGlobalPattern = `${nonGlobalPath}/**/*.+(js|ts)`;

lib/getStepDefinitionsPaths.test.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,43 @@ describe("getStepDefinitionsPaths", () => {
6363
expect(actual).to.include(expected);
6464
});
6565

66-
it("should return the overriden non global step definition pattern if nonGlobalStepBaseDir is defined", () => {
67-
jest.spyOn(process, "cwd").mockImplementation(() => "cwd");
68-
getConfig.mockReturnValue({
66+
describe("nonGlobalStepBaseDir is defined", () => {
67+
const path = "stepDefinitionPath/test.feature";
68+
const config = {
6969
nonGlobalStepDefinitions: true,
7070
nonGlobalStepBaseDir: "nonGlobalStepBaseDir"
71+
};
72+
73+
beforeEach(() => {
74+
jest.spyOn(process, "cwd").mockImplementation(() => "cwd");
7175
});
72-
// eslint-disable-next-line global-require
73-
const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths");
74-
const path = "stepDefinitionPath/test.feature";
75-
const actual = getStepDefinitionsPaths(path);
76-
const expected = "cwd/nonGlobalStepBaseDir/test/**/*.+(js|ts)";
7776

78-
expect(actual).to.include(expected);
79-
expect(actual).to.not.include("stepDefinitionPath/test/**/*.+(js|ts)");
77+
it("should return the overriden non global step definition pattern and default common folder", () => {
78+
getConfig.mockReturnValue(config);
79+
80+
const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths");
81+
const actual = getStepDefinitionsPaths(path);
82+
83+
const expectedNonGlobalDefinitionPattern =
84+
"cwd/nonGlobalStepBaseDir/test/**/*.+(js|ts)";
85+
const expectedCommonPath =
86+
"cwd/nonGlobalStepBaseDir/test/../common/**/*.+(js|ts)";
87+
88+
expect(actual).to.include(expectedNonGlobalDefinitionPattern);
89+
expect(actual).to.include(expectedCommonPath);
90+
expect(actual).to.not.include("stepDefinitionPath/test/**/*.+(js|ts)");
91+
});
92+
93+
it("should return common folder defined by the dev and based on nonGlobalStepBaseDir", () => {
94+
getConfig.mockReturnValue({ ...config, commonPath: "commonPath/" });
95+
96+
const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths");
97+
const actual = getStepDefinitionsPaths(path);
98+
99+
const expectedCommonPath =
100+
"cwd/nonGlobalStepBaseDir/test/../commonPath/**/*.+(js|ts)";
101+
102+
expect(actual).to.include(expectedCommonPath);
103+
});
80104
});
81105
});

0 commit comments

Comments
 (0)