forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-runner-plan.mjs
More file actions
171 lines (134 loc) Β· 4.89 KB
/
test-runner-plan.mjs
File metadata and controls
171 lines (134 loc) Β· 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import * as common from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import { describe, it, run } from 'node:test';
import { join } from 'node:path';
const testFixtures = fixtures.path('test-runner', 'plan');
describe('input validation', () => {
it('throws if options is not an object', (t) => {
t.assert.throws(() => {
t.plan(1, null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "options" argument must be of type object/,
});
});
it('throws if options.wait is not a number or a boolean', (t) => {
t.assert.throws(() => {
t.plan(1, { wait: 'foo' });
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "options\.wait" property must be one of type boolean or number\. Received type string/,
});
});
it('throws if count is not a number', (t) => {
t.assert.throws(() => {
t.plan('foo');
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "count" argument must be of type number/,
});
});
});
describe('test planning', () => {
it('should pass when assertions match plan', async () => {
const stream = run({
files: [join(testFixtures, 'match.mjs')]
});
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(1));
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
it('should fail when less assertions than planned', async () => {
const stream = run({
files: [join(testFixtures, 'less.mjs')]
});
stream.on('test:fail', common.mustCall(1));
stream.on('test:pass', common.mustNotCall());
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
it('should fail when more assertions than planned', async () => {
const stream = run({
files: [join(testFixtures, 'more.mjs')]
});
stream.on('test:fail', common.mustCall(1));
stream.on('test:pass', common.mustNotCall());
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
it('should handle plan with subtests correctly', async () => {
const stream = run({
files: [join(testFixtures, 'subtest.mjs')]
});
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(2)); // Parent + child test
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
it('should handle plan via options', async () => {
const stream = run({
files: [join(testFixtures, 'plan-via-options.mjs')]
});
stream.on('test:fail', common.mustCall(1));
stream.on('test:pass', common.mustCall(1));
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
it('should handle streaming with plan', async () => {
const stream = run({
files: [join(testFixtures, 'streaming.mjs')]
});
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(1));
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
it('should handle nested subtests with plan', async () => {
const stream = run({
files: [join(testFixtures, 'nested-subtests.mjs')]
});
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(3)); // Parent + 2 levels of nesting
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
describe('with timeout', () => {
it('should handle basic timeout scenarios', async () => {
const stream = run({
files: [join(testFixtures, 'timeout-basic.mjs')]
});
stream.on('test:fail', common.mustCall(1));
stream.on('test:pass', common.mustCall(1));
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
it('should fail when timeout expires before plan is met', async (t) => {
const stream = run({
files: [join(testFixtures, 'timeout-expired.mjs')]
});
stream.on('test:fail', common.mustCall(1));
stream.on('test:pass', common.mustNotCall());
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
it('should handle wait:true option specifically', async () => {
const stream = run({
files: [join(testFixtures, 'timeout-wait-true.mjs')]
});
stream.on('test:fail', common.mustCall(1));
stream.on('test:pass', common.mustCall(1));
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
it('should handle wait:false option (should not wait)', async () => {
const stream = run({
files: [join(testFixtures, 'timeout-wait-false.mjs')]
});
stream.on('test:fail', common.mustCall(1)); // Fails because plan is not met immediately
stream.on('test:pass', common.mustNotCall());
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
});
});