Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aa41f27

Browse filesBrowse files
richiemccolltargos
authored andcommitted
test_runner: add describe.only and it.only shorthands
PR-URL: #46604 Fixes: #46562 Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent 3234155 commit aa41f27
Copy full SHA for aa41f27

File tree

Expand file treeCollapse file tree

4 files changed

+130
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+130
-5
lines changed
Open diff view settings
Collapse file

‎doc/api/test.md‎

Copy file name to clipboardExpand all lines: doc/api/test.md
+18Lines changed: 18 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,15 @@ Shorthand for skipping a suite, same as [`describe([name], { skip: true }[, fn])
824824
Shorthand for marking a suite as `TODO`, same as
825825
[`describe([name], { todo: true }[, fn])`][describe options].
826826

827+
## `describe.only([name][, options][, fn])`
828+
829+
<!-- YAML
830+
added: REPLACEME
831+
-->
832+
833+
Shorthand for marking a suite as `only`, same as
834+
[`describe([name], { only: true }[, fn])`][describe options].
835+
827836
## `it([name][, options][, fn])`
828837

829838
* `name` {string} The name of the test, which is displayed when reporting test
@@ -848,6 +857,15 @@ same as [`it([name], { skip: true }[, fn])`][it options].
848857
Shorthand for marking a test as `TODO`,
849858
same as [`it([name], { todo: true }[, fn])`][it options].
850859

860+
## `it.only([name][, options][, fn])`
861+
862+
<!-- YAML
863+
added: REPLACEME
864+
-->
865+
866+
Shorthand for marking a test as `only`,
867+
same as [`it([name], { only: true }[, fn])`][it options].
868+
851869
## `before([fn][, options])`
852870

853871
<!-- YAML
Collapse file

‎lib/internal/test_runner/harness.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/harness.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function runInParentContext(Factory) {
199199
run(name, options, fn);
200200
};
201201

202-
ArrayPrototypeForEach(['skip', 'todo'], (keyword) => {
202+
ArrayPrototypeForEach(['skip', 'todo', 'only'], (keyword) => {
203203
cb[keyword] = (name, options, fn) => {
204204
run(name, options, fn, { [keyword]: true });
205205
};
Collapse file

‎test/message/test_runner_only_tests.js‎

Copy file name to clipboardExpand all lines: test/message/test_runner_only_tests.js
+35-1Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Flags: --no-warnings --test-only
22
'use strict';
33
require('../common');
4-
const test = require('node:test');
4+
const { test, describe, it } = require('node:test');
55

66
// These tests should be skipped based on the 'only' option.
77
test('only = undefined');
@@ -46,3 +46,37 @@ test('only = true, with subtests', { only: true }, async (t) => {
4646
await t.test('skipped subtest 3', { only: false });
4747
await t.test('skipped subtest 4', { skip: true });
4848
});
49+
50+
describe.only('describe only = true, with subtests', () => {
51+
it('`it` subtest 1 should run', () => {});
52+
53+
it('`it` subtest 2 should run', async () => {});
54+
});
55+
56+
describe.only('describe only = true, with a mixture of subtests', () => {
57+
it.only('`it` subtest 1', () => {});
58+
59+
it.only('`it` async subtest 1', async () => {});
60+
61+
it('`it` subtest 2 only=true', { only: true });
62+
63+
it('`it` subtest 2 only=false', { only: false }, () => {
64+
throw new Error('This should not run');
65+
});
66+
67+
it.skip('`it` subtest 3 skip', () => {
68+
throw new Error('This should not run');
69+
});
70+
71+
it.todo('`it` subtest 4 todo', { only: false }, () => {
72+
throw new Error('This should not run');
73+
});
74+
});
75+
76+
describe.only('describe only = true, with subtests', () => {
77+
test('subtest should run', () => {});
78+
79+
test('async subtest should run', async () => {});
80+
81+
test('subtest should be skipped', { only: false }, () => {});
82+
});
Collapse file

‎test/message/test_runner_only_tests.out‎

Copy file name to clipboardExpand all lines: test/message/test_runner_only_tests.out
+76-3Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,82 @@ ok 11 - only = true, with subtests
116116
---
117117
duration_ms: *
118118
...
119-
1..11
120-
# tests 11
121-
# pass 1
119+
# Subtest: describe only = true, with subtests
120+
# Subtest: `it` subtest 1 should run
121+
ok 1 - `it` subtest 1 should run
122+
---
123+
duration_ms: *
124+
...
125+
# Subtest: `it` subtest 2 should run
126+
ok 2 - `it` subtest 2 should run
127+
---
128+
duration_ms: *
129+
...
130+
1..2
131+
ok 12 - describe only = true, with subtests
132+
---
133+
duration_ms: *
134+
...
135+
# Subtest: describe only = true, with a mixture of subtests
136+
# Subtest: `it` subtest 1
137+
ok 1 - `it` subtest 1
138+
---
139+
duration_ms: *
140+
...
141+
# Subtest: `it` async subtest 1
142+
ok 2 - `it` async subtest 1
143+
---
144+
duration_ms: *
145+
...
146+
# Subtest: `it` subtest 2 only=true
147+
ok 3 - `it` subtest 2 only=true
148+
---
149+
duration_ms: *
150+
...
151+
# Subtest: `it` subtest 2 only=false
152+
ok 4 - `it` subtest 2 only=false # SKIP 'only' option not set
153+
---
154+
duration_ms: *
155+
...
156+
# Subtest: `it` subtest 3 skip
157+
ok 5 - `it` subtest 3 skip # SKIP
158+
---
159+
duration_ms: *
160+
...
161+
# Subtest: `it` subtest 4 todo
162+
ok 6 - `it` subtest 4 todo # SKIP 'only' option not set
163+
---
164+
duration_ms: *
165+
...
166+
1..6
167+
ok 13 - describe only = true, with a mixture of subtests
168+
---
169+
duration_ms: *
170+
...
171+
# Subtest: describe only = true, with subtests
172+
# Subtest: subtest should run
173+
ok 1 - subtest should run
174+
---
175+
duration_ms: *
176+
...
177+
# Subtest: async subtest should run
178+
ok 2 - async subtest should run
179+
---
180+
duration_ms: *
181+
...
182+
# Subtest: subtest should be skipped
183+
ok 3 - subtest should be skipped # SKIP 'only' option not set
184+
---
185+
duration_ms: *
186+
...
187+
1..3
188+
ok 14 - describe only = true, with subtests
189+
---
190+
duration_ms: *
191+
...
192+
1..14
193+
# tests 14
194+
# pass 4
122195
# fail 0
123196
# cancelled 0
124197
# skipped 10

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.