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: nodejs#43998
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
MoLow authored Jul 28, 2022
1 parent 37b4f47 commit a3e1108
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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'));
},
};
});
Loading

0 comments on commit a3e1108

Please sign in to comment.