Skip to content

Commit e8fb529

Browse files
authored
Merge pull request #46 from vizzuhq/veghdev
integration test: add option tests
2 parents cb0f362 + dec7bc3 commit e8fb529

File tree

113 files changed

+2030
-41
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+2030
-41
lines changed

test/integration/man.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ try {
2424
"\n(relative or absolute path where the repo folder is the root)" +
2525
"\n")
2626
.default("c",
27-
["/test/integration/test_cases/test_cases.json"])
27+
[
28+
"/test/integration/test_cases/test_cases.json",
29+
"/test/integration/test_options/test_options.json"
30+
])
2831
.argv;
2932

3033
let manual = new Manual(argv.configs, argv.port);

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

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,40 @@ class TestCaseResult {
4141
deleteTestCaseResultReady = this.#deleteTestCaseResult();
4242
}
4343
deleteTestCaseResultReady.then(() => {
44-
if (this.#testData.result == "PASSED") {
45-
return resolve(this.#createTestCaseResultPassed());
46-
} else if(this.#testData.result == "WARNING") {
47-
return resolve(this.#createTestCaseResultWarning());
48-
} else if(this.#testData.result == "FAILED") {
49-
return resolve(this.#createTestCaseResultFailed());
44+
45+
if (this.#testCaseObj.testCase in this.#testCaseObj.testCasesConfig.tests &&
46+
"err" in this.#testCaseObj.testCasesConfig.tests[this.#testCaseObj.testCase]) {
47+
let err = this.#testCaseObj.testCasesConfig.tests[this.#testCaseObj.testCase]["err"];
48+
if (this.#testData.result === "ERROR") {
49+
if(this.#testData.description.includes(err)) {
50+
return resolve(this.#createTestCaseResultPassed(err));
51+
} else {
52+
return resolve(this.#createTestCaseResultError());
53+
}
54+
} else {
55+
this.#testData.result = "ERROR";
56+
this.#testData.description = "did not occur " + err;
57+
return resolve(this.#createTestCaseResultError());
58+
}
5059
} else {
51-
return resolve(this.#createTestCaseResultError());
60+
if (this.#testData.result === "PASSED") {
61+
return resolve(this.#createTestCaseResultPassed(this.#testData.hash));
62+
} else if(this.#testData.result === "WARNING") {
63+
return resolve(this.#createTestCaseResultWarning());
64+
} else if(this.#testData.result === "FAILED") {
65+
return resolve(this.#createTestCaseResultFailed());
66+
} else {
67+
return resolve(this.#createTestCaseResultError());
68+
}
5269
}
5370
});
5471
});
5572
}
5673

5774

58-
#createTestCaseResultPassed() {
75+
#createTestCaseResultPassed(msg) {
5976
this.#testCaseObj.testSuiteResults.PASSED.push(this.#testCaseObj.testCase);
60-
this.#cnsl.log(("[ " + this.#testData.result.padEnd(this.#cnsl.getTestStatusPad(), " ") + " ] ").success + "[ " + String(++this.#testCaseObj.testSuiteResults.FINISHED).padEnd(this.#cnsl.getTestNumberPad(), " ") + " ] " + path.relative(TestEnv.getTestSuitePath(), path.join(TestEnv.getWorkspacePath(), this.#testCaseObj.testCase)));
77+
this.#cnsl.log(("[ " + "PASSED".padEnd(this.#cnsl.getTestStatusPad(), " ") + " ] ").success + "[ " + String(++this.#testCaseObj.testSuiteResults.FINISHED).padEnd(this.#cnsl.getTestNumberPad(), " ") + " ] " + "[ " + msg + " ] " + path.relative(TestEnv.getTestSuitePath(), path.join(TestEnv.getWorkspacePath(), this.#testCaseObj.testCase)));
6178
if (this.#testCaseObj.createImages === "ALL") {
6279
this.#createImage(this.#testData, '-1new');
6380
}
@@ -66,7 +83,7 @@ class TestCaseResult {
6683

6784
#createTestCaseResultWarning() {
6885
this.#testCaseObj.testSuiteResults.WARNING.push(this.#testCaseObj.testCase);
69-
this.#cnsl.log(("[ " + this.#testData.result.padEnd(this.#cnsl.getTestStatusPad(), " ") + " ] " + "[ " + String(++this.#testCaseObj.testSuiteResults.FINISHED).padEnd(this.#cnsl.getTestNumberPad(), " ") + " ] " + "[ " + this.#testData.description + " ] ").warn + path.relative(TestEnv.getTestSuitePath(), path.join(TestEnv.getWorkspacePath(), this.#testCaseObj.testCase)));
86+
this.#cnsl.log(("[ " + "WARNING".padEnd(this.#cnsl.getTestStatusPad(), " ") + " ] " + "[ " + String(++this.#testCaseObj.testSuiteResults.FINISHED).padEnd(this.#cnsl.getTestNumberPad(), " ") + " ] " + "[ " + this.#testData.description + " ] ").warn + path.relative(TestEnv.getTestSuitePath(), path.join(TestEnv.getWorkspacePath(), this.#testCaseObj.testCase)));
7087
if (this.#testCaseObj.createImages !== "DISABLED") {
7188
this.#createImage(this.#testData, '-1new');
7289
}
@@ -108,7 +125,7 @@ class TestCaseResult {
108125

109126
#createTestCaseResultError() {
110127
this.#testCaseObj.testSuiteResults.FAILED.push(this.#testCaseObj.testCase);
111-
this.#createTestCaseResultErrorMsg();
128+
this.#createTestCaseResultErrorMsg();
112129
}
113130

114131

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class TestCase {
3838
return new Promise((resolve, reject) => {
3939
let refHash = [];
4040
let animStep = { step: testCaseObj.animStep, default: true };
41+
let errMsg;
4142
if (testCaseObj.testCase in testCaseObj.testCasesConfig.tests) {
4243
if ("animstep" in testCaseObj.testCasesConfig.tests[testCaseObj.testCase]) {
4344
animStep.step = testCaseObj.testCasesConfig.tests[testCaseObj.testCase]["animstep"].replace("%", "");
@@ -46,6 +47,9 @@ class TestCase {
4647
if ("refs" in testCaseObj.testCasesConfig.tests[testCaseObj.testCase]) {
4748
refHash = testCaseObj.testCasesConfig.tests[testCaseObj.testCase]["refs"];
4849
}
50+
if ("err" in testCaseObj.testCasesConfig.tests[testCaseObj.testCase]) {
51+
errMsg = testCaseObj.testCasesConfig.tests[testCaseObj.testCase]["err"];
52+
}
4953
}
5054
if (vizzuUrl.startsWith("/")) {
5155
vizzuUrl = "/" + path.relative(TestEnv.getWorkspacePath(), vizzuUrl);
@@ -64,6 +68,9 @@ class TestCase {
6468
if (!animStep.default) {
6569
testData["animstep"] = animStep.step;
6670
}
71+
if (errMsg) {
72+
testData["err"] = errMsg;
73+
}
6774
return resolve(testData);
6875
})
6976
}).catch(err => {

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

Lines changed: 80 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",
@@ -98,6 +102,9 @@ class TestCasesConfig {
98102
},
99103
animstep: {
100104
type: "string"
105+
},
106+
err: {
107+
type: "string"
101108
}
102109
},
103110
additionalProperties: false
@@ -112,6 +119,75 @@ class TestCasesConfig {
112119
additionalProperties: false
113120
};
114121
}
122+
123+
124+
static isTestCasesConfig(testCasesConfig) {
125+
const validate = new Ajv().compile(TestCasesConfig.getTestCasesConfigSchema());
126+
return validate(testCasesConfig);
127+
}
128+
129+
130+
static getTestCasesConfigSchema() {
131+
return {
132+
type: "object",
133+
properties: {
134+
suites: {
135+
type: "array",
136+
items: {
137+
type: "object",
138+
properties: {
139+
suite: {
140+
type: "string"
141+
},
142+
config: {
143+
type: "string"
144+
},
145+
tests: {
146+
type: "object",
147+
additionalProperties: {
148+
type: "object",
149+
properties: {
150+
refs: {
151+
type: "array"
152+
},
153+
animstep: {
154+
type: "string"
155+
},
156+
err: {
157+
type: "string"
158+
}
159+
},
160+
additionalProperties: false
161+
}
162+
}
163+
},
164+
required: ["suite", "config", "tests"],
165+
additionalProperties: false
166+
}
167+
},
168+
tests: {
169+
type: "object",
170+
additionalProperties: {
171+
type: "object",
172+
properties: {
173+
refs: {
174+
type: "array"
175+
},
176+
animstep: {
177+
type: "string"
178+
},
179+
err: {
180+
type: "string"
181+
}
182+
},
183+
additionalProperties: false
184+
}
185+
}
186+
},
187+
required: ["suites", "tests"],
188+
additionalProperties: false
189+
};
190+
}
115191
}
116192

117193

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe("getConfig()", () => {
1111

1212
test("if configPathList is an empty array", () => {
1313
return TestCasesConfig.getConfig([]).then(config => {
14-
expect(config).toStrictEqual({"suites": [], "tests": {}});
14+
expect(config).toEqual({"suites": [], "tests": {}});
1515
});
1616
});
1717
});
@@ -90,9 +90,15 @@ describe("getConfig()", () => {
9090
test("if config fits into schema, config is valid", () => {
9191
return TestCasesConfig.getConfig([
9292
"./modules/integration-test/test-case/test-cases-config.test/test-cases-1.json",
93-
"./modules/integration-test/test-case/test-cases-config.test/test-cases-2.json"
93+
"./modules/integration-test/test-case/test-cases-config.test/test-cases-2.json",
94+
"./modules/integration-test/test-case/test-cases-config.test/test-cases-3.json"
9495
]).then(config => {
95-
expect(config).toStrictEqual(testCasesResult);
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+
});
100+
expect(config).toEqual(testCasesResult);
101+
expect(TestCasesConfig.isTestCasesConfig(config)).toBeTruthy();
96102
});
97103
});
98104
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"suite": "/test/integration/modules/integration-test/test-cases/test-suite-3"
3+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ const testCasesResult = {
5959
]
6060
}
6161
}
62+
},
63+
{
64+
config: TestEnv.getWorkspacePath() + "/test/integration/modules/integration-test/test-case/test-cases-config.test/test-cases-3.json",
65+
suite: TestEnv.getWorkspacePath() + "/test/integration/modules/integration-test/test-cases/test-suite-3",
66+
tests: {}
6267
}
6368
],
6469
tests: {

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

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
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+
testCasesList.sort();
34+
filteredTestCasesList.sort();
35+
return resolve({testCases: testCasesList, filteredTestCases: filteredTestCasesList});
36+
});
37+
}).catch(err => {
38+
return reject(err);
2839
});
29-
});
40+
} catch(err) {
41+
return reject(err);
42+
}
3043
});
3144
});
3245
}
@@ -49,10 +62,14 @@ class TestCases {
4962
testCasesReady.push(testCaseReady);
5063
testCaseReady.then(newTestCases => {
5164
testCases = testCases.concat(newTestCases);
65+
}).catch(err => {
66+
return reject(err);
5267
});
5368
});
5469
Promise.all(testCasesReady).then(() => {
5570
return resolve(testCases);
71+
}).catch(err => {
72+
return reject(err);
5673
});
5774
}
5875
});
@@ -71,7 +88,7 @@ class TestCases {
7188
}
7289

7390

74-
static filterTestCases(testCases, suitePath, filters) {
91+
static filterTestCases(testCases, suitePath, filters=[]) {
7592
return new Promise((resolve, reject) => {
7693
let filteredTestCases = [];
7794
if (filters.length === 0) {
@@ -89,7 +106,11 @@ class TestCases {
89106
if (testCases.includes(filter)) {
90107
filteredTestCases.push(filter);
91108
} else {
92-
let filterWithSuitePath = path.join(suitePath, filter);
109+
let filterPathInSuite = "/" + path.join(
110+
path.relative(
111+
TestEnv.getWorkspacePath(),
112+
suitePath),
113+
filter);
93114
let filterRelative = "/" + path.relative(
94115
TestEnv.getWorkspacePath(),
95116
WorkspacePath.resolvePath(
@@ -99,8 +120,8 @@ class TestCases {
99120
let filterAbsolute = "/" + path.relative(
100121
TestEnv.getWorkspacePath(),
101122
filter);
102-
if(testCases.includes(filterWithSuitePath)) {
103-
filteredTestCases.push(filterWithSuitePath);
123+
if(testCases.includes(filterPathInSuite)) {
124+
filteredTestCases.push(filterPathInSuite);
104125
} else if(testCases.includes(filterRelative)) {
105126
filteredTestCases.push(filterRelative);
106127
} else if(testCases.includes(filterAbsolute)) {

0 commit comments

Comments
 (0)