Skip to content

Commit 9206928

Browse files
authored
Output logs for tests that remain pending when AVA exits
1 parent 136dde3 commit 9206928

File tree

13 files changed

+183
-0
lines changed

13 files changed

+183
-0
lines changed

lib/reporters/default.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,11 @@ export default class Reporter {
370370
}
371371

372372
this.lineWriter.writeLine(`${testsInFile.size} tests were pending in ${this.relativeFile(file)}\n`);
373+
const testTitleToLogs = evt.pendingTestsLogs.get(file);
373374
for (const title of testsInFile) {
375+
const logs = testTitleToLogs?.get(title);
374376
this.lineWriter.writeLine(`${figures.circleDotted} ${this.prefixTitle(file, title)}`);
377+
this.writeLogs({logs});
375378
}
376379

377380
this.lineWriter.writeLine('');

lib/run-status.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default class RunStatus extends Emittery {
99
super();
1010

1111
this.pendingTests = new Map();
12+
this.pendingTestsLogs = new Map();
1213

1314
this.emptyParallelRun = parallelRuns
1415
&& parallelRuns.currentFileCount === 0
@@ -60,6 +61,7 @@ export default class RunStatus extends Emittery {
6061
});
6162

6263
this.pendingTests.set(testFile, new Set());
64+
this.pendingTestsLogs.set(testFile, new Map());
6365
worker.onStateChange(data => this.emitStateChange(data));
6466
}
6567

@@ -124,22 +126,31 @@ export default class RunStatus extends Emittery {
124126
fileStats.remainingTests--;
125127
this.removePendingTest(event);
126128
break;
129+
case 'test-register-log-reference':
130+
this.addPendingTestLogs(event);
131+
break;
127132
case 'timeout':
128133
stats.timeouts++;
129134
event.pendingTests = this.pendingTests;
135+
event.pendingTestsLogs = this.pendingTestsLogs;
130136
this.pendingTests = new Map();
137+
this.pendingTestsLogs = new Map();
131138
for (const testsInFile of event.pendingTests.values()) {
132139
stats.timedOutTests += testsInFile.size;
133140
}
134141

135142
break;
136143
case 'interrupt':
137144
event.pendingTests = this.pendingTests;
145+
event.pendingTestsLogs = this.pendingTestsLogs;
138146
this.pendingTests = new Map();
147+
this.pendingTestsLogs = new Map();
139148
break;
140149
case 'process-exit':
141150
event.pendingTests = this.pendingTests;
151+
event.pendingTestsLogs = this.pendingTestsLogs;
142152
this.pendingTests = new Map();
153+
this.pendingTestsLogs = new Map();
143154
break;
144155
case 'uncaught-exception':
145156
stats.uncaughtExceptions++;
@@ -198,6 +209,10 @@ export default class RunStatus extends Emittery {
198209
return 0;
199210
}
200211

212+
addPendingTestLogs(event) {
213+
this.pendingTestsLogs.get(event.testFile)?.set(event.title, event.logs);
214+
}
215+
201216
addPendingTest(event) {
202217
if (this.pendingTests.has(event.testFile)) {
203218
this.pendingTests.get(event.testFile).add(event.title);

lib/runner.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ export default class Runner extends Emittery {
358358
notifyTimeoutUpdate: this.notifyTimeoutUpdate,
359359
});
360360

361+
this.emit('stateChange', {
362+
type: 'test-register-log-reference',
363+
title: task.title,
364+
logs: test.logs,
365+
});
366+
361367
const result = await this.runSingle(test);
362368
testOk = result.passed;
363369

test-tap/fixture/long-running.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const delay = require('delay');
33
const test = require('../../entrypoints/main.cjs');
44

55
test('slow', async t => {
6+
t.log('helpful log of a pending test');
67
await delay(5000);
78
t.pass();
89
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const delay = require('delay');
2+
3+
const test = require('../../../../entrypoints/main.cjs');
4+
5+
test('a passes', t => t.pass());
6+
7+
test('a slow', async t => {
8+
t.log('this slow test prints useful debug message just text');
9+
await delay(15_000);
10+
t.log('this never logs because test times out');
11+
t.pass();
12+
});
13+
test('a slow two', async t => {
14+
t.log('another useful debug message', {x: 5});
15+
await delay(15_000);
16+
t.log('this never logs because test times out');
17+
t.pass();
18+
});
19+
20+
test('a passes two', t => t.pass());
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const delay = require('delay');
2+
3+
const test = require('../../../../entrypoints/main.cjs');
4+
5+
test('a passes', t => t.pass());
6+
7+
test('a slow', async t => {
8+
t.log('hello world');
9+
await delay(15_000);
10+
t.log('this never prints due to test time out');
11+
t.pass();
12+
});
13+
test('a slow two', async t => {
14+
await delay(15_000);
15+
t.log('this never prints due to test time out');
16+
t.pass();
17+
});
18+
19+
test('a passes two', t => t.pass());
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

test-tap/helper/report.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ exports.only = reporter => run('only', reporter);
126126
exports.timeoutInSingleFile = reporter => run('timeoutInSingleFile', reporter);
127127
exports.timeoutInMultipleFiles = reporter => run('timeoutInMultipleFiles', reporter);
128128
exports.timeoutWithMatch = reporter => run('timeoutWithMatch', reporter, {match: ['*needle*']});
129+
exports.timeoutContextLogs = reporter => run('timeoutContextLogs', reporter);
129130
exports.watch = reporter => run('watch', reporter);
130131
exports.edgeCases = reporter => run('edgeCases', reporter, {
131132
filter: [

test-tap/integration/assorted.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url));
1414
test('timeout', {skip: ciInfo.isCI}, t => {
1515
execCli(['long-running.cjs', '-T', '1s'], (error, stdout) => {
1616
t.ok(error);
17+
t.match(stdout, 'helpful log of a pending test');
1718
t.match(stdout, /Timed out/);
1819
t.end();
1920
});
2021
});
2122

2223
test('interrupt', {skip: ciInfo.isCI}, t => {
2324
const proc = execCli(['long-running.cjs'], (_, stdout) => {
25+
t.match(stdout, 'helpful log of a pending test');
2426
t.match(stdout, /SIGINT/);
2527
t.end();
2628
});

test-tap/reporters/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ test(async t => {
5151
t.test('single file run', run('timeoutInSingleFile'));
5252
t.test('multiple files run', run('timeoutInMultipleFiles'));
5353
t.test('single file with only certain tests matched run', run('timeoutWithMatch'));
54+
t.test('logs provided during a pending test logged at the end', run('timeoutContextLogs'));
5455
t.end();
5556
});
5657
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
---tty-stream-chunk-separator
3+
✔ a › a passes
4+
---tty-stream-chunk-separator
5+
✔ a › a passes two
6+
---tty-stream-chunk-separator
7+

8+
✘ Timed out while running tests
9+
10+
2 tests were pending in a.cjs
11+
12+
◌ a › a slow
13+
ℹ this slow test prints useful debug message just text
14+
◌ a › a slow two
15+
ℹ another useful debug message {
16+
 x: 5,
17+
}
18+
19+
---tty-stream-chunk-separator
20+
✔ b › a passes
21+
---tty-stream-chunk-separator
22+
✔ b › a passes two
23+
---tty-stream-chunk-separator
24+

25+
✘ Timed out while running tests
26+
27+
2 tests were pending in b.cjs
28+
29+
◌ b › a slow
30+
ℹ hello world
31+
◌ b › a slow two
32+
33+
---tty-stream-chunk-separator
34+
─
35+
36+
4 tests passed
37+
4 tests remained pending after a timeout
38+
---tty-stream-chunk-separator
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
---tty-stream-chunk-separator
3+
✔ a › a passes
4+
---tty-stream-chunk-separator
5+
✔ a › a passes two
6+
---tty-stream-chunk-separator
7+

8+
✘ Timed out while running tests
9+
10+
2 tests were pending in a.cjs
11+
12+
◌ a › a slow
13+
ℹ this slow test prints useful debug message just text
14+
◌ a › a slow two
15+
ℹ another useful debug message {
16+
 x: 5,
17+
}
18+
19+
---tty-stream-chunk-separator
20+
✔ b › a passes
21+
---tty-stream-chunk-separator
22+
✔ b › a passes two
23+
---tty-stream-chunk-separator
24+

25+
✘ Timed out while running tests
26+
27+
2 tests were pending in b.cjs
28+
29+
◌ b › a slow
30+
ℹ hello world
31+
◌ b › a slow two
32+
33+
---tty-stream-chunk-separator
34+
─
35+
36+
4 tests passed
37+
4 tests remained pending after a timeout
38+
---tty-stream-chunk-separator
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
---tty-stream-chunk-separator
3+
✔ a › a passes
4+
---tty-stream-chunk-separator
5+
✔ a › a passes two
6+
---tty-stream-chunk-separator
7+

8+
✘ Timed out while running tests
9+
10+
2 tests were pending in a.cjs
11+
12+
◌ a › a slow
13+
ℹ this slow test prints useful debug message just text
14+
◌ a › a slow two
15+
ℹ another useful debug message {
16+
 x: 5,
17+
}
18+
19+
---tty-stream-chunk-separator
20+
✔ b › a passes
21+
---tty-stream-chunk-separator
22+
✔ b › a passes two
23+
---tty-stream-chunk-separator
24+

25+
✘ Timed out while running tests
26+
27+
2 tests were pending in b.cjs
28+
29+
◌ b › a slow
30+
ℹ hello world
31+
◌ b › a slow two
32+
33+
---tty-stream-chunk-separator
34+
─
35+
36+
4 tests passed
37+
4 tests remained pending after a timeout
38+
---tty-stream-chunk-separator

0 commit comments

Comments
 (0)