Skip to content

Commit

Permalink
fix: define commonPath based on nonGlobalStepBaseDir.
Browse files Browse the repository at this point in the history
  • Loading branch information
Song-Nan17 authored and lgandecki committed Jul 7, 2020
1 parent 8b92ed3 commit 47f360a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
3 changes: 1 addition & 2 deletions lib/getStepDefinitionsPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const getStepDefinitionsPaths = filePath => {
if (config.nonGlobalStepBaseDir) {
const stepBase = `${appRoot}/${config.nonGlobalStepBaseDir}`;
nonGlobalPath = nonGlobalPath.replace(stepDefinitionPath(), stepBase);
commonPath = `${nonGlobalPath}/${config.commonPath ||
`${stepBase}/common/`}`;
commonPath = `${nonGlobalPath}/../${config.commonPath || "common/"}`;
}

const nonGlobalPattern = `${nonGlobalPath}/**/*.+(js|ts)`;
Expand Down
44 changes: 34 additions & 10 deletions lib/getStepDefinitionsPaths.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,43 @@ describe("getStepDefinitionsPaths", () => {
expect(actual).to.include(expected);
});

it("should return the overriden non global step definition pattern if nonGlobalStepBaseDir is defined", () => {
jest.spyOn(process, "cwd").mockImplementation(() => "cwd");
getConfig.mockReturnValue({
describe("nonGlobalStepBaseDir is defined", () => {
const path = "stepDefinitionPath/test.feature";
const config = {
nonGlobalStepDefinitions: true,
nonGlobalStepBaseDir: "nonGlobalStepBaseDir"
};

beforeEach(() => {
jest.spyOn(process, "cwd").mockImplementation(() => "cwd");
});
// eslint-disable-next-line global-require
const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths");
const path = "stepDefinitionPath/test.feature";
const actual = getStepDefinitionsPaths(path);
const expected = "cwd/nonGlobalStepBaseDir/test/**/*.+(js|ts)";

expect(actual).to.include(expected);
expect(actual).to.not.include("stepDefinitionPath/test/**/*.+(js|ts)");
it("should return the overriden non global step definition pattern and default common folder", () => {
getConfig.mockReturnValue(config);

const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths");
const actual = getStepDefinitionsPaths(path);

const expectedNonGlobalDefinitionPattern =
"cwd/nonGlobalStepBaseDir/test/**/*.+(js|ts)";
const expectedCommonPath =
"cwd/nonGlobalStepBaseDir/test/../common/**/*.+(js|ts)";

expect(actual).to.include(expectedNonGlobalDefinitionPattern);
expect(actual).to.include(expectedCommonPath);
expect(actual).to.not.include("stepDefinitionPath/test/**/*.+(js|ts)");
});

it("should return common folder defined by the dev and based on nonGlobalStepBaseDir", () => {
getConfig.mockReturnValue({ ...config, commonPath: "commonPath/" });

const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths");
const actual = getStepDefinitionsPaths(path);

const expectedCommonPath =
"cwd/nonGlobalStepBaseDir/test/../commonPath/**/*.+(js|ts)";

expect(actual).to.include(expectedCommonPath);
});
});
});

0 comments on commit 47f360a

Please sign in to comment.