Skip to content

Commit f565ee8

Browse files
committed
Update test script
1 parent 96cda05 commit f565ee8

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

source/view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ view.View = class {
2626
this._find = null;
2727
this._modelFactoryService = new view.ModelFactoryService(this._host);
2828
this._modelFactoryService.import();
29-
this._worker = this._host.environment('measure') ? null : new view.Worker(this._host);
29+
this._worker = this._host.environment('serial') ? null : new view.Worker(this._host);
3030
}
3131

3232
async start() {

test/models.js

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ const access = async (path) => {
2828
}
2929
};
3030

31-
const exit = (error) => {
31+
const error = (e) => {
3232
/* eslint-disable no-console */
33-
console.error(`${error.name}: ${error.message}`);
34-
if (error.cause) {
35-
console.error(` ${error.cause.name}: ${error.cause.message}`);
33+
console.error(`${e.name}: ${e.message}`);
34+
if (e.cause) {
35+
console.error(` ${e.cause.name}: ${e.cause.message}`);
3636
}
37+
};
38+
39+
const exit = (e) => {
40+
error(e);
3741
/* eslint-enable no-console */
3842
process.exit(1);
3943
};
@@ -265,13 +269,26 @@ class Worker {
265269

266270
const main = async () => {
267271
try {
268-
const args = { inputs: [], measure: false, profile: false };
272+
const args = { inputs: [], measure: false, profile: false, continue: false, serial: false };
269273
if (process.argv.length > 2) {
270274
for (const arg of process.argv.slice(2)) {
271275
switch (arg) {
272-
case 'measure': args.measure = true; break;
273-
case 'profile': args.profile = true; break;
274-
default: args.inputs.push(arg); break;
276+
case 'measure': args.measure = true; args.serial = true; break;
277+
case 'profile': args.profile = true; args.serial = true; break;
278+
case 'continue': args.continue = true; args.serial = true; break;
279+
default: {
280+
// eslint-disable-next-line no-await-in-loop
281+
const exists = await access(arg);
282+
if (exists || !/[*?[\]]/.test(arg)) {
283+
args.inputs.push(arg);
284+
} else {
285+
const iterator = fs.glob(arg, { cwd: process.cwd() });
286+
// eslint-disable-next-line no-await-in-loop
287+
const files = await Array.fromAsync(iterator);
288+
args.inputs.push(...files);
289+
}
290+
break;
291+
}
275292
}
276293
}
277294
}
@@ -280,7 +297,7 @@ const main = async () => {
280297
const patterns = paths ? [] : args.inputs;
281298
const targets = paths ? args.inputs.map((path) => ({ target: path, tags: 'quantization,validation' })) : await configuration();
282299
const queue = new Queue(targets, patterns);
283-
const threads = args.measure || inspector.url() ? 1 : undefined;
300+
const threads = args.serial || inspector.url() ? 1 : undefined;
284301
const logger = new Logger(threads);
285302
let measures = null;
286303
if (args.measure) {
@@ -303,17 +320,32 @@ const main = async () => {
303320
}
304321
if (threads === 1) {
305322
const worker = await import('./worker.js');
323+
const total = queue.length;
324+
let success = 0;
306325
for (let item = queue.pop(); item; item = queue.pop()) {
307326
const target = new worker.Target(item);
308327
target.measures = measures ? new Map() : null;
328+
target.serial = args.serial;
309329
target.on('status', (sender, message) => logger.update('', message));
310330
/* eslint-disable no-await-in-loop */
311-
await target.execute();
331+
try {
332+
await target.execute();
333+
success += 1;
334+
} catch (e) {
335+
if (args.continue) {
336+
error(e);
337+
} else {
338+
exit(e);
339+
}
340+
}
312341
if (target.measures) {
313342
await measures.add(target.measures);
314343
}
315344
/* eslint-enable no-await-in-loop */
316345
}
346+
if (args.continue) {
347+
write(` ${success} / ${total} = ${success * 100 / total}%\n`);
348+
}
317349
} else {
318350
const threads = Math.min(10, Math.round(0.7 * os.cpus().length), queue.length);
319351
const identifiers = [...new Array(threads).keys()].map((value) => value.toString());

test/worker.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class Target {
5151
this.tags = new Set(this.tags);
5252
this.folder = item.type ? path.normalize(dirname('..', 'third_party' , 'test', item.type)) : process.cwd();
5353
this.assert = !this.assert || Array.isArray(this.assert) ? this.assert : [this.assert];
54+
this.serial = false;
5455
}
5556

5657
on(event, callback) {
@@ -75,10 +76,7 @@ export class Target {
7576
this.measures.set('name', this.name);
7677
}
7778
await zip.Archive.import();
78-
const environment = {
79-
zoom: 'none',
80-
measure: this.measures ? true : false
81-
};
79+
const environment = { zoom: 'none', serial: this.serial };
8280
this.host = await new mock.Host(environment);
8381
this.view = new view.View(this.host);
8482
this.view.options.attributes = true;

0 commit comments

Comments
 (0)