Skip to content

Commit 04c7c68

Browse files
committed
integration test: fix test-cases, add unit tests
1 parent 133803f commit 04c7c68

File tree

4 files changed

+322
-25
lines changed

4 files changed

+322
-25
lines changed

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

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require("path");
22
const fs = require("fs");
3-
const Ajv = require("ajv")
3+
const Ajv = require("ajv");
44

55
const assert = require("../../../modules/console/assert.js");
66
const WorkspacePath = require("../../../modules/workspace/workspace-path.js");
@@ -11,7 +11,6 @@ class TestCasesConfig {
1111

1212
static getConfig(configPathList) {
1313
return new Promise((resolve, reject) => {
14-
const ajv = new Ajv()
1514
let configsReady = [];
1615
let configs = {suites: [], tests: {}};
1716
assert(Array.isArray(configPathList), "configPathList is array");
@@ -20,8 +19,7 @@ class TestCasesConfig {
2019
configPathListClone[index] = WorkspacePath.resolvePath(configPath, TestEnv.getWorkspacePath(), TestEnv.getTestSuitePath());
2120
let configReady = new Promise((resolve, reject) => {
2221
TestCasesConfig.readConfig(configPathListClone[index]).then(config => {
23-
const validate = ajv.compile(TestCasesConfig.getConfigSchema());
24-
assert(validate(config), "config schema validation failed");
22+
assert(TestCasesConfig.isConfig(config), "config schema validation failed");
2523
let suite = {
2624
suite: path.join(TestEnv.getWorkspacePath(), config.data.suite),
2725
config: config.path,
@@ -75,6 +73,12 @@ class TestCasesConfig {
7573
}
7674

7775

76+
static isConfig(config) {
77+
const validate = new Ajv().compile(TestCasesConfig.getConfigSchema());
78+
return validate(config);
79+
}
80+
81+
7882
static getConfigSchema() {
7983
return {
8084
type: "object",
@@ -112,6 +116,69 @@ class TestCasesConfig {
112116
additionalProperties: false
113117
};
114118
}
119+
120+
121+
static isTestCasesConfig(testCasesConfig) {
122+
const validate = new Ajv().compile(TestCasesConfig.getTestCasesConfigSchema());
123+
return validate(testCasesConfig);
124+
}
125+
126+
127+
static getTestCasesConfigSchema() {
128+
return {
129+
type: "object",
130+
properties: {
131+
suites: {
132+
type: "array",
133+
items: {
134+
type: "object",
135+
properties: {
136+
suite: {
137+
type: "string"
138+
},
139+
config: {
140+
type: "string"
141+
},
142+
tests: {
143+
type: "object",
144+
additionalProperties: {
145+
type: "object",
146+
properties: {
147+
refs: {
148+
type: "array"
149+
},
150+
animstep: {
151+
type: "string"
152+
}
153+
},
154+
additionalProperties: false
155+
}
156+
}
157+
},
158+
required: ["suite", "config", "tests"],
159+
additionalProperties: false
160+
}
161+
},
162+
tests: {
163+
type: "object",
164+
additionalProperties: {
165+
type: "object",
166+
properties: {
167+
refs: {
168+
type: "array"
169+
},
170+
animstep: {
171+
type: "string"
172+
}
173+
},
174+
additionalProperties: false
175+
}
176+
}
177+
},
178+
required: ["suites", "tests"],
179+
additionalProperties: false
180+
};
181+
}
115182
}
116183

117184

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ describe("getConfig()", () => {
9393
"./modules/integration-test/test-case/test-cases-config.test/test-cases-2.json",
9494
"./modules/integration-test/test-case/test-cases-config.test/test-cases-3.json"
9595
]).then(config => {
96-
config.suites = config.suites.map(a => a.suite).sort();
97-
testCasesResult.suites = testCasesResult.suites.map(a => a.suite).sort()
96+
config.suites = config.suites.sort((a, b) => {
97+
if (a.suite < b.suite) return -1
98+
return a.suite > b.suite ? 1 : 0
99+
});
98100
expect(config).toEqual(testCasesResult);
101+
expect(TestCasesConfig.isTestCasesConfig(config)).toBeTruthy();
99102
});
100103
});
101104
});

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

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
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");
7+
const TestCasesConfig = require("../../../modules/integration-test/test-case/test-cases-config.js");
68

79

810
class TestCases {
911

1012
static getTestCases(testCasesConfigReady, filters) {
1113
return new Promise((resolve, reject) => {
1214
testCasesConfigReady.then(configs => {
13-
let testCasesReadyList = [];
14-
let filteredTestCasesReadyList = [];
15-
configs.suites.forEach(suite => {
16-
let testCasesReady = TestCases.collectTestCases(suite.suite);
17-
testCasesReadyList.push(testCasesReady);
18-
testCasesReady.then(testCases => {
19-
let filteredTestCasesReady = TestCases.filterTestCases(testCases, suite.suite, filters);
20-
filteredTestCasesReadyList.push(filteredTestCasesReady);
15+
try {
16+
assert(TestCasesConfig.isTestCasesConfig(configs), "test cases config schema validation failed");
17+
let testCasesReadyList = [];
18+
let filteredTestCasesReadyList = [];
19+
configs.suites.forEach(suite => {
20+
let testCasesReady = TestCases.collectTestCases(suite.suite);
21+
testCasesReadyList.push(testCasesReady);
22+
testCasesReady.then(testCases => {
23+
let filteredTestCasesReady = TestCases.filterTestCases(testCases, suite.suite, filters);
24+
filteredTestCasesReadyList.push(filteredTestCasesReady);
25+
}).catch(err => {
26+
return reject(err);
27+
});
2128
});
22-
});
23-
Promise.all(testCasesReadyList).then(testCasesList => {
24-
testCasesList = testCasesList.flat(1);
25-
Promise.all(filteredTestCasesReadyList).then(filteredTestCasesList => {
26-
filteredTestCasesList = filteredTestCasesList.flat(1);
27-
return resolve({testCases: testCasesList, filteredTestCases: filteredTestCasesList});
29+
Promise.all(testCasesReadyList).then(testCasesList => {
30+
testCasesList = testCasesList.flat(1);
31+
Promise.all(filteredTestCasesReadyList).then(filteredTestCasesList => {
32+
filteredTestCasesList = filteredTestCasesList.flat(1);
33+
return resolve({testCases: testCasesList, filteredTestCases: filteredTestCasesList});
34+
});
35+
}).catch(err => {
36+
return reject(err);
2837
});
29-
});
38+
} catch(err) {
39+
return reject(err);
40+
}
3041
});
3142
});
3243
}
@@ -49,10 +60,14 @@ class TestCases {
4960
testCasesReady.push(testCaseReady);
5061
testCaseReady.then(newTestCases => {
5162
testCases = testCases.concat(newTestCases);
63+
}).catch(err => {
64+
return reject(err);
5265
});
5366
});
5467
Promise.all(testCasesReady).then(() => {
5568
return resolve(testCases);
69+
}).catch(err => {
70+
return reject(err);
5671
});
5772
}
5873
});
@@ -71,7 +86,7 @@ class TestCases {
7186
}
7287

7388

74-
static filterTestCases(testCases, suitePath, filters) {
89+
static filterTestCases(testCases, suitePath, filters=[]) {
7590
return new Promise((resolve, reject) => {
7691
let filteredTestCases = [];
7792
if (filters.length === 0) {
@@ -89,7 +104,11 @@ class TestCases {
89104
if (testCases.includes(filter)) {
90105
filteredTestCases.push(filter);
91106
} else {
92-
let filterWithSuitePath = path.join(suitePath, filter);
107+
let filterPathInSuite = "/" + path.join(
108+
path.relative(
109+
TestEnv.getWorkspacePath(),
110+
suitePath),
111+
filter);
93112
let filterRelative = "/" + path.relative(
94113
TestEnv.getWorkspacePath(),
95114
WorkspacePath.resolvePath(
@@ -99,8 +118,8 @@ class TestCases {
99118
let filterAbsolute = "/" + path.relative(
100119
TestEnv.getWorkspacePath(),
101120
filter);
102-
if(testCases.includes(filterWithSuitePath)) {
103-
filteredTestCases.push(filterWithSuitePath);
121+
if(testCases.includes(filterPathInSuite)) {
122+
filteredTestCases.push(filterPathInSuite);
104123
} else if(testCases.includes(filterRelative)) {
105124
filteredTestCases.push(filterRelative);
106125
} else if(testCases.includes(filterAbsolute)) {

0 commit comments

Comments
 (0)