Skip to content

Commit 6cdd236

Browse files
committed
integration test: fix test-cases-config
1 parent 17f2b90 commit 6cdd236

File tree

6 files changed

+243
-5
lines changed

6 files changed

+243
-5
lines changed

test/integration/modules/integration-test/test-case/test-cases-config.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require("path");
22
const fs = require("fs");
33

4+
const assert = require("../../../modules/console/assert.js");
45
const WorkspacePath = require("../../../modules/workspace/workspace-path.js");
56
const TestEnv = require("../../../modules/integration-test/test-env.js");
67

@@ -11,6 +12,7 @@ class TestCasesConfig {
1112
return new Promise((resolve, reject) => {
1213
let configsReady = [];
1314
let configs = {suites: [], tests: {}};
15+
assert(Array.isArray(configPathList), "configPathList is array");
1416
configPathList.forEach((configPath, index) => {
1517
configPathList[index] = WorkspacePath.resolvePath(configPath, TestEnv.getWorkspacePath(), TestEnv.getTestSuitePath());
1618
let configReady = new Promise((resolve, reject) => {
@@ -28,8 +30,9 @@ class TestCasesConfig {
2830
});
2931
configs.suites.push(suite);
3032
return resolve();
31-
})
32-
33+
}).catch(err => {
34+
return reject(err);
35+
});
3336
});
3437
configsReady.push(configReady);
3538
});
@@ -50,10 +53,13 @@ class TestCasesConfig {
5053
if (err) {
5154
return reject(err);
5255
}
53-
return resolve({path: configPath, data: JSON.parse(data)});
56+
try {
57+
data = JSON.parse(data);
58+
} catch (err) {
59+
return reject(err);
60+
}
61+
return resolve({path: configPath, data: data});
5462
});
55-
} else if (err.code === "ENOENT") {
56-
return resolve({path: configPath, data: {}});
5763
} else {
5864
return reject(err);
5965
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const TestCasesConfig = require("./test-cases-config.js");
2+
3+
const testCasesResult = require("./test-cases-config.test/test-cases-result.js");
4+
5+
6+
describe("getConfig()", () => {
7+
describe("configPathList", () => {
8+
test("if configPathList is no an array, err is thrown", () => {
9+
return TestCasesConfig.getConfig().catch(err => {
10+
expect(err.toString()).toBe("Error: Assert failed: configPathList is array");
11+
});
12+
});
13+
14+
test("if configPathList is an empty array", () => {
15+
return TestCasesConfig.getConfig([]).then(config => {
16+
expect(config).toStrictEqual({"suites": [], "tests": {}});
17+
});
18+
});
19+
20+
test("if configPathList is an array", () => {
21+
return TestCasesConfig.getConfig([
22+
"./modules/integration-test/test-case/test-cases-config.test/test-cases-1.json",
23+
"./modules/integration-test/test-case/test-cases-config.test/test-cases-2.json"
24+
]).then(config => {
25+
expect(config).toStrictEqual(testCasesResult);
26+
});
27+
});
28+
});
29+
30+
describe("configPath", () => {
31+
test("if configPath name is not string, err is thrown", () => {
32+
return TestCasesConfig.getConfig([
33+
[]
34+
]).catch(err => {
35+
expect(err.toString()).toInclude("TypeError [ERR_INVALID_ARG_TYPE]: The \"path\" argument must be of type string. Received an instance of Array");
36+
});
37+
});
38+
39+
test("if configPath is not file, err is thrown", () => {
40+
return TestCasesConfig.getConfig([
41+
"./modules/integration-test/test-case/test-cases-config.test"
42+
]).catch(err => {
43+
expect(err.toString()).toInclude("Error: EISDIR: illegal operation on a directory, read");
44+
});
45+
});
46+
47+
test("if configPath does not exist, err is thrown", () => {
48+
return TestCasesConfig.getConfig([
49+
"./modules/integration-test/test-case/test-cases-config.test/test-cases-4.json"
50+
]).catch(err => {
51+
expect(err.toString()).toInclude("Error: ENOENT: no such file or directory");
52+
});
53+
});
54+
55+
test("if configPath is not json, err is thrown", () => {
56+
return TestCasesConfig.getConfig([
57+
"./modules/integration-test/test-case/test-cases-config.test/test-cases-3.json"
58+
]).catch(err => {
59+
expect(err.toString()).toInclude("SyntaxError: Unexpected end of JSON input");
60+
});
61+
});
62+
});
63+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"suite": "/test/integration/modules/integration-test/test-cases/test-suite-1",
3+
"test": {
4+
"example-group-1/example-1": {
5+
"refs": [
6+
"1111111"
7+
]
8+
},
9+
"example-group-1/example-2": {
10+
"refs": [
11+
"2222222"
12+
]
13+
},
14+
"example-group-2/example-3": {
15+
"refs": [
16+
"3333333"
17+
]
18+
},
19+
"example-group-2/example-4": {
20+
"refs": [
21+
"4444444"
22+
]
23+
},
24+
"example-group-2/example-5": {
25+
"refs": [
26+
"5555555"
27+
]
28+
}
29+
}
30+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"suite": "/test/integration/modules/integration-test/test-cases/test-suite-2",
3+
"test": {
4+
"example-group-3/example-6": {
5+
"refs": [
6+
"6666666"
7+
]
8+
},
9+
"example-group-3/example-7": {
10+
"refs": [
11+
"7777777"
12+
]
13+
},
14+
"example-group-4/example-8": {
15+
"refs": [
16+
"8888888"
17+
]
18+
},
19+
"example-group-4/example-9": {
20+
"refs": [
21+
"9999999"
22+
]
23+
}
24+
}
25+
}

test/integration/modules/integration-test/test-case/test-cases-config.test/test-cases-3.json

Whitespace-only changes.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
const TestEnv = require("../../../../modules/integration-test/test-env.js");
2+
3+
4+
const testCasesResult = {
5+
suites: [
6+
{
7+
config: TestEnv.getWorkspacePath() + "/test/integration/modules/integration-test/test-case/test-cases-config.test/test-cases-1.json",
8+
suite: TestEnv.getWorkspacePath() + "/test/integration/modules/integration-test/test-cases/test-suite-1",
9+
tests: {
10+
"/test/integration/modules/integration-test/test-cases/test-suite-1/example-group-1/example-1": {
11+
"refs": [
12+
"1111111"
13+
]
14+
},
15+
"/test/integration/modules/integration-test/test-cases/test-suite-1/example-group-1/example-2": {
16+
"refs": [
17+
"2222222"
18+
]
19+
},
20+
"/test/integration/modules/integration-test/test-cases/test-suite-1/example-group-2/example-3": {
21+
"refs": [
22+
"3333333"
23+
]
24+
},
25+
"/test/integration/modules/integration-test/test-cases/test-suite-1/example-group-2/example-4": {
26+
"refs": [
27+
"4444444"
28+
]
29+
},
30+
"/test/integration/modules/integration-test/test-cases/test-suite-1/example-group-2/example-5": {
31+
"refs": [
32+
"5555555"
33+
]
34+
}
35+
}
36+
},
37+
{
38+
config: TestEnv.getWorkspacePath() + "/test/integration/modules/integration-test/test-case/test-cases-config.test/test-cases-2.json",
39+
suite: TestEnv.getWorkspacePath() + "/test/integration/modules/integration-test/test-cases/test-suite-2",
40+
tests: {
41+
"/test/integration/modules/integration-test/test-cases/test-suite-2/example-group-3/example-6": {
42+
"refs": [
43+
"6666666"
44+
]
45+
},
46+
"/test/integration/modules/integration-test/test-cases/test-suite-2/example-group-3/example-7": {
47+
"refs": [
48+
"7777777"
49+
]
50+
},
51+
"/test/integration/modules/integration-test/test-cases/test-suite-2/example-group-4/example-8": {
52+
"refs": [
53+
"8888888"
54+
]
55+
},
56+
"/test/integration/modules/integration-test/test-cases/test-suite-2/example-group-4/example-9": {
57+
"refs": [
58+
"9999999"
59+
]
60+
}
61+
}
62+
}
63+
],
64+
tests: {
65+
"/test/integration/modules/integration-test/test-cases/test-suite-1/example-group-1/example-1": {
66+
"refs": [
67+
"1111111"
68+
]
69+
},
70+
"/test/integration/modules/integration-test/test-cases/test-suite-1/example-group-1/example-2": {
71+
"refs": [
72+
"2222222"
73+
]
74+
},
75+
"/test/integration/modules/integration-test/test-cases/test-suite-1/example-group-2/example-3": {
76+
"refs": [
77+
"3333333"
78+
]
79+
},
80+
"/test/integration/modules/integration-test/test-cases/test-suite-1/example-group-2/example-4": {
81+
"refs": [
82+
"4444444"
83+
]
84+
},
85+
"/test/integration/modules/integration-test/test-cases/test-suite-1/example-group-2/example-5": {
86+
"refs": [
87+
"5555555"
88+
]
89+
},
90+
"/test/integration/modules/integration-test/test-cases/test-suite-2/example-group-3/example-6": {
91+
"refs": [
92+
"6666666"
93+
]
94+
},
95+
"/test/integration/modules/integration-test/test-cases/test-suite-2/example-group-3/example-7": {
96+
"refs": [
97+
"7777777"
98+
]
99+
},
100+
"/test/integration/modules/integration-test/test-cases/test-suite-2/example-group-4/example-8": {
101+
"refs": [
102+
"8888888"
103+
]
104+
},
105+
"/test/integration/modules/integration-test/test-cases/test-suite-2/example-group-4/example-9": {
106+
"refs": [
107+
"9999999"
108+
]
109+
}
110+
}
111+
};
112+
113+
114+
module.exports = testCasesResult;

0 commit comments

Comments
 (0)