Skip to content

Commit ec34da2

Browse files
committed
test(getstepdefinitionspaths): tweaked tests, use path.resolve for commonPath
fix #275
1 parent 26aed23 commit ec34da2

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

lib/getStepDefinitionsPaths.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require("path");
12
const glob = require("glob");
23
const { getConfig } = require("./getConfig");
34
const stepDefinitionPath = require("./stepDefinitionPath.js");
@@ -15,7 +16,7 @@ const getStepDefinitionsPaths = filePath => {
1516
let commonPath = config.commonPath || `${stepDefinitionPath()}/common/`;
1617

1718
if (config.commonPath) {
18-
commonPath = `${appRoot}/${commonPath}`;
19+
commonPath = path.resolve(appRoot, commonPath);
1920
}
2021
const commonDefinitionsPattern = `${commonPath}**/*.+(js|ts)`;
2122
paths = paths.concat(glob.sync(nonGlobalPattern));
Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1+
/* eslint-disable global-require */
12
jest.mock("./stepDefinitionPath.js", () => () => "stepDefinitionPath");
23
jest.mock("glob", () => ({
34
sync(pattern) {
45
return pattern;
56
}
67
}));
78

9+
let getConfig;
10+
811
describe("getStepDefinitionsPaths", () => {
9-
it("should return the default common folder", () => {
12+
beforeEach(() => {
1013
jest.resetModules();
11-
jest.mock("cosmiconfig", () => () => ({
12-
load: () => ({
13-
config: {
14-
nonGlobalStepDefinitions: true
15-
}
16-
})
17-
}));
18-
// eslint-disable-next-line global-require
14+
({ getConfig } = require("./getConfig"));
15+
jest.mock("./getConfig");
16+
});
17+
it("should return the default common folder", () => {
18+
getConfig.mockReturnValue({
19+
nonGlobalStepDefinitions: true
20+
});
21+
1922
const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths");
2023

2124
const actual = getStepDefinitionsPaths("/path");
@@ -24,26 +27,28 @@ describe("getStepDefinitionsPaths", () => {
2427
expect(actual).to.include(expected);
2528
});
2629

27-
it("should return the common folder defined by the developper", () => {
28-
jest.resetModules();
30+
it("should return the common folder defined by the developer", () => {
31+
jest.mock("path", () => ({
32+
resolve(appRoot, commonPath) {
33+
return `./${appRoot}/${commonPath}`;
34+
},
35+
extname() {
36+
return ".js";
37+
}
38+
}));
2939

3040
jest.mock("fs");
3141
jest.spyOn(process, "cwd").mockImplementation(() => "cwd");
3242

33-
jest.mock("cosmiconfig", () => () => ({
34-
load: () => ({
35-
config: {
36-
nonGlobalStepDefinitions: true,
37-
commonPath: "myPath/"
38-
}
39-
})
40-
}));
41-
// eslint-disable-next-line global-require
43+
getConfig.mockReturnValue({
44+
nonGlobalStepDefinitions: true,
45+
commonPath: "myPath/"
46+
});
47+
4248
const { getStepDefinitionsPaths } = require("./getStepDefinitionsPaths");
4349

4450
const actual = getStepDefinitionsPaths("/path");
45-
const expected = "cwd/myPath/**/*.+(js|ts)";
46-
51+
const expected = "./cwd/myPath/**/*.+(js|ts)";
4752
expect(actual).to.include(expected);
4853
});
4954
});

0 commit comments

Comments
 (0)