|
1 |
| -// Flags: --test-only |
2 | 1 | 'use strict';
|
3 |
| -require('../../../common'); |
| 2 | +const common = require('../../../common'); |
4 | 3 | const { test, describe, it } = require('node:test');
|
5 | 4 |
|
6 | 5 | // These tests should be skipped based on the 'only' option.
|
7 |
| -test('only = undefined'); |
8 |
| -test('only = undefined, skip = string', { skip: 'skip message' }); |
9 |
| -test('only = undefined, skip = true', { skip: true }); |
10 |
| -test('only = undefined, skip = false', { skip: false }); |
11 |
| -test('only = false', { only: false }); |
12 |
| -test('only = false, skip = string', { only: false, skip: 'skip message' }); |
13 |
| -test('only = false, skip = true', { only: false, skip: true }); |
14 |
| -test('only = false, skip = false', { only: false, skip: false }); |
| 6 | +test('only = undefined', common.mustNotCall()); |
| 7 | +test('only = undefined, skip = string', { skip: 'skip message' }, common.mustNotCall()); |
| 8 | +test('only = undefined, skip = true', { skip: true }, common.mustNotCall()); |
| 9 | +test('only = undefined, skip = false', { skip: false }, common.mustNotCall()); |
| 10 | +test('only = false', { only: false }, common.mustNotCall()); |
| 11 | +test('only = false, skip = string', { only: false, skip: 'skip message' }, common.mustNotCall()); |
| 12 | +test('only = false, skip = true', { only: false, skip: true }, common.mustNotCall()); |
| 13 | +test('only = false, skip = false', { only: false, skip: false }, common.mustNotCall()); |
15 | 14 |
|
16 | 15 | // These tests should be skipped based on the 'skip' option.
|
17 |
| -test('only = true, skip = string', { only: true, skip: 'skip message' }); |
18 |
| -test('only = true, skip = true', { only: true, skip: true }); |
| 16 | +test('only = true, skip = string', { only: true, skip: 'skip message' }, common.mustNotCall()); |
| 17 | +test('only = true, skip = true', { only: true, skip: true }, common.mustNotCall()); |
19 | 18 |
|
20 | 19 | // An 'only' test with subtests.
|
21 |
| -test('only = true, with subtests', { only: true }, async (t) => { |
| 20 | +test('only = true, with subtests', { only: true }, common.mustCall(async (t) => { |
22 | 21 | // These subtests should run.
|
23 |
| - await t.test('running subtest 1'); |
24 |
| - await t.test('running subtest 2'); |
| 22 | + await t.test('running subtest 1', common.mustCall()); |
| 23 | + await t.test('running subtest 2', common.mustCall()); |
25 | 24 |
|
26 | 25 | // Switch the context to only execute 'only' tests.
|
27 | 26 | t.runOnly(true);
|
28 |
| - await t.test('skipped subtest 1'); |
29 |
| - await t.test('skipped subtest 2'); |
30 |
| - await t.test('running subtest 3', { only: true }); |
| 27 | + await t.test('skipped subtest 1', common.mustNotCall()); |
| 28 | + await t.test('skipped subtest 2'), common.mustNotCall(); |
| 29 | + await t.test('running subtest 3', { only: true }, common.mustCall()); |
31 | 30 |
|
32 | 31 | // Switch the context back to execute all tests.
|
33 | 32 | t.runOnly(false);
|
34 |
| - await t.test('running subtest 4', async (t) => { |
| 33 | + await t.test('running subtest 4', common.mustCall(async (t) => { |
35 | 34 | // These subtests should run.
|
36 |
| - await t.test('running sub-subtest 1'); |
37 |
| - await t.test('running sub-subtest 2'); |
| 35 | + await t.test('running sub-subtest 1', common.mustCall()); |
| 36 | + await t.test('running sub-subtest 2', common.mustCall()); |
38 | 37 |
|
39 | 38 | // Switch the context to only execute 'only' tests.
|
40 | 39 | t.runOnly(true);
|
41 |
| - await t.test('skipped sub-subtest 1'); |
42 |
| - await t.test('skipped sub-subtest 2'); |
43 |
| - }); |
| 40 | + await t.test('skipped sub-subtest 1', common.mustNotCall()); |
| 41 | + await t.test('skipped sub-subtest 2', common.mustNotCall()); |
| 42 | + })); |
44 | 43 |
|
45 | 44 | // Explicitly do not run these tests.
|
46 |
| - await t.test('skipped subtest 3', { only: false }); |
47 |
| - await t.test('skipped subtest 4', { skip: true }); |
48 |
| -}); |
| 45 | + await t.test('skipped subtest 3', { only: false }, common.mustNotCall()); |
| 46 | + await t.test('skipped subtest 4', { skip: true }, common.mustNotCall()); |
| 47 | +})); |
49 | 48 |
|
50 |
| -describe.only('describe only = true, with subtests', () => { |
51 |
| - it.only('`it` subtest 1 should run', () => {}); |
| 49 | +describe.only('describe only = true, with subtests', common.mustCall(() => { |
| 50 | + it.only('`it` subtest 1 should run', common.mustCall()); |
52 | 51 |
|
53 |
| - it('`it` subtest 2 should not run', async () => {}); |
54 |
| -}); |
| 52 | + it('`it` subtest 2 should not run', common.mustNotCall()); |
| 53 | +})); |
55 | 54 |
|
56 |
| -describe.only('describe only = true, with a mixture of subtests', () => { |
57 |
| - it.only('`it` subtest 1', () => {}); |
| 55 | +describe.only('describe only = true, with a mixture of subtests', common.mustCall(() => { |
| 56 | + it.only('`it` subtest 1', common.mustCall()); |
58 | 57 |
|
59 |
| - it.only('`it` async subtest 1', async () => {}); |
| 58 | + it.only('`it` async subtest 1', common.mustCall(async () => {})); |
60 | 59 |
|
61 |
| - it('`it` subtest 2 only=true', { only: true }); |
| 60 | + it('`it` subtest 2 only=true', { only: true }, common.mustCall()); |
62 | 61 |
|
63 |
| - it('`it` subtest 2 only=false', { only: false }, () => { |
64 |
| - throw new Error('This should not run'); |
65 |
| - }); |
| 62 | + it('`it` subtest 2 only=false', { only: false }, common.mustNotCall()); |
66 | 63 |
|
67 |
| - it.skip('`it` subtest 3 skip', () => { |
68 |
| - throw new Error('This should not run'); |
69 |
| - }); |
| 64 | + it.skip('`it` subtest 3 skip', common.mustNotCall()); |
70 | 65 |
|
71 |
| - it.todo('`it` subtest 4 todo', { only: false }, () => { |
72 |
| - throw new Error('This should not run'); |
73 |
| - }); |
| 66 | + it.todo('`it` subtest 4 todo', { only: false }, common.mustNotCall()); |
74 | 67 |
|
75 |
| - test.only('`test` subtest 1', () => {}); |
| 68 | + test.only('`test` subtest 1', common.mustCall()); |
76 | 69 |
|
77 |
| - test.only('`test` async subtest 1', async () => {}); |
| 70 | + test.only('`test` async subtest 1', common.mustCall(async () => {})); |
78 | 71 |
|
79 |
| - test('`test` subtest 2 only=true', { only: true }); |
| 72 | + test('`test` subtest 2 only=true', { only: true }, common.mustCall()); |
80 | 73 |
|
81 |
| - test('`test` subtest 2 only=false', { only: false }, () => { |
82 |
| - throw new Error('This should not run'); |
83 |
| - }); |
| 74 | + test('`test` subtest 2 only=false', { only: false }, common.mustNotCall()); |
84 | 75 |
|
85 |
| - test.skip('`test` subtest 3 skip', () => { |
86 |
| - throw new Error('This should not run'); |
87 |
| - }); |
| 76 | + test.skip('`test` subtest 3 skip', common.mustNotCall()); |
88 | 77 |
|
89 |
| - test.todo('`test` subtest 4 todo', { only: false }, () => { |
90 |
| - throw new Error('This should not run'); |
91 |
| - }); |
92 |
| -}); |
| 78 | + test.todo('`test` subtest 4 todo', { only: false }, common.mustNotCall()); |
| 79 | +})); |
93 | 80 |
|
94 |
| -describe.only('describe only = true, with subtests', () => { |
95 |
| - test.only('subtest should run', () => {}); |
| 81 | +describe.only('describe only = true, with subtests', common.mustCall(() => { |
| 82 | + test.only('subtest should run', common.mustCall()); |
96 | 83 |
|
97 |
| - test('async subtest should not run', async () => {}); |
| 84 | + test('async subtest should not run', common.mustNotCall()); |
98 | 85 |
|
99 |
| - test('subtest should be skipped', { only: false }, () => {}); |
100 |
| -}); |
| 86 | + test('subtest should be skipped', { only: false }, common.mustNotCall()); |
| 87 | +})); |
| 88 | + |
| 89 | +describe('describe only = undefined, with subtests', common.mustCall(() => { |
| 90 | + test('async subtest should not run', common.mustNotCall()); |
| 91 | +})); |
| 92 | + |
| 93 | +describe('describe only = false, with subtests', { only: false }, common.mustCall(() => { |
| 94 | + test('async subtest should not run', common.mustNotCall()); |
| 95 | +})); |
0 commit comments