fix(node): support nested tests in "node:test" (#21717)

Closes https://github.com/denoland/deno/issues/21679
This commit is contained in:
Bartek Iwańczuk 2023-12-29 16:18:08 +01:00 committed by GitHub
parent 576b20aa00
commit 1dd1aba244
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 9 deletions

View file

@ -54,6 +54,13 @@ test("async throw fail", async () => {
throw new Error("thrown from async throw fail");
});
test("nested test", async (t) => {
await t.test("nested 1", async (t) => {
await t.test("nested 2", () => {
});
});
});
test("async skip fail", async (t) => {
t.skip();
throw new Error("thrown from async throw fail");

View file

@ -1,5 +1,5 @@
[WILDCARD]
running 62 tests from ./node/test.js
running 63 tests from ./node/test.js
sync pass todo ...
------- output -------
Warning: Not implemented: test.TestContext.todo
@ -43,6 +43,11 @@ Warning: Not implemented: test.TestContext.skip
async skip pass ... ok [WILDCARD]
async pass ... ok [WILDCARD]
async throw fail ... FAILED [WILDCARD]
nested test ...
nested 1 ...
nested 2 ... ok [WILDCARD]
nested 1 ... ok [WILDCARD]
nested test ... ok [WILDCARD]
async skip fail ...
------- output -------
Warning: Not implemented: test.TestContext.skip
@ -123,12 +128,12 @@ error: Error: thrown from async throw fail
throw new Error("thrown from async throw fail");
[WILDCARD]
async skip fail => ./node/test.js:57:1
async skip fail => ./node/test.js:64:1
error: Error: thrown from async throw fail
throw new Error("thrown from async throw fail");
[WILDCARD]
async assertion fail => ./node/test.js:62:1
async assertion fail => ./node/test.js:69:1
error: AssertionError: Values are not strictly equal:
@ -140,7 +145,7 @@ error: AssertionError: Values are not strictly equal:
at [WILDCARD]
reject fail => ./node/test.js:71:1
reject fail => ./node/test.js:78:1
error: Error: rejected from reject fail
return Promise.reject(new Error("rejected from reject fail"));
^
@ -160,11 +165,11 @@ sync fail todo => ./node/test.js:20:1
sync fail todo with message => ./node/test.js:25:1
sync throw fail => ./node/test.js:42:1
async throw fail => ./node/test.js:53:1
async skip fail => ./node/test.js:57:1
async assertion fail => ./node/test.js:62:1
reject fail => ./node/test.js:71:1
async skip fail => ./node/test.js:64:1
async assertion fail => ./node/test.js:69:1
reject fail => ./node/test.js:78:1
./node/test.js (uncaught error)
FAILED | 8 passed | 51 failed | 4 ignored [WILDCARD]
FAILED | 9 passed (2 steps) | 51 failed | 4 ignored [WILDCARD]
error: Test failed

View file

@ -56,7 +56,10 @@ class NodeTestContext {
const prepared = prepareOptions(name, options, fn, {});
return this.#denoContext.step({
name: prepared.name,
fn: prepared.fn,
fn: async (denoTestContext) => {
const newNodeTextContext = new NodeTestContext(denoTestContext);
await prepared.fn(newNodeTextContext);
},
ignore: prepared.options.todo || prepared.options.skip,
}).then(() => undefined);
}