Skip to content

Commit

Permalink
Update test measures script (#1123)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed Jun 15, 2024
1 parent bae1e57 commit 0a7a178
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion source/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ view.View = class {
this._find = null;
this._modelFactoryService = new view.ModelFactoryService(this._host);
this._modelFactoryService.import();
this._worker = new view.Worker(this._host);
this._worker = this._host.environment('measure') ? null : new view.Worker(this._host);
}

async start() {
Expand Down
12 changes: 9 additions & 3 deletions test/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,29 @@ class Worker {
const main = async () => {
try {
const args = process.argv.length > 2 ? process.argv.slice(2) : [];
const measure = args.length > 0 && args[0] === 'measure' ? args.shift() : null;
const exists = await Promise.all(args.map((pattern) => access(pattern)));
const paths = exists.length > 0 && exists.every((value) => value);
const patterns = paths ? [] : args;
const targets = paths ? args.map((path) => ({ target: path })) : await configuration();
const queue = new Queue(targets, patterns);
const threads = inspector.url() ? 1 : undefined;
const threads = measure || inspector.url() ? 1 : undefined;
const logger = new Logger(threads);
const measures = new Table(['name', 'download', 'load', 'validate', 'render']);
// await measures.log(dirname('..', 'dist', 'test', 'measures.csv'));
if (measure) {
await measures.log(dirname('..', 'dist', 'test', 'measures.csv'));
}
if (threads === 1) {
const worker = await import('./worker.js');
for (let item = queue.pop(); item; item = queue.pop()) {
const target = new worker.Target(item);
target.measures = measure ? new Map([['name', item.name]]) : null;
target.on('status', (_, message) => logger.update('', message));
/* eslint-disable no-await-in-loop */
await target.execute();
await measures.add(target.measures);
if (target.measures) {
await measures.add(target.measures);
}
/* eslint-enable no-await-in-loop */
}
} else {
Expand Down
38 changes: 26 additions & 12 deletions test/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ const host = {};

host.TestHost = class {

constructor(window) {
this.errors = [];
this.window = window;
this.document = window.document;
constructor(window, environment) {
this._window = window;
this._environment = environment;
this._errors = [];
host.TestHost.source = host.TestHost.source || dirname('..', 'source');
}

Expand All @@ -58,11 +58,20 @@ host.TestHost = class {
async start() {
}

get window() {
return this._window;
}

get document() {
return this._window.document;
}

get errors() {
return this._errors;
}

environment(name) {
if (name === 'zoom') {
return 'none';
}
return null;
return this._environment[name];
}

screen(/* name */) {
Expand Down Expand Up @@ -99,7 +108,7 @@ host.TestHost = class {
}

exception(error /*, fatal */) {
this.errors.push(error);
this._errors.push(error);
}

message() {
Expand Down Expand Up @@ -343,7 +352,6 @@ export class Target {
this.events = {};
this.tags = new Set(this.tags);
this.folder = item.type ? path.normalize(dirname('..', 'third_party' , 'test', item.type)) : process.cwd();
this.measures = new Map([['name', this.name]]);
}

on(event, callback) {
Expand All @@ -366,7 +374,11 @@ export class Target {
async execute() {
await zip.Archive.import();
this.window = this.window || new Window();
this.host = await new host.TestHost(this.window);
const environment = {
zoom: 'none',
measure: this.measures ? true : false
};
this.host = await new host.TestHost(this.window, environment);
this.view = new view.View(this.host);
this.view.options.attributes = true;
this.view.options.initializers = true;
Expand All @@ -379,7 +391,9 @@ export class Target {
err = error;
}
const duration = Number(process.hrtime.bigint() - start) / 1e9;
this.measures.set(method.name, duration);
if (this.measures) {
this.measures.set(method.name, duration);
}
if (err) {
throw err;
}
Expand Down

0 comments on commit 0a7a178

Please sign in to comment.