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

test_runner: differentiate test types in enqueue dequeue events #54049

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -2930,6 +2930,7 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
`undefined` if the test was run through the REPL.
* `name` {string} The test name.
* `nesting` {number} The nesting level of the test.
* `type` {string} The test type. Either `'suite'` or `'test'`.

Emitted when a test is dequeued, right before it is executed.
This event is not guaranteed to be emitted in the same order as the tests are
Expand Down Expand Up @@ -2962,6 +2963,7 @@ defined.
`undefined` if the test was run through the REPL.
* `name` {string} The test name.
* `nesting` {number} The nesting level of the test.
* `type` {string} The test type. Either `'suite'` or `'test'`.

Emitted when a test is enqueued for execution.

Expand Down
8 changes: 5 additions & 3 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ class SuiteContext {
}

class Test extends AsyncResource {
reportedType = 'test';
abortController;
outerSignal;
#reportedSubtest;
Expand Down Expand Up @@ -625,7 +626,7 @@ class Test extends AsyncResource {
while (this.pendingSubtests.length > 0 && this.hasConcurrency()) {
const deferred = ArrayPrototypeShift(this.pendingSubtests);
const test = deferred.test;
test.reporter.dequeue(test.nesting, test.loc, test.name);
test.reporter.dequeue(test.nesting, test.loc, test.name, this.reportedType);
await test.run();
deferred.resolve();
}
Expand Down Expand Up @@ -816,7 +817,7 @@ class Test extends AsyncResource {
// If there is enough available concurrency to run the test now, then do
// it. Otherwise, return a Promise to the caller and mark the test as
// pending for later execution.
this.reporter.enqueue(this.nesting, this.loc, this.name);
this.reporter.enqueue(this.nesting, this.loc, this.name, this.reportedType);
if (this.root.harness.buildPromise || !this.parent.hasConcurrency()) {
const deferred = PromiseWithResolvers();

Expand All @@ -825,7 +826,7 @@ class Test extends AsyncResource {
return deferred.promise;
}

this.reporter.dequeue(this.nesting, this.loc, this.name);
this.reporter.dequeue(this.nesting, this.loc, this.name, this.reportedType);
return this.run();
}

Expand Down Expand Up @@ -1195,6 +1196,7 @@ class Test extends AsyncResource {
}

class TestHook extends Test {
reportedType = 'hook';
#args;
constructor(fn, options) {
const { hookType, loc, parent, timeout, signal } = options;
Expand Down
6 changes: 4 additions & 2 deletions lib/internal/test_runner/tests_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,22 @@ class TestsStream extends Readable {
return { __proto__: null, todo: reason ?? true };
}

enqueue(nesting, loc, name) {
enqueue(nesting, loc, name, type) {
this[kEmitMessage]('test:enqueue', {
__proto__: null,
nesting,
name,
type,
...loc,
});
}

dequeue(nesting, loc, name) {
dequeue(nesting, loc, name, type) {
this[kEmitMessage]('test:dequeue', {
__proto__: null,
nesting,
name,
type,
...loc,
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
const {test, suite} = require('node:test');

suite('this is a suite');
test('this is a test');
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ AFTER
not ok 1 - test that aborts
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort-runs-after-hook.js:(LINE):1'
failureType: 'uncaughtException'
error: 'boom'
Expand Down
22 changes: 22 additions & 0 deletions test/fixtures/test-runner/output/abort.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@ TAP version 13
ok 1 - ok 1
---
duration_ms: *
type: 'test'
...
# Subtest: ok 2
ok 2 - ok 2
---
duration_ms: *
type: 'test'
...
# Subtest: ok 3
ok 3 - ok 3
---
duration_ms: *
type: 'test'
...
# Subtest: ok 4
ok 4 - ok 4
---
duration_ms: *
type: 'test'
...
# Subtest: not ok 1
not ok 5 - not ok 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -33,6 +38,7 @@ TAP version 13
not ok 6 - not ok 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -42,6 +48,7 @@ TAP version 13
not ok 7 - not ok 3
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -63,6 +70,7 @@ TAP version 13
not ok 8 - not ok 4
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -84,6 +92,7 @@ TAP version 13
not ok 9 - not ok 5
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -105,6 +114,7 @@ TAP version 13
not ok 1 - promise timeout signal
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
Expand All @@ -120,6 +130,7 @@ not ok 1 - promise timeout signal
not ok 2 - promise abort signal
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -142,26 +153,31 @@ not ok 2 - promise abort signal
ok 1 - ok 1
---
duration_ms: *
type: 'test'
...
# Subtest: ok 2
ok 2 - ok 2
---
duration_ms: *
type: 'test'
...
# Subtest: ok 3
ok 3 - ok 3
---
duration_ms: *
type: 'test'
...
# Subtest: ok 4
ok 4 - ok 4
---
duration_ms: *
type: 'test'
...
# Subtest: not ok 1
not ok 5 - not ok 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -171,6 +187,7 @@ not ok 2 - promise abort signal
not ok 6 - not ok 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -180,6 +197,7 @@ not ok 2 - promise abort signal
not ok 7 - not ok 3
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -201,6 +219,7 @@ not ok 2 - promise abort signal
not ok 8 - not ok 4
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -222,6 +241,7 @@ not ok 2 - promise abort signal
not ok 9 - not ok 5
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -243,6 +263,7 @@ not ok 2 - promise abort signal
not ok 3 - callback timeout signal
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
Expand All @@ -258,6 +279,7 @@ not ok 3 - callback timeout signal
not ok 4 - callback abort signal
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/test-runner/output/abort_hooks.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ TAP version 13
not ok 1 - test 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -21,6 +22,7 @@ TAP version 13
not ok 2 - test 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand Down Expand Up @@ -53,11 +55,13 @@ not ok 1 - 1 before describe
ok 1 - test 1
---
duration_ms: *
type: 'test'
...
# Subtest: test 2
ok 2 - test 2
---
duration_ms: *
type: 'test'
...
1..2
not ok 2 - 2 after describe
Expand Down Expand Up @@ -86,6 +90,7 @@ not ok 2 - 2 after describe
not ok 1 - test 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'hookFailed'
error: 'This operation was aborted'
Expand All @@ -107,6 +112,7 @@ not ok 2 - 2 after describe
not ok 2 - test 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'hookFailed'
error: 'This operation was aborted'
Expand Down Expand Up @@ -139,6 +145,7 @@ not ok 3 - 3 beforeEach describe
not ok 1 - test 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'hookFailed'
error: 'This operation was aborted'
Expand All @@ -160,6 +167,7 @@ not ok 3 - 3 beforeEach describe
not ok 2 - test 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'hookFailed'
error: 'This operation was aborted'
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/test-runner/output/abort_suite.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@ TAP version 13
ok 1 - ok 1
---
duration_ms: *
type: 'test'
...
# Subtest: ok 2
ok 2 - ok 2
---
duration_ms: *
type: 'test'
...
# Subtest: ok 3
ok 3 - ok 3
---
duration_ms: *
type: 'test'
...
# Subtest: ok 4
ok 4 - ok 4
---
duration_ms: *
type: 'test'
...
# Subtest: not ok 1
not ok 5 - not ok 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -33,6 +38,7 @@ TAP version 13
not ok 6 - not ok 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -42,6 +48,7 @@ TAP version 13
not ok 7 - not ok 3
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -63,6 +70,7 @@ TAP version 13
not ok 8 - not ok 4
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -84,6 +92,7 @@ TAP version 13
not ok 9 - not ok 5
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ TAP version 13
ok 1 - passing test
---
duration_ms: *
type: 'test'
...
1..1
# tests 1
Expand Down
Loading
Loading