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 1 commit
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.pendingTestsLogReference.get(file) ?? new Map();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const testTitleToLogs = evt.pendingTestsLogReference.get(file) ?? new Map();
const testTitleToLogs = evt.pendingTestsLogReference.get(file);

for (const title of testsInFile) {
const logs = testTitleToLogs.get(title) ?? [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writeLogs() can handle falsey logs values. So with optional chaining and the above we can do:

Suggested change
const logs = testTitleToLogs.get(title) ?? [];
const logs = testTitleToLogs?.get(title);

this.lineWriter.writeLine(`${figures.circleDotted} ${this.prefixTitle(file, title)}`);
this.writeLogs({logs});
}

this.lineWriter.writeLine('');
Expand Down
17 changes: 17 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.pendingTestsLogReference = new Map();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate map from this.pendingTests because they are modified and initialized in different events with different objects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, I think pendingTestsLogs sounds better


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.pendingTestsLogReference.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.addLogReference(event);
break;
case 'timeout':
stats.timeouts++;
event.pendingTests = this.pendingTests;
event.pendingTestsLogReference = this.pendingTestsLogReference;
this.pendingTests = new Map();
this.pendingTestsLogReference = new Map();
for (const testsInFile of event.pendingTests.values()) {
stats.timedOutTests += testsInFile.size;
}

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

addLogReference(event) {
if (this.pendingTestsLogReference.has(event.testFile)) {
this.pendingTestsLogReference.get(event.testFile).set(event.title, event.logs);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.pendingTestsLogReference.has(event.testFile)) {
this.pendingTestsLogReference.get(event.testFile).set(event.title, event.logs);
}
this.pendingTestsLogReference.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