Skip to content

Commit

Permalink
test_runner: fix top level describe queuing
Browse files Browse the repository at this point in the history
PR-URL: #43998
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
MoLow authored and juanarbol committed Oct 11, 2022
1 parent 78c8462 commit 6ad7a86
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 89 deletions.
17 changes: 7 additions & 10 deletions lib/internal/test_runner/test.js
Expand Up @@ -561,25 +561,22 @@ class Suite extends Test {

try {
const context = { signal: this.signal };
this.buildSuite = this.runInAsyncScope(this.fn, context, [context]);
this.buildSuite = PromisePrototypeThen(
PromiseResolve(this.runInAsyncScope(this.fn, context, [context])),
undefined,
(err) => {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
});
} catch (err) {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
}
this.fn = () => {};
this.buildPhaseFinished = true;
}

start() {
return this.run();
}

async run() {
try {
await this.buildSuite;
} catch (err) {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
}
this.parent.activeSubtests++;
await this.buildSuite;
this.startTime = hrtime();

if (this[kShouldAbort]()) {
Expand Down
55 changes: 44 additions & 11 deletions test/message/test_runner_describe_it.js
Expand Up @@ -149,17 +149,6 @@ describe('level 0a', { concurrency: 4 }, () => {
return p0a;
});

describe('top level', { concurrency: 2 }, () => {
it('+long running', async () => {
return new Promise((resolve, reject) => {
setTimeout(resolve, 3000).unref();
});
});

describe('+short running', async () => {
it('++short running', async () => {});
});
});

describe('invalid subtest - pass but subtest fails', () => {
setImmediate(() => {
Expand Down Expand Up @@ -339,3 +328,47 @@ describe('timeouts', () => {
setTimeout(done, 10);
});
});

describe('successful thenable', () => {
it('successful thenable', () => {
let thenCalled = false;
return {
get then() {
if (thenCalled) throw new Error();
thenCalled = true;
return (successHandler) => successHandler();
},
};
});

it('rejected thenable', () => {
let thenCalled = false;
return {
get then() {
if (thenCalled) throw new Error();
thenCalled = true;
return (_, errorHandler) => errorHandler(new Error('custom error'));
},
};
});

let thenCalled = false;
return {
get then() {
if (thenCalled) throw new Error();
thenCalled = true;
return (successHandler) => successHandler();
},
};
});

describe('rejected thenable', () => {
let thenCalled = false;
return {
get then() {
if (thenCalled) throw new Error();
thenCalled = true;
return (_, errorHandler) => errorHandler(new Error('custom error'));
},
};
});

0 comments on commit 6ad7a86

Please sign in to comment.