Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output logs for tests that remain pending when AVA exits #3125

Merged
merged 5 commits into from Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/reporters/default.js
Expand Up @@ -370,8 +370,11 @@ export default class Reporter {
}

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

this.lineWriter.writeLine('');
Expand Down
15 changes: 15 additions & 0 deletions lib/run-status.js
Expand Up @@ -9,6 +9,7 @@ export default class RunStatus extends Emittery {
super();

this.pendingTests = new Map();
this.pendingTestsLogs = new Map();

this.emptyParallelRun = parallelRuns
&& parallelRuns.currentFileCount === 0
Expand Down Expand Up @@ -60,6 +61,7 @@ export default class RunStatus extends Emittery {
});

this.pendingTests.set(testFile, new Set());
this.pendingTestsLogs.set(testFile, new Map());
worker.onStateChange(data => this.emitStateChange(data));
}

Expand Down Expand Up @@ -124,22 +126,31 @@ export default class RunStatus extends Emittery {
fileStats.remainingTests--;
this.removePendingTest(event);
break;
case 'test-register-log-reference':
this.addPendingTestLogs(event);
break;
case 'timeout':
stats.timeouts++;
event.pendingTests = this.pendingTests;
event.pendingTestsLogs = this.pendingTestsLogs;
this.pendingTests = new Map();
this.pendingTestsLogs = new Map();
for (const testsInFile of event.pendingTests.values()) {
stats.timedOutTests += testsInFile.size;
}

break;
case 'interrupt':
event.pendingTests = this.pendingTests;
event.pendingTestsLogs = this.pendingTestsLogs;
this.pendingTests = new Map();
this.pendingTestsLogs = new Map();
break;
case 'process-exit':
event.pendingTests = this.pendingTests;
event.pendingTestsLogs = this.pendingTestsLogs;
this.pendingTests = new Map();
this.pendingTestsLogs = new Map();
break;
case 'uncaught-exception':
stats.uncaughtExceptions++;
Expand Down Expand Up @@ -198,6 +209,10 @@ export default class RunStatus extends Emittery {
return 0;
}

addPendingTestLogs(event) {
this.pendingTestsLogs.get(event.testFile)?.set(event.title, event.logs);
}

addPendingTest(event) {
if (this.pendingTests.has(event.testFile)) {
this.pendingTests.get(event.testFile).add(event.title);
Expand Down
6 changes: 6 additions & 0 deletions lib/runner.js
Expand Up @@ -358,6 +358,12 @@ export default class Runner extends Emittery {
notifyTimeoutUpdate: this.notifyTimeoutUpdate,
});

this.emit('stateChange', {
type: 'test-register-log-reference',
title: task.title,
logs: test.logs,
});

const result = await this.runSingle(test);
testOk = result.passed;

Expand Down
1 change: 1 addition & 0 deletions test-tap/fixture/long-running.cjs
Expand Up @@ -3,6 +3,7 @@ const delay = require('delay');
const test = require('../../entrypoints/main.cjs');

test('slow', async t => {
t.log('helpful log of a pending test');
await delay(5000);
t.pass();
});
Expand Down
20 changes: 20 additions & 0 deletions test-tap/fixture/report/timeoutcontextlogs/a.cjs
@@ -0,0 +1,20 @@
const delay = require('delay');

const test = require('../../../../entrypoints/main.cjs');

test('a passes', t => t.pass());

test('a slow', async t => {
t.log('this slow test prints useful debug message just text');
await delay(15_000);
t.log('this never logs because test times out');
t.pass();
});
test('a slow two', async t => {
t.log('another useful debug message', {x: 5});
await delay(15_000);
t.log('this never logs because test times out');
t.pass();
});

test('a passes two', t => t.pass());
19 changes: 19 additions & 0 deletions test-tap/fixture/report/timeoutcontextlogs/b.cjs
@@ -0,0 +1,19 @@
const delay = require('delay');

const test = require('../../../../entrypoints/main.cjs');

test('a passes', t => t.pass());

test('a slow', async t => {
t.log('hello world');
await delay(15_000);
t.log('this never prints due to test time out');
t.pass();
});
test('a slow two', async t => {
await delay(15_000);
t.log('this never prints due to test time out');
t.pass();
});

test('a passes two', t => t.pass());
1 change: 1 addition & 0 deletions test-tap/fixture/report/timeoutcontextlogs/package.json
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions test-tap/helper/report.js
Expand Up @@ -126,6 +126,7 @@ exports.only = reporter => run('only', reporter);
exports.timeoutInSingleFile = reporter => run('timeoutInSingleFile', reporter);
exports.timeoutInMultipleFiles = reporter => run('timeoutInMultipleFiles', reporter);
exports.timeoutWithMatch = reporter => run('timeoutWithMatch', reporter, {match: ['*needle*']});
exports.timeoutContextLogs = reporter => run('timeoutContextLogs', reporter);
exports.watch = reporter => run('watch', reporter);
exports.edgeCases = reporter => run('edgeCases', reporter, {
filter: [
Expand Down
2 changes: 2 additions & 0 deletions test-tap/integration/assorted.js
Expand Up @@ -14,13 +14,15 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url));
test('timeout', {skip: ciInfo.isCI}, t => {
execCli(['long-running.cjs', '-T', '1s'], (error, stdout) => {
t.ok(error);
t.match(stdout, 'helpful log of a pending test');
t.match(stdout, /Timed out/);
t.end();
});
});

test('interrupt', {skip: ciInfo.isCI}, t => {
const proc = execCli(['long-running.cjs'], (_, stdout) => {
t.match(stdout, 'helpful log of a pending test');
t.match(stdout, /SIGINT/);
t.end();
});
Expand Down
1 change: 1 addition & 0 deletions test-tap/reporters/default.js
Expand Up @@ -51,6 +51,7 @@ test(async t => {
t.test('single file run', run('timeoutInSingleFile'));
t.test('multiple files run', run('timeoutInMultipleFiles'));
t.test('single file with only certain tests matched run', run('timeoutWithMatch'));
t.test('logs provided during a pending test logged at the end', run('timeoutContextLogs'));
t.end();
});
});
38 changes: 38 additions & 0 deletions test-tap/reporters/default.timeoutcontextlogs.v14.log
@@ -0,0 +1,38 @@

---tty-stream-chunk-separator
✔ a › a passes
---tty-stream-chunk-separator
✔ a › a passes two
---tty-stream-chunk-separator

✘ Timed out while running tests

2 tests were pending in a.cjs

◌ a › a slow
ℹ this slow test prints useful debug message just text
◌ a › a slow two
ℹ another useful debug message {
 x: 5,
}

---tty-stream-chunk-separator
✔ b › a passes
---tty-stream-chunk-separator
✔ b › a passes two
---tty-stream-chunk-separator

✘ Timed out while running tests

2 tests were pending in b.cjs

◌ b › a slow
ℹ hello world
◌ b › a slow two

---tty-stream-chunk-separator
─

4 tests passed
4 tests remained pending after a timeout
---tty-stream-chunk-separator
38 changes: 38 additions & 0 deletions test-tap/reporters/default.timeoutcontextlogs.v16.log
@@ -0,0 +1,38 @@

---tty-stream-chunk-separator
✔ a › a passes
---tty-stream-chunk-separator
✔ a › a passes two
---tty-stream-chunk-separator

✘ Timed out while running tests

2 tests were pending in a.cjs

◌ a › a slow
ℹ this slow test prints useful debug message just text
◌ a › a slow two
ℹ another useful debug message {
 x: 5,
}

---tty-stream-chunk-separator
✔ b › a passes
---tty-stream-chunk-separator
✔ b › a passes two
---tty-stream-chunk-separator

✘ Timed out while running tests

2 tests were pending in b.cjs

◌ b › a slow
ℹ hello world
◌ b › a slow two

---tty-stream-chunk-separator
─

4 tests passed
4 tests remained pending after a timeout
---tty-stream-chunk-separator
38 changes: 38 additions & 0 deletions test-tap/reporters/default.timeoutcontextlogs.v18.log
@@ -0,0 +1,38 @@

---tty-stream-chunk-separator
✔ a › a passes
---tty-stream-chunk-separator
✔ a › a passes two
---tty-stream-chunk-separator

✘ Timed out while running tests

2 tests were pending in a.cjs

◌ a › a slow
ℹ this slow test prints useful debug message just text
◌ a › a slow two
ℹ another useful debug message {
 x: 5,
}

---tty-stream-chunk-separator
✔ b › a passes
---tty-stream-chunk-separator
✔ b › a passes two
---tty-stream-chunk-separator

✘ Timed out while running tests

2 tests were pending in b.cjs

◌ b › a slow
ℹ hello world
◌ b › a slow two

---tty-stream-chunk-separator
─

4 tests passed
4 tests remained pending after a timeout
---tty-stream-chunk-separator