Skip to content

Commit ed02d09

Browse files
committed
reporters: Misc clean up
1 parent 5439843 commit ed02d09

File tree

5 files changed

+82
-116
lines changed

5 files changed

+82
-116
lines changed

bin/qtap.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ if (opts.version) {
123123
.replace(/^.+?$/m, (m) => util.styleText('bold', m))
124124
.replace(/\n(^.+)$/ms, (m, rest) => '\n' + util.styleText('grey', rest));
125125
console.error(formatted);
126+
127+
if (e.cause) {
128+
console.error(util.styleText('grey', String(e.cause?.message)));
129+
}
126130
} else {
127131
// Print including full stack trace
128132
console.error(e);

src/reporters.js

Lines changed: 62 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -4,87 +4,50 @@ import yaml from 'yaml';
44

55
import { shortenTestFileLabels } from './util.js';
66

7-
function dynamic (eventbus) {
8-
/**
9-
* @typedef {Object} ClientState
10-
* @property {string} clientId
11-
* @property {string} displayName
12-
* @property {string} status
13-
* @property {null|string} lastline
14-
*/
15-
16-
/** @type {Object<string,ClientState[]>} */
17-
const clientsByFile = Object.create(null);
18-
/** @type {Object<string,ClientState>} */
19-
const clientsById = Object.create(null);
20-
21-
let screen = '';
22-
23-
function render () {
24-
const icons = { waiting: '⢎', progress: '⠧', success: '✔', failure: '✘' };
25-
let str = '';
26-
for (const testFile in clientsByFile) {
27-
str += `\nRunning ${testFile}\n`;
28-
for (const client of clientsByFile[testFile]) {
29-
str += `* ${client.displayName} ${icons[client.status]} ${client.lastline || ''}\n`;
30-
}
31-
}
32-
33-
if (screen) {
34-
const oldHeight = screen.split('\n').length;
35-
for (let i = 1; i < oldHeight; i++) {
36-
process.stdout.write('\x1b[A\x1b[K');
37-
}
38-
}
39-
40-
process.stdout.write(str);
41-
screen = str;
42-
}
43-
44-
eventbus.on('client', (event) => {
45-
const client = {
46-
clientId: event.clientId,
47-
displayName: event.displayName,
48-
status: 'waiting',
49-
lastline: null
50-
};
51-
52-
clientsByFile[event.testFile] ??= [];
53-
clientsByFile[event.testFile].push(client);
54-
clientsById[event.clientId] = client;
55-
render();
56-
});
57-
58-
eventbus.on('clientonline', (event) => {
59-
clientsById[event.clientId].status = 'progress';
60-
render();
61-
});
62-
63-
eventbus.on('clientresult', (event) => {
64-
clientsById[event.clientId].status = event.ok ? 'success' : 'failure';
65-
render();
66-
});
67-
68-
/*
69-
const browserCount = (clients.size / testFiles.size);
70-
let onlineMsg;
71-
if (testFiles.size === 1 && browserCount === 1) {
72-
onlineMsg = util.styleText('grey', `Running tests in ${client.browser}`);
73-
} else if (testFiles.size === 1) {
74-
onlineMsg = util.styleText('grey', `Running tests in ${browserCount} browsers`);
75-
} else if (browserCount === 1) {
76-
onlineMsg = util.styleText('grey', `Running ${testFiles.size} test files in ${client.browser}`);
77-
} else {
78-
onlineMsg = util.styleText('grey', `Running ${testFiles.size} test files in ${browserCount} browsers`);
79-
}
80-
*/
7+
function dynamic (_eventbus) {
8+
// const icons = { waiting: '⢎', progress: '⠧', success: '✔', failure: '✘' };
9+
// "interval": 80,
10+
// "frames": [
11+
// "⠋",
12+
// "⠙",
13+
// "⠹",
14+
// "⠸",
15+
// "⠼",
16+
// "⠴",
17+
// "⠦",
18+
// "⠧",
19+
// "⠇",
20+
// "⠏"
21+
// ]
22+
// "frames": [
23+
// "⢎ ",
24+
// "⠎⠁",
25+
// "⠊⠑",
26+
// "⠈⠱",
27+
// " ⡱",
28+
// "⢀⡰",
29+
// "⢄⡠",
30+
// "⢆⡀"
31+
// ]
32+
// let screen = '';
33+
// function render () {
34+
// let str = '';
35+
// if (screen) {
36+
// const oldHeight = screen.split('\n').length;
37+
// for (let i = 1; i < oldHeight; i++) {
38+
// process.stdout.write('\x1b[A\x1b[K');
39+
// }
40+
// }
41+
// process.stdout.write(str);
42+
// screen = str;
43+
// }
8144
}
8245

8346
function plain (eventbus) {
8447
const WAIT_MSG_GRACE = 3000;
8548
const TEST_MSG_GRACE = 1000;
8649

87-
const perfOrigin = performance.now();
50+
let perfOrigin;
8851

8952
/**
9053
* @typedef {Object} Client
@@ -196,6 +159,8 @@ function plain (eventbus) {
196159
const client = /** @type {Client} */ (clients.get(event.clientId));
197160
clearTimeout(client.waitMsgTimer);
198161

162+
perfOrigin ??= performance.now();
163+
199164
let line;
200165
if (browserCount === 1) {
201166
line = util.styleText('grey', `${client.linePrefix}⠧ Running tests in ${client.browser}`);
@@ -367,51 +332,36 @@ export default { none, minimal };
367332
368333
===============================================================
369334
370-
Running /test/timeout.html
371-
* Firefox ⠧ ok 2 Baz > this thing
372-
* Chrome ⠧ ok 1 Foo bar
335+
$ qtap test/fixtures/pass.html
336+
[Firefox Headless] ⠧ ok 2 Baz > this thing
337+
[Chrome Headless ] ⠧ ok 1 Foo bar
373338
374339
===============================================================
375340
376-
Running /test/timeout.html
377-
* Firefox ✘ Timed out after 30s of inactivity
378-
* Chrome Timed out after 30s of inactivity
341+
$ qtap --timeout 3 test/fixtures/timeout.html
342+
[Firefox Headless]Test timed out after 30s
343+
[Chrome Headless ]Test timed out after 30s
379344
380345
===============================================================
381346
382347
Running /test/connect-timeout.html
383-
* Firefox ⢎ Waiting...
384-
* Chrome ⢎ Waiting...
348+
$ bin/qtap.js -c test/fixtures/qtap.config.js -b fakeRefuse test/fixtures/pass.html
349+
[Firefox Headless] ⢎ Waiting for browser to connect...
350+
[Chrome Headless ] ⢎ Waiting for browser to connect...
385351
386352
===============================================================
387353
388-
Running /test/connect-timeout.html
389-
* Firefox ✘ Browser did not start within 60s
390-
* Chrome ✘ Browser did not start within 60s after 3 retries.
391-
392-
# Spinner
393-
394-
"interval": 80,
395-
"frames": [
396-
"⠋",
397-
"⠙",
398-
"⠹",
399-
"⠸",
400-
"⠼",
401-
"⠴",
402-
"⠦",
403-
"⠧",
404-
"⠇",
405-
"⠏"
406-
]
407-
"frames": [
408-
"⢎ ",
409-
"⠎⠁",
410-
"⠊⠑",
411-
"⠈⠱",
412-
" ⡱",
413-
"⢀⡰",
414-
"⢄⡠",
415-
"⢆⡀"
416-
]
354+
$ bin/qtap.js -c test/fixtures/qtap.config.js --connect-timeout 3 -b fakeRefuse test/fixtures/pass.html
355+
✘ Browser did not start within 6s
356+
357+
$ bin/qtap.js -c test/fixtures/qtap.config.js --connect-timeout 3 -b fakeLazy test/fixtures/fake_pass_4.txt
358+
⠧ Waiting for browser to connect
359+
⠧ Running tests in fakeLazy
360+
✔ Completed 4 tests
361+
362+
===============================================================
363+
364+
$ qtap -c test/fixtures/qtap.config.js -b fakeRefuseAlways test/fixtures/pass.html
365+
✘ Browser did not start within 60s after 3 attempts.
366+
417367
*/

src/server.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class ControlServer {
195195
body = (await fsPromises.readFile(file)).toString();
196196
} catch (e) {
197197
// @ts-ignore - TypeScript @types/node lacks `Error(,options)`
198-
throw new Error('Could not open ' + this.testFile, { cause: e });
198+
throw new util.QTapError('Could not open ' + this.testFile, { cause: e });
199199
}
200200
}
201201

@@ -461,9 +461,12 @@ class ControlServer {
461461
controller = new AbortController();
462462
continue;
463463
}
464+
if (e instanceof util.BrowserConnectTimeout && maxTries > 1) {
465+
throw new util.BrowserConnectTimeout(`Browser did not start within ${this.connectTimeout}s after ${i} attempts`);
466+
}
464467
if (e instanceof util.QTapError) {
465468
e.qtapClient = {
466-
browser: browserFn.displayName,
469+
browser: browser.getDisplayName(),
467470
testFile: this.testFile
468471
};
469472
}
@@ -476,7 +479,7 @@ class ControlServer {
476479
} catch (e) {
477480
if (e instanceof util.QTapError) {
478481
e.qtapClient = {
479-
browser: browserFn.displayName,
482+
browser: browser.getDisplayName(),
480483
testFile: this.testFile
481484
};
482485
}

test/fixtures/qtap.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ async function fakeRefuse (_url, signals) {
143143
}
144144
fakeRefuse.allowRetries = false;
145145

146+
async function fakeRefuseAlways (_url, signals) {
147+
await new Promise((resolve, reject) => {
148+
signals.browser.addEventListener('abort', () => {
149+
reject('You may retry but I will never connect.');
150+
});
151+
});
152+
}
153+
146154
const snoozeByFile = {};
147155
async function fakeLazy (url, signals, logger) {
148156
const path = new URL(url).pathname;
@@ -176,6 +184,7 @@ export default {
176184
fakeFailAsync,
177185
fakeSlowFail,
178186
fakeRefuse,
187+
fakeRefuseAlways,
179188
fakeLazy,
180189
},
181190
reporters: {

test/qtap.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ QUnit.module('qtap', function (hooks) {
366366
},
367367
expected: [
368368
'online: running notfound.html',
369-
'error: Error: Could not open notfound.html',
369+
'error: Could not open notfound.html',
370370
],
371371
exitCode: null
372372
},

0 commit comments

Comments
 (0)