Skip to content

Commit f93162f

Browse files
authored
Merge pull request #18 from vizzuhq/veghdev
vizzutest improvements
2 parents 832b660 + 7468eb1 commit f93162f

File tree

2 files changed

+67
-38
lines changed

2 files changed

+67
-38
lines changed

ci/docker/vizzu-test-cloudbuild

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key
1313
ADD . /workspace/
1414
WORKDIR /workspace/test/integration
1515
RUN npm install
16-
RUN node vizzutest.js -r DISABLED
16+
RUN node vizzutest.js -r DISABLED -u /example/lib/vizzu.min.js

test/integration/vizzutest.js

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const { resolve } = require('path');
22

3-
const remoteLatestBucket = 'vizzu-lib-main-sha.storage.googleapis.com';
4-
const remoteStableBucket = 'vizzu-lib-main.storage.googleapis.com';
3+
const remoteLatestBucket = 'https://vizzu-lib-main-sha.storage.googleapis.com';
4+
const remoteStableBucket = 'https://vizzu-lib-main.storage.googleapis.com';
5+
const remoteCdn = 'https://cdn.jsdelivr.net/npm/vizzu';
56
const defaultAnimStep = '20%';
67
const defaultTestCaseTimeout = 60000;
78
const padLength = 7;
@@ -40,8 +41,6 @@ try {
4041
#url;
4142
#refurl;
4243

43-
#osKey = 'ubuntu_focal';
44-
4544

4645
constructor(testCasesPath) {
4746
if(path.isAbsolute(testCasesPath)) {
@@ -116,40 +115,62 @@ try {
116115

117116
async #setUrl(url) {
118117
try {
119-
let vizzuMinJs = 'vizzu.min.js';
120118
let vizzuJs = 'vizzu.js';
119+
let vizzuMinJs = 'vizzu.min.js';
120+
let vizzuTypeForced;
121121

122122
if (url.endsWith(vizzuMinJs)) {
123123
url = url.substring(0, url.length - vizzuMinJs.length);
124-
}
125-
if (url.endsWith(vizzuJs)) {
124+
vizzuTypeForced = vizzuMinJs;
125+
} else if (url.endsWith(vizzuJs)) {
126126
url = url.substring(0, url.length - vizzuJs.length);
127+
vizzuTypeForced = vizzuJs
127128
}
129+
128130
if (url.endsWith('/')) {
129131
url = url.substring(0, url.length - 1);
130132
}
131133

132-
if (url.includes(remoteStableBucket)) {
133-
url = 'https://' + remoteStableBucket + '/lib';
134-
} else if (url.includes(remoteLatestBucket)) {
135-
url = 'https://' + remoteLatestBucket + '/lib-' + url.split('/lib-')[1].substring(0,7);
134+
if (url.toLowerCase() === 'head') {
135+
url = remoteStableBucket + '/lib';
136+
} else if (/^[A-Za-z0-9]+$/.test(url) && url.length === 7) {
137+
url = remoteLatestBucket + '/lib-' + url;
138+
} else if (/^(\d+\.)?(\d+\.)?(\*|\d+)$/.test(url)) {
139+
url = remoteCdn + '@' + url + '/dist';
140+
vizzuTypeForced = vizzuMinJs;
136141
}
137142

138143
if (url.startsWith('https://')) {
139-
if (await this.#isUrlExist(url + '/' + vizzuMinJs)) {
140-
url = url + '/' + vizzuMinJs;
141-
} else if (await this.#isUrlExist(url + '/' + vizzuJs)) {
142-
url = url + '/' + vizzuJs;
144+
if (vizzuTypeForced) {
145+
if (await this.#isUrlExist(url + '/' + vizzuTypeForced)) {
146+
url = url + '/' + vizzuTypeForced;
147+
} else {
148+
throw new Error('ENOENT: ' + url + '/' + vizzuTypeForced);
149+
}
143150
} else {
144-
throw new Error('ENOENT: ' + url + '/' + vizzuMinJs + '|' + url + '/' + vizzuJs);
151+
if (await this.#isUrlExist(url + '/' + vizzuJs)) {
152+
url = url + '/' + vizzuJs;
153+
} else if (await this.#isUrlExist(url + '/' + vizzuMinJs)) {
154+
url = url + '/' + vizzuMinJs;
155+
} else {
156+
throw new Error('ENOENT: ' + url + '/' + vizzuJs + '|' + url + '/' + vizzuMinJs);
157+
}
145158
}
146159
} else {
147-
if (fs.existsSync(this.#workspacePath + url + '/' + vizzuMinJs)) {
148-
url = url + '/' + vizzuMinJs;
149-
} else if (fs.existsSync(this.#workspacePath + url + '/' + vizzuJs)) {
150-
url = url + '/' + vizzuJs;
160+
if (vizzuTypeForced) {
161+
if (fs.existsSync(this.#workspacePath + url + '/' + vizzuTypeForced)) {
162+
url = url + '/' + vizzuTypeForced;
163+
} else {
164+
throw new Error('ENOENT: ' + url + '/' + vizzuTypeForced);
165+
}
151166
} else {
152-
throw new Error('ENOENT: ' + path.resolve(this.#workspacePath + url + '/' + vizzuMinJs) + '|' + path.resolve(this.#workspacePath + url + '/' + vizzuJs));
167+
if (fs.existsSync(this.#workspacePath + url + '/' + vizzuJs)) {
168+
url = url + '/' + vizzuJs;
169+
} else if (fs.existsSync(this.#workspacePath + url + '/' + vizzuMinJs)) {
170+
url = url + '/' + vizzuMinJs;
171+
} else {
172+
throw new Error('ENOENT: ' + path.resolve(this.#workspacePath + url + '/' + vizzuJs) + '|' + path.resolve(this.#workspacePath + url + '/' + vizzuMinJs));
173+
}
153174
}
154175
}
155176
this.#url = url;
@@ -170,7 +191,7 @@ try {
170191
for (let i = 0; i < this.#testCasesRun.length; i++) {
171192
await this.#runTestCase(i);
172193
}
173-
if (argv.reportLevel != 'DISABLED') {
194+
if (argv.reportLevel != 'DISABLED' && argv.t != 'DISABLED') {
174195
this.#createJson(__dirname + '/test_report/', this.#testCasesRun);
175196
}
176197
}
@@ -182,6 +203,7 @@ try {
182203
}
183204

184205
#startTestSuite() {
206+
fs.rmSync(__dirname + '/test_report/' + 'test_cases.json', { force: true });
185207
this.#workspace = new Workspace(this.#workspacePath);
186208
this.#workspace.openWorkspace();
187209
console.log('[ HOSTING ]' + ' ' + '[ ' + 'http://127.0.0.1:' + String(this.#workspace.getWorkspacePort()) + ' ]');
@@ -285,15 +307,15 @@ try {
285307
if (this.#refurl === undefined) {
286308
let vizzuMinJs = 'vizzu.min.js';
287309
let vizzuJs = 'vizzu.js';
288-
let shaUrl = await fetch('https://' + remoteStableBucket + '/lib/sha.txt');
310+
let shaUrl = await fetch(remoteStableBucket + '/lib/sha.txt');
289311
sha = await shaUrl.text();
290312
sha = sha.trim();
291-
if (await this.#isUrlExist('https://' + remoteLatestBucket + '/lib-' + sha + '/' + vizzuMinJs)) {
292-
this.#refurl = 'https://' + remoteLatestBucket + '/lib-' + sha + '/' + vizzuMinJs;
293-
} else if (await this.#isUrlExist('https://' + remoteLatestBucket + '/lib-' + sha + '/' + vizzuJs)) {
294-
this.#refurl = 'https://' + remoteLatestBucket + '/lib-' + sha + '/' + vizzuJs;
313+
if (await this.#isUrlExist(remoteLatestBucket + '/lib-' + sha + '/' + vizzuMinJs)) {
314+
this.#refurl = remoteLatestBucket + '/lib-' + sha + '/' + vizzuMinJs;
315+
} else if (await this.#isUrlExist(remoteLatestBucket + '/lib-' + sha + '/' + vizzuJs)) {
316+
this.#refurl = remoteLatestBucket + '/lib-' + sha + '/' + vizzuJs;
295317
} else {
296-
throw new Error('ENOENT: ' + 'https://' + remoteLatestBucket + '/lib-' + sha + '/' + vizzuMinJs + '|' + 'https://' + remoteLatestBucket + '/lib-' + sha + '/' + vizzuJs);
318+
throw new Error('ENOENT: ' + remoteLatestBucket + '/lib-' + sha + '/' + vizzuMinJs + '|' + remoteLatestBucket + '/lib-' + sha + '/' + vizzuJs);
297319
}
298320
}
299321
let testCaseRefData = await this.#runTestCaseClient(testCase, this.#refurl);
@@ -380,6 +402,7 @@ try {
380402
}
381403
}
382404
let hashes = this.#getTestCaseRefHash(testCase);
405+
this.#testCasesData[testCase]['refs'] = [ testCaseData.hash.substring(0,7) ];
383406
if (hashes === undefined) {
384407
return { testCaseResult: 'WARNING', testCaseReultDescription: 'ref hash does not exist' };
385408
} else {
@@ -427,14 +450,17 @@ try {
427450
fs.mkdirSync(testSuiteResultPath, { recursive: true });
428451
let testCasesData = {};
429452
testCases.forEach(testCase => {
453+
if (argv.t == 'FAILED' && !this.#testSuiteResults.FAILED.includes(testCase)) return;
430454
testCasesData[testCase] = this.#testCasesData[testCase];
431455
});
432-
testCasesData = JSON.stringify(testCasesData, null, 4);
433-
fs.writeFile(testSuiteResultPath + 'test_cases.json', testCasesData, (err) => {
434-
if (err) {
435-
throw err;
436-
}
437-
});
456+
if (Object.keys(testCasesData).length !== 0) {
457+
testCasesData = JSON.stringify(testCasesData, null, 4);
458+
fs.writeFile(testSuiteResultPath + 'test_cases.json', testCasesData, (err) => {
459+
if (err) {
460+
throw err;
461+
}
462+
});
463+
}
438464
}
439465
}
440466

@@ -464,11 +490,14 @@ try {
464490
.alias('r', 'reportLevel')
465491
.choices('r', ['INFO', 'WARN', 'ERROR', 'DISABLED'])
466492
.default('r', 'INFO')
467-
.describe('r', 'Set report level')
493+
.describe('r', 'Set report detail level')
494+
.choices('t', ['ALL', 'FAILED', 'DISABLED'])
495+
.default('t', 'FAILED')
496+
.describe('t', 'Set test_report/test_cases.json detail level')
468497
.alias('u', 'vizzuUrl')
469-
.describe('u', 'Change vizzu.min.js url')
498+
.describe('u', 'Change vizzu.js url')
470499
.nargs('u', 1)
471-
.default('u', '/example/lib')
500+
.default('u', '/example/lib/vizzu.js')
472501
.argv;
473502

474503
let test = new TestSuite(__dirname + '/test_cases');

0 commit comments

Comments
 (0)