Skip to content

Commit ff3cc3b

Browse files
committed
test: use more informative errors in test-runner-cli
PR-URL: #55321 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me>
1 parent 1921d7a commit ff3cc3b

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

test/parallel/test-runner-cli.js

+39-33
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ for (const isolation of ['none', 'process']) {
6767
`--experimental-${type}-types`, `--experimental-test-isolation=${isolation}`];
6868
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'matching-patterns') });
6969

70-
assert.strictEqual(child.status, 0);
71-
assert.strictEqual(child.signal, null);
7270
assert.strictEqual(child.stderr.toString(), '');
7371
const stdout = child.stdout.toString();
7472

@@ -78,6 +76,8 @@ for (const isolation of ['none', 'process']) {
7876
assert.match(stdout, /ok 4 - this should pass/);
7977
assert.match(stdout, /ok 5 - this should pass/);
8078
assert.match(stdout, /ok 6 - this should pass/);
79+
assert.strictEqual(child.status, 0);
80+
assert.strictEqual(child.signal, null);
8181
}
8282

8383
{
@@ -97,9 +97,9 @@ for (const isolation of ['none', 'process']) {
9797
assert.match(stdout, /ok 4 - this should pass/);
9898
assert.match(stdout, /ok 5 - this should be skipped/);
9999
assert.match(stdout, /ok 6 - this should be executed/);
100+
assert.strictEqual(child.stderr.toString(), '');
100101
assert.strictEqual(child.status, 1);
101102
assert.strictEqual(child.signal, null);
102-
assert.strictEqual(child.stderr.toString(), '');
103103
}
104104

105105
{
@@ -112,11 +112,11 @@ for (const isolation of ['none', 'process']) {
112112
];
113113
const child = spawnSync(process.execPath, args, { cwd: testFixtures });
114114

115-
assert.strictEqual(child.status, 1);
116-
assert.strictEqual(child.signal, null);
117115
assert.strictEqual(child.stderr.toString(), '');
118116
const stdout = child.stdout.toString();
119117
assert.match(stdout, /not ok 1 - .+index\.js/);
118+
assert.strictEqual(child.status, 1);
119+
assert.strictEqual(child.signal, null);
120120
}
121121

122122
{
@@ -129,11 +129,11 @@ for (const isolation of ['none', 'process']) {
129129
];
130130
const child = spawnSync(process.execPath, args);
131131

132-
assert.strictEqual(child.status, 1);
133-
assert.strictEqual(child.signal, null);
134132
assert.strictEqual(child.stderr.toString(), '');
135133
const stdout = child.stdout.toString();
136134
assert.match(stdout, /not ok 1 - .+test-nm\.js/);
135+
assert.strictEqual(child.status, 1);
136+
assert.strictEqual(child.signal, null);
137137
}
138138

139139
{
@@ -142,8 +142,6 @@ for (const isolation of ['none', 'process']) {
142142
const options = { cwd: join(testFixtures, 'default-behavior') };
143143
const child = spawnSync(process.execPath, args, options);
144144

145-
assert.strictEqual(child.status, 1);
146-
assert.strictEqual(child.signal, null);
147145
assert.strictEqual(child.stderr.toString(), '');
148146
const stdout = child.stdout.toString();
149147
assert.match(stdout, /this should pass/);
@@ -152,6 +150,9 @@ for (const isolation of ['none', 'process']) {
152150
assert.match(stdout, /this should pass/);
153151
assert.match(stdout, /this should be skipped/);
154152
assert.match(stdout, /this should be executed/);
153+
154+
assert.strictEqual(child.status, 1);
155+
assert.strictEqual(child.signal, null);
155156
}
156157

157158
{
@@ -166,8 +167,6 @@ for (const isolation of ['none', 'process']) {
166167
];
167168
const child = spawnSync(process.execPath, args);
168169

169-
assert.strictEqual(child.status, 1);
170-
assert.strictEqual(child.signal, null);
171170
assert.strictEqual(child.stderr.toString(), '');
172171
const stdout = child.stdout.toString();
173172
assert.match(stdout, /# Subtest: this should pass/);
@@ -204,6 +203,9 @@ for (const isolation of ['none', 'process']) {
204203
assert.match(stdout, /# cancelled 0/);
205204
assert.match(stdout, /# skipped 1/);
206205
assert.match(stdout, /# todo 0/);
206+
207+
assert.strictEqual(child.status, 1);
208+
assert.strictEqual(child.signal, null);
207209
}
208210
}
209211

@@ -219,11 +221,11 @@ for (const isolation of ['none', 'process']) {
219221
for (const args of flags) {
220222
const child = spawnSync(process.execPath, args);
221223

222-
assert.notStrictEqual(child.status, 0);
223-
assert.strictEqual(child.signal, null);
224224
assert.strictEqual(child.stdout.toString(), '');
225225
const stderr = child.stderr.toString();
226226
assert.match(stderr, /--test/);
227+
assert.notStrictEqual(child.status, 0);
228+
assert.strictEqual(child.signal, null);
227229
}
228230
}
229231

@@ -236,8 +238,6 @@ for (const isolation of ['none', 'process']) {
236238
];
237239
const child = spawnSync(process.execPath, args);
238240

239-
assert.strictEqual(child.status, 0);
240-
assert.strictEqual(child.signal, null);
241241
assert.strictEqual(child.stderr.toString(), '');
242242
const stdout = child.stdout.toString();
243243
assert.match(stdout, /# stderr 1/);
@@ -251,6 +251,9 @@ for (const isolation of ['none', 'process']) {
251251
assert.match(stdout, /ok 1 - a test/);
252252
assert.match(stdout, /# tests 1/);
253253
assert.match(stdout, /# pass 1/);
254+
255+
assert.strictEqual(child.status, 0);
256+
assert.strictEqual(child.signal, null);
254257
}
255258

256259
{
@@ -263,70 +266,70 @@ for (const isolation of ['none', 'process']) {
263266
const child = spawnSync(process.execPath, args);
264267

265268
assert.strictEqual(child.stderr.toString(), '');
266-
assert.strictEqual(child.status, 0);
267-
assert.strictEqual(child.signal, null);
268269
const stdout = child.stdout.toString();
269270
assert.match(stdout, /this should pass/);
271+
assert.strictEqual(child.status, 0);
272+
assert.strictEqual(child.signal, null);
270273
}
271274

272275
{
273276
// --test-shard option validation
274277
const args = ['--test', '--test-shard=1', join(testFixtures, 'index.js')];
275278
const child = spawnSync(process.execPath, args, { cwd: testFixtures });
276279

277-
assert.strictEqual(child.status, 1);
278-
assert.strictEqual(child.signal, null);
279280
assert.match(child.stderr.toString(), /The argument '--test-shard' must be in the form of <index>\/<total>\. Received '1'/);
280281
const stdout = child.stdout.toString();
281282
assert.strictEqual(stdout, '');
283+
assert.strictEqual(child.status, 1);
284+
assert.strictEqual(child.signal, null);
282285
}
283286

284287
{
285288
// --test-shard option validation
286289
const args = ['--test', '--test-shard=1/2/3', join(testFixtures, 'index.js')];
287290
const child = spawnSync(process.execPath, args, { cwd: testFixtures });
288291

289-
assert.strictEqual(child.status, 1);
290-
assert.strictEqual(child.signal, null);
291292
assert.match(child.stderr.toString(), /The argument '--test-shard' must be in the form of <index>\/<total>\. Received '1\/2\/3'/);
292293
const stdout = child.stdout.toString();
293294
assert.strictEqual(stdout, '');
295+
assert.strictEqual(child.status, 1);
296+
assert.strictEqual(child.signal, null);
294297
}
295298

296299
{
297300
// --test-shard option validation
298301
const args = ['--test', '--test-shard=0/3', join(testFixtures, 'index.js')];
299302
const child = spawnSync(process.execPath, args, { cwd: testFixtures });
300303

301-
assert.strictEqual(child.status, 1);
302-
assert.strictEqual(child.signal, null);
303304
assert.match(child.stderr.toString(), /The value of "options\.shard\.index" is out of range\. It must be >= 1 && <= 3\. Received 0/);
304305
const stdout = child.stdout.toString();
305306
assert.strictEqual(stdout, '');
307+
assert.strictEqual(child.status, 1);
308+
assert.strictEqual(child.signal, null);
306309
}
307310

308311
{
309312
// --test-shard option validation
310313
const args = ['--test', '--test-shard=0xf/20abcd', join(testFixtures, 'index.js')];
311314
const child = spawnSync(process.execPath, args, { cwd: testFixtures });
312315

313-
assert.strictEqual(child.status, 1);
314-
assert.strictEqual(child.signal, null);
315316
assert.match(child.stderr.toString(), /The argument '--test-shard' must be in the form of <index>\/<total>\. Received '0xf\/20abcd'/);
316317
const stdout = child.stdout.toString();
317318
assert.strictEqual(stdout, '');
319+
assert.strictEqual(child.status, 1);
320+
assert.strictEqual(child.signal, null);
318321
}
319322

320323
{
321324
// --test-shard option validation
322325
const args = ['--test', '--test-shard=hello', join(testFixtures, 'index.js')];
323326
const child = spawnSync(process.execPath, args, { cwd: testFixtures });
324327

325-
assert.strictEqual(child.status, 1);
326-
assert.strictEqual(child.signal, null);
327328
assert.match(child.stderr.toString(), /The argument '--test-shard' must be in the form of <index>\/<total>\. Received 'hello'/);
328329
const stdout = child.stdout.toString();
329330
assert.strictEqual(stdout, '');
331+
assert.strictEqual(child.status, 1);
332+
assert.strictEqual(child.signal, null);
330333
}
331334

332335
{
@@ -339,8 +342,6 @@ for (const isolation of ['none', 'process']) {
339342
];
340343
const child = spawnSync(process.execPath, args);
341344

342-
assert.strictEqual(child.status, 0);
343-
assert.strictEqual(child.signal, null);
344345
assert.strictEqual(child.stderr.toString(), '');
345346
const stdout = child.stdout.toString();
346347
assert.match(stdout, /# Subtest: a\.cjs this should pass/);
@@ -362,6 +363,9 @@ for (const isolation of ['none', 'process']) {
362363
assert.match(stdout, /# pass 5/);
363364
assert.match(stdout, /# fail 0/);
364365
assert.match(stdout, /# skipped 0/);
366+
367+
assert.strictEqual(child.status, 0);
368+
assert.strictEqual(child.signal, null);
365369
}
366370

367371
{
@@ -374,8 +378,6 @@ for (const isolation of ['none', 'process']) {
374378
];
375379
const child = spawnSync(process.execPath, args);
376380

377-
assert.strictEqual(child.status, 0);
378-
assert.strictEqual(child.signal, null);
379381
assert.strictEqual(child.stderr.toString(), '');
380382
const stdout = child.stdout.toString();
381383
assert.match(stdout, /# Subtest: b\.cjs this should pass/);
@@ -397,15 +399,16 @@ for (const isolation of ['none', 'process']) {
397399
assert.match(stdout, /# pass 5/);
398400
assert.match(stdout, /# fail 0/);
399401
assert.match(stdout, /# skipped 0/);
402+
403+
assert.strictEqual(child.status, 0);
404+
assert.strictEqual(child.signal, null);
400405
}
401406

402407
{
403408
// Should not match files like latest.js
404409
const args = ['--test', '--test-reporter=tap'];
405410
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'issue-54726') });
406411

407-
assert.strictEqual(child.status, 0);
408-
assert.strictEqual(child.signal, null);
409412
assert.strictEqual(child.stderr.toString(), '');
410413
const stdout = child.stdout.toString();
411414

@@ -416,4 +419,7 @@ for (const isolation of ['none', 'process']) {
416419
assert.match(stdout, /cancelled 0/);
417420
assert.match(stdout, /skipped 0/);
418421
assert.match(stdout, /todo 0/);
422+
423+
assert.strictEqual(child.status, 0);
424+
assert.strictEqual(child.signal, null);
419425
}

0 commit comments

Comments
 (0)