Skip to content

Commit 50c854b

Browse files
MoLowruyadorno
authored andcommitted
test_runner: fix top level describe queuing
PR-URL: #43998 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 9763e2f commit 50c854b

File tree

6 files changed

+208
-89
lines changed

6 files changed

+208
-89
lines changed

lib/internal/test_runner/test.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -561,25 +561,22 @@ class Suite extends Test {
561561

562562
try {
563563
const context = { signal: this.signal };
564-
this.buildSuite = this.runInAsyncScope(this.fn, context, [context]);
564+
this.buildSuite = PromisePrototypeThen(
565+
PromiseResolve(this.runInAsyncScope(this.fn, context, [context])),
566+
undefined,
567+
(err) => {
568+
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
569+
});
565570
} catch (err) {
566571
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
567572
}
568573
this.fn = () => {};
569574
this.buildPhaseFinished = true;
570575
}
571576

572-
start() {
573-
return this.run();
574-
}
575-
576577
async run() {
577-
try {
578-
await this.buildSuite;
579-
} catch (err) {
580-
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
581-
}
582578
this.parent.activeSubtests++;
579+
await this.buildSuite;
583580
this.startTime = hrtime();
584581

585582
if (this[kShouldAbort]()) {

test/message/test_runner_describe_it.js

+44-11
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,6 @@ describe('level 0a', { concurrency: 4 }, () => {
149149
return p0a;
150150
});
151151

152-
describe('top level', { concurrency: 2 }, () => {
153-
it('+long running', async () => {
154-
return new Promise((resolve, reject) => {
155-
setTimeout(resolve, 3000).unref();
156-
});
157-
});
158-
159-
describe('+short running', async () => {
160-
it('++short running', async () => {});
161-
});
162-
});
163152

164153
describe('invalid subtest - pass but subtest fails', () => {
165154
setImmediate(() => {
@@ -339,3 +328,47 @@ describe('timeouts', () => {
339328
setTimeout(done, 10);
340329
});
341330
});
331+
332+
describe('successful thenable', () => {
333+
it('successful thenable', () => {
334+
let thenCalled = false;
335+
return {
336+
get then() {
337+
if (thenCalled) throw new Error();
338+
thenCalled = true;
339+
return (successHandler) => successHandler();
340+
},
341+
};
342+
});
343+
344+
it('rejected thenable', () => {
345+
let thenCalled = false;
346+
return {
347+
get then() {
348+
if (thenCalled) throw new Error();
349+
thenCalled = true;
350+
return (_, errorHandler) => errorHandler(new Error('custom error'));
351+
},
352+
};
353+
});
354+
355+
let thenCalled = false;
356+
return {
357+
get then() {
358+
if (thenCalled) throw new Error();
359+
thenCalled = true;
360+
return (successHandler) => successHandler();
361+
},
362+
};
363+
});
364+
365+
describe('rejected thenable', () => {
366+
let thenCalled = false;
367+
return {
368+
get then() {
369+
if (thenCalled) throw new Error();
370+
thenCalled = true;
371+
return (_, errorHandler) => errorHandler(new Error('custom error'));
372+
},
373+
};
374+
});

0 commit comments

Comments
 (0)