From f5e46c9bf2f50d66a953fa133161fc829cecff06 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Sat, 10 Feb 2024 13:22:13 -0700 Subject: chore: move cli/tests/ -> tests/ (#22369) This looks like a massive PR, but it's only a move from cli/tests -> tests, and updates of relative paths for files. This is the first step towards aggregate all of the integration test files under tests/, which will lead to a set of integration tests that can run without the CLI binary being built. While we could leave these tests under `cli`, it would require us to keep a more complex directory structure for the various test runners. In addition, we have a lot of complexity to ignore various test files in the `cli` project itself (cargo publish exclusion rules, autotests = false, etc). And finally, the `tests/` folder will eventually house the `test_ffi`, `test_napi` and other testing code, reducing the size of the root repo directory. For easier review, the extremely large and noisy "move" is in the first commit (with no changes -- just a move), while the remainder of the changes to actual files is in the second commit. --- tests/testdata/test/steps/failing_steps.dot.out | 53 ++++++++++ tests/testdata/test/steps/failing_steps.out | 59 +++++++++++ tests/testdata/test/steps/failing_steps.tap.out | 43 ++++++++ tests/testdata/test/steps/failing_steps.ts | 27 +++++ tests/testdata/test/steps/ignored_steps.dot.out | 5 + tests/testdata/test/steps/ignored_steps.out | 8 ++ tests/testdata/test/steps/ignored_steps.tap.out | 8 ++ tests/testdata/test/steps/ignored_steps.ts | 16 +++ tests/testdata/test/steps/invalid_usage.out | 82 +++++++++++++++ tests/testdata/test/steps/invalid_usage.ts | 118 ++++++++++++++++++++++ tests/testdata/test/steps/output_within.out | 29 ++++++ tests/testdata/test/steps/output_within.ts | 15 +++ tests/testdata/test/steps/passing_steps.dot.out | 17 ++++ tests/testdata/test/steps/passing_steps.out | 44 ++++++++ tests/testdata/test/steps/passing_steps.tap.out | 42 ++++++++ tests/testdata/test/steps/passing_steps.ts | 127 ++++++++++++++++++++++++ 16 files changed, 693 insertions(+) create mode 100644 tests/testdata/test/steps/failing_steps.dot.out create mode 100644 tests/testdata/test/steps/failing_steps.out create mode 100644 tests/testdata/test/steps/failing_steps.tap.out create mode 100644 tests/testdata/test/steps/failing_steps.ts create mode 100644 tests/testdata/test/steps/ignored_steps.dot.out create mode 100644 tests/testdata/test/steps/ignored_steps.out create mode 100644 tests/testdata/test/steps/ignored_steps.tap.out create mode 100644 tests/testdata/test/steps/ignored_steps.ts create mode 100644 tests/testdata/test/steps/invalid_usage.out create mode 100644 tests/testdata/test/steps/invalid_usage.ts create mode 100644 tests/testdata/test/steps/output_within.out create mode 100644 tests/testdata/test/steps/output_within.ts create mode 100644 tests/testdata/test/steps/passing_steps.dot.out create mode 100644 tests/testdata/test/steps/passing_steps.out create mode 100644 tests/testdata/test/steps/passing_steps.tap.out create mode 100644 tests/testdata/test/steps/passing_steps.ts (limited to 'tests/testdata/test/steps') diff --git a/tests/testdata/test/steps/failing_steps.dot.out b/tests/testdata/test/steps/failing_steps.dot.out new file mode 100644 index 000000000..f8ba8d8e6 --- /dev/null +++ b/tests/testdata/test/steps/failing_steps.dot.out @@ -0,0 +1,53 @@ +! +. +! +! +! +! +! +! +! + + ERRORS + +nested failure ... step 1 ... inner 1 => ./test/steps/failing_steps.ts:[WILDCARD] +error: Error: Failed. + throw new Error("Failed."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +multiple test step failures ... step 1 => ./test/steps/failing_steps.ts:[WILDCARD] +error: Error: Fail. + throw new Error("Fail."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +multiple test step failures ... step 2 => ./test/steps/failing_steps.ts:[WILDCARD] +error: Error: Fail. + await t.step("step 2", () => Promise.reject(new Error("Fail."))); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +failing step in failing test ... step 1 => ./test/steps/failing_steps.ts:[WILDCARD] +error: Error: Fail. + throw new Error("Fail."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +failing step in failing test => ./test/steps/failing_steps.ts:[WILDCARD] +error: Error: Fail test. + throw new Error("Fail test."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + + FAILURES + +nested failure ... step 1 ... inner 1 => ./test/steps/failing_steps.ts:[WILDCARD] +multiple test step failures ... step 1 => ./test/steps/failing_steps.ts:[WILDCARD] +multiple test step failures ... step 2 => ./test/steps/failing_steps.ts:[WILDCARD] +failing step in failing test ... step 1 => ./test/steps/failing_steps.ts:[WILDCARD] +failing step in failing test => ./test/steps/failing_steps.ts:[WILDCARD] + +FAILED | 0 passed (1 step) | 3 failed (5 steps) ([WILDCARD]) + +error: Test failed diff --git a/tests/testdata/test/steps/failing_steps.out b/tests/testdata/test/steps/failing_steps.out new file mode 100644 index 000000000..4b717f5cc --- /dev/null +++ b/tests/testdata/test/steps/failing_steps.out @@ -0,0 +1,59 @@ +[WILDCARD] +running 3 tests from ./test/steps/failing_steps.ts +nested failure ... + step 1 ... + inner 1 ... FAILED ([WILDCARD]) + inner 2 ... ok ([WILDCARD]) + step 1 ... FAILED (due to 1 failed step) ([WILDCARD]) +nested failure ... FAILED (due to 1 failed step) ([WILDCARD]) +multiple test step failures ... + step 1 ... FAILED ([WILDCARD]) + step 2 ... FAILED ([WILDCARD]) +multiple test step failures ... FAILED (due to 2 failed steps) ([WILDCARD]) +failing step in failing test ... + step 1 ... FAILED ([WILDCARD]) +failing step in failing test ... FAILED ([WILDCARD]) + + ERRORS + +nested failure ... step 1 ... inner 1 => ./test/steps/failing_steps.ts:[WILDCARD] +error: Error: Failed. + throw new Error("Failed."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +multiple test step failures ... step 1 => ./test/steps/failing_steps.ts:[WILDCARD] +error: Error: Fail. + throw new Error("Fail."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +multiple test step failures ... step 2 => ./test/steps/failing_steps.ts:[WILDCARD] +error: Error: Fail. + await t.step("step 2", () => Promise.reject(new Error("Fail."))); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +failing step in failing test ... step 1 => ./test/steps/failing_steps.ts:[WILDCARD] +error: Error: Fail. + throw new Error("Fail."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + +failing step in failing test => ./test/steps/failing_steps.ts:[WILDCARD] +error: Error: Fail test. + throw new Error("Fail test."); + ^ + at [WILDCARD]/failing_steps.ts:[WILDCARD] + + FAILURES + +nested failure ... step 1 ... inner 1 => ./test/steps/failing_steps.ts:[WILDCARD] +multiple test step failures ... step 1 => ./test/steps/failing_steps.ts:[WILDCARD] +multiple test step failures ... step 2 => ./test/steps/failing_steps.ts:[WILDCARD] +failing step in failing test ... step 1 => ./test/steps/failing_steps.ts:[WILDCARD] +failing step in failing test => ./test/steps/failing_steps.ts:[WILDCARD] + +FAILED | 0 passed (1 step) | 3 failed (5 steps) ([WILDCARD]) + +error: Test failed diff --git a/tests/testdata/test/steps/failing_steps.tap.out b/tests/testdata/test/steps/failing_steps.tap.out new file mode 100644 index 000000000..11b289f08 --- /dev/null +++ b/tests/testdata/test/steps/failing_steps.tap.out @@ -0,0 +1,43 @@ +TAP version 14 +# ./test/steps/failing_steps.ts +# Subtest: nested failure + not ok 1 - inner 1 + --- + {"message":"Error: Failed.\n throw new Error(\"Failed.\");\n ^\n at [WILDCARD]/failing_steps.ts:[WILDCARD]\n[WILDCARD]","severity":"fail","at":{"file":"./test/steps/failing_steps.ts","line":[WILDCARD]}} + ... + ok 2 - inner 2 + not ok 3 - step 1 + --- + {"message":"1 test step failed.","severity":"fail","at":{"file":"./test/steps/failing_steps.ts","line":[WILDCARD]}} + ... + 1..3 +not ok 1 - nested failure + --- + {"message":"1 test step failed.","severity":"fail","at":{"file":"./test/steps/failing_steps.ts","line":[WILDCARD]}} + ... +# Subtest: multiple test step failures + not ok 1 - step 1 + --- + {"message":"Error: Fail.\n throw new Error(\"Fail.\");\n ^\n at [WILDCARD]/failing_steps.ts:[WILDCARD]\n[WILDCARD]","severity":"fail","at":{"file":"./test/steps/failing_steps.ts","line":[WILDCARD]}} + ... + not ok 2 - step 2 + --- + {"message":"Error: Fail.\n await t.step(\"step 2\", () => Promise.reject(new Error(\"Fail.\")));\n ^\n at [WILDCARD]/failing_steps.ts:[WILDCARD]\n[WILDCARD]","severity":"fail","at":{"file":"./test/steps/failing_steps.ts","line":[WILDCARD]}} + ... + 1..2 +not ok 2 - multiple test step failures + --- + {"message":"2 test steps failed.","severity":"fail","at":{"file":"./test/steps/failing_steps.ts","line":[WILDCARD]}} + ... +# Subtest: failing step in failing test + not ok 1 - step 1 + --- + {"message":"Error: Fail.\n throw new Error(\"Fail.\");\n ^\n at [WILDCARD]/failing_steps.ts:[WILDCARD]\n[WILDCARD]","severity":"fail","at":{"file":"./test/steps/failing_steps.ts","line":[WILDCARD]}} + ... + 1..1 +not ok 3 - failing step in failing test + --- + {"message":"Error: Fail test.\n throw new Error(\"Fail test.\");\n ^\n at [WILDCARD]/failing_steps.ts:[WILDCARD]","severity":"fail","at":{"file":"./test/steps/failing_steps.ts","line":[WILDCARD]}} + ... +1..3 +error: Test failed diff --git a/tests/testdata/test/steps/failing_steps.ts b/tests/testdata/test/steps/failing_steps.ts new file mode 100644 index 000000000..efa18d54e --- /dev/null +++ b/tests/testdata/test/steps/failing_steps.ts @@ -0,0 +1,27 @@ +Deno.test("nested failure", async (t) => { + const success = await t.step("step 1", async (t) => { + let success = await t.step("inner 1", () => { + throw new Error("Failed."); + }); + if (success) throw new Error("Expected failure"); + + success = await t.step("inner 2", () => {}); + if (!success) throw new Error("Expected success"); + }); + + if (success) throw new Error("Expected failure"); +}); + +Deno.test("multiple test step failures", async (t) => { + await t.step("step 1", () => { + throw new Error("Fail."); + }); + await t.step("step 2", () => Promise.reject(new Error("Fail."))); +}); + +Deno.test("failing step in failing test", async (t) => { + await t.step("step 1", () => { + throw new Error("Fail."); + }); + throw new Error("Fail test."); +}); diff --git a/tests/testdata/test/steps/ignored_steps.dot.out b/tests/testdata/test/steps/ignored_steps.dot.out new file mode 100644 index 000000000..442a06c62 --- /dev/null +++ b/tests/testdata/test/steps/ignored_steps.dot.out @@ -0,0 +1,5 @@ +, +. +. + +ok | 1 passed (1 step) | 0 failed | 0 ignored (1 step) [WILDCARD] diff --git a/tests/testdata/test/steps/ignored_steps.out b/tests/testdata/test/steps/ignored_steps.out new file mode 100644 index 000000000..2786e1e1a --- /dev/null +++ b/tests/testdata/test/steps/ignored_steps.out @@ -0,0 +1,8 @@ +[WILDCARD] +running 1 test from ./test/steps/ignored_steps.ts +ignored step ... + step 1 ... ignored ([WILDCARD]) + step 2 ... ok ([WILDCARD]) +ignored step ... ok ([WILDCARD]) + +ok | 1 passed (1 step) | 0 failed | 0 ignored (1 step) [WILDCARD] diff --git a/tests/testdata/test/steps/ignored_steps.tap.out b/tests/testdata/test/steps/ignored_steps.tap.out new file mode 100644 index 000000000..b2b2f5070 --- /dev/null +++ b/tests/testdata/test/steps/ignored_steps.tap.out @@ -0,0 +1,8 @@ +TAP version 14 +# ./test/steps/ignored_steps.ts +# Subtest: ignored step + ok 1 - step 1 # SKIP + ok 2 - step 2 + 1..2 +ok 1 - ignored step +1..1 diff --git a/tests/testdata/test/steps/ignored_steps.ts b/tests/testdata/test/steps/ignored_steps.ts new file mode 100644 index 000000000..102b481fb --- /dev/null +++ b/tests/testdata/test/steps/ignored_steps.ts @@ -0,0 +1,16 @@ +Deno.test("ignored step", async (t) => { + let result = await t.step({ + name: "step 1", + ignore: true, + fn: () => { + throw new Error("Fail."); + }, + }); + if (result !== false) throw new Error("Expected false."); + result = await t.step({ + name: "step 2", + ignore: false, + fn: () => {}, + }); + if (result !== true) throw new Error("Expected true."); +}); diff --git a/tests/testdata/test/steps/invalid_usage.out b/tests/testdata/test/steps/invalid_usage.out new file mode 100644 index 000000000..4b82befae --- /dev/null +++ b/tests/testdata/test/steps/invalid_usage.out @@ -0,0 +1,82 @@ +[WILDCARD] +running 7 tests from ./test/steps/invalid_usage.ts +capturing ... + some step ... ok ([WILDCARD]) +capturing ... FAILED ([WILDCARD]) +top level missing await ... + step ... INCOMPLETE +top level missing await ... FAILED (due to incomplete steps) ([WILDCARD]) +inner missing await ... + step ... + inner ... INCOMPLETE + step ... FAILED (due to incomplete steps) ([WILDCARD]) +inner missing await ... FAILED (due to 1 failed step) ([WILDCARD]) +parallel steps with sanitizers ... + step 1 ... INCOMPLETE + step 2 ... FAILED ([WILDCARD]) +parallel steps with sanitizers ... FAILED (due to incomplete steps) ([WILDCARD]) +parallel steps when first has sanitizer ... + step 1 ... ok ([WILDCARD]) + step 2 ... FAILED ([WILDCARD]) +parallel steps when first has sanitizer ... FAILED (due to 1 failed step) ([WILDCARD]) +parallel steps when second has sanitizer ... + step 1 ... ok ([WILDCARD]) + step 2 ... FAILED ([WILDCARD]) +parallel steps when second has sanitizer ... FAILED (due to 1 failed step) ([WILDCARD]) +parallel steps where only inner tests have sanitizers ... + step 1 ... + step inner ... ok ([WILDCARD]) + step 1 ... ok ([WILDCARD]) + step 2 ... + step inner ... FAILED ([WILDCARD]) + step 2 ... FAILED (due to 1 failed step) ([WILDCARD]) +parallel steps where only inner tests have sanitizers ... FAILED (due to 1 failed step) ([WILDCARD]) + + ERRORS + +capturing => ./test/steps/invalid_usage.ts:[WILDCARD] +error: Error: Cannot run test step after parent scope has finished execution. Ensure any `.step(...)` calls are executed before their parent scope completes execution. + await capturedContext.step("next step", () => {}); + ^ + at TestContext.step ([WILDCARD]) + at [WILDCARD]/invalid_usage.ts:[WILDCARD] + +top level missing await ... step => ./test/steps/invalid_usage.ts:[WILDCARD] +error: Didn't complete before parent. Await step with `await t.step(...)`. + +inner missing await ... step ... inner => ./test/steps/invalid_usage.ts:[WILDCARD] +error: Didn't complete before parent. Await step with `await t.step(...)`. + +parallel steps with sanitizers ... step 2 => ./test/steps/invalid_usage.ts:[WILDCARD] +error: Started test step while another test step with sanitizers was running: + * parallel steps with sanitizers ... step 1 + +parallel steps with sanitizers ... step 1 => ./test/steps/invalid_usage.ts:[WILDCARD] +error: Didn't complete before parent. Await step with `await t.step(...)`. + +parallel steps when first has sanitizer ... step 2 => ./test/steps/invalid_usage.ts:[WILDCARD] +error: Started test step while another test step with sanitizers was running: + * parallel steps when first has sanitizer ... step 1 + +parallel steps when second has sanitizer ... step 2 => ./test/steps/invalid_usage.ts:[WILDCARD] +error: Started test step with sanitizers while another test step was running: + * parallel steps when second has sanitizer ... step 1 + +parallel steps where only inner tests have sanitizers ... step 2 ... step inner => ./test/steps/invalid_usage.ts:[WILDCARD] +error: Started test step with sanitizers while another test step was running: + * parallel steps where only inner tests have sanitizers ... step 1 + + FAILURES + +capturing => ./test/steps/invalid_usage.ts:1:6 +top level missing await ... step => ./test/steps/invalid_usage.ts:[WILDCARD] +inner missing await ... step ... inner => ./test/steps/invalid_usage.ts:[WILDCARD] +parallel steps with sanitizers ... step 2 => ./test/steps/invalid_usage.ts:[WILDCARD] +parallel steps with sanitizers ... step 1 => ./test/steps/invalid_usage.ts:[WILDCARD] +parallel steps when first has sanitizer ... step 2 => ./test/steps/invalid_usage.ts:[WILDCARD] +parallel steps when second has sanitizer ... step 2 => ./test/steps/invalid_usage.ts:[WILDCARD] +parallel steps where only inner tests have sanitizers ... step 2 ... step inner => ./test/steps/invalid_usage.ts:[WILDCARD] + +FAILED | 0 passed (5 steps) | 7 failed (9 steps) ([WILDCARD]) + +error: Test failed diff --git a/tests/testdata/test/steps/invalid_usage.ts b/tests/testdata/test/steps/invalid_usage.ts new file mode 100644 index 000000000..1acfc874c --- /dev/null +++ b/tests/testdata/test/steps/invalid_usage.ts @@ -0,0 +1,118 @@ +Deno.test("capturing", async (t) => { + let capturedContext!: Deno.TestContext; + await t.step("some step", (t) => { + capturedContext = t; + }); + // this should error because the scope of the tester has already completed + await capturedContext.step("next step", () => {}); +}); + +Deno.test("top level missing await", (t) => { + t.step("step", () => { + return new Promise(() => {}); + }); +}); + +Deno.test({ + name: "inner missing await", + fn: async (t) => { + await t.step("step", (t) => { + t.step("inner", () => { + return new Promise((resolve) => setTimeout(resolve, 10)); + }); + }); + await new Promise((resolve) => setTimeout(resolve, 10)); + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}); + +Deno.test("parallel steps with sanitizers", async (t) => { + // not allowed because steps with sanitizers cannot be run in parallel + const step1Entered = Promise.withResolvers(); + const testFinished = Promise.withResolvers(); + t.step("step 1", async () => { + step1Entered.resolve(); + await testFinished.promise; + }); + await step1Entered.promise; + await t.step("step 2", () => {}); +}); + +Deno.test("parallel steps when first has sanitizer", async (t) => { + const step1Entered = Promise.withResolvers(); + const step2Finished = Promise.withResolvers(); + const step1 = t.step({ + name: "step 1", + fn: async () => { + step1Entered.resolve(); + await step2Finished.promise; + }, + }); + await step1Entered.promise; + await t.step({ + name: "step 2", + fn: () => {}, + sanitizeOps: false, + sanitizeResources: false, + sanitizeExit: false, + }); + step2Finished.resolve(); + await step1; +}); + +Deno.test("parallel steps when second has sanitizer", async (t) => { + const step1Entered = Promise.withResolvers(); + const step2Finished = Promise.withResolvers(); + const step1 = t.step({ + name: "step 1", + fn: async () => { + step1Entered.resolve(); + await step2Finished.promise; + }, + sanitizeOps: false, + sanitizeResources: false, + sanitizeExit: false, + }); + await step1Entered.promise; + await t.step({ + name: "step 2", + fn: async () => { + await new Promise((resolve) => setTimeout(resolve, 100)); + }, + }); + step2Finished.resolve(); + await step1; +}); + +Deno.test({ + name: "parallel steps where only inner tests have sanitizers", + fn: async (t) => { + const step1Entered = Promise.withResolvers(); + const step2Finished = Promise.withResolvers(); + const step1 = t.step("step 1", async (t) => { + await t.step({ + name: "step inner", + fn: async () => { + step1Entered.resolve(); + await step2Finished.promise; + }, + sanitizeOps: true, + }); + }); + await step1Entered.promise; + await t.step("step 2", async (t) => { + await t.step({ + name: "step inner", + fn: () => {}, + sanitizeOps: true, + }); + }); + step2Finished.resolve(); + await step1; + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}); diff --git a/tests/testdata/test/steps/output_within.out b/tests/testdata/test/steps/output_within.out new file mode 100644 index 000000000..d58722daa --- /dev/null +++ b/tests/testdata/test/steps/output_within.out @@ -0,0 +1,29 @@ +[WILDCARD] +running 1 test from ./test/steps/output_within.ts +description ... +------- output ------- +1 +----- output end ----- + step 1 ... +------- output ------- +2 +----- output end ----- + inner 1 ... +------- output ------- +3 +----- output end ----- + inner 1 ... ok ([WILDCARD]s) + inner 2 ... +------- output ------- +4 +----- output end ----- + inner 2 ... ok ([WILDCARD]s) +------- output ------- +5 +----- output end ----- + step 1 ... ok ([WILDCARD]s) +------- output ------- +6 +----- output end ----- +description ... ok ([WILDCARD]s) +[WILDCARD] diff --git a/tests/testdata/test/steps/output_within.ts b/tests/testdata/test/steps/output_within.ts new file mode 100644 index 000000000..d3438a8ad --- /dev/null +++ b/tests/testdata/test/steps/output_within.ts @@ -0,0 +1,15 @@ +Deno.test("description", async (t) => { + // the output is not great, but this is an extreme scenario + console.log(1); + await t.step("step 1", async (t) => { + console.log(2); + await t.step("inner 1", () => { + console.log(3); + }); + await t.step("inner 2", () => { + console.log(4); + }); + console.log(5); + }); + console.log(6); +}); diff --git a/tests/testdata/test/steps/passing_steps.dot.out b/tests/testdata/test/steps/passing_steps.dot.out new file mode 100644 index 000000000..243cacd69 --- /dev/null +++ b/tests/testdata/test/steps/passing_steps.dot.out @@ -0,0 +1,17 @@ +[WILDCARD] +. +. +. +. +. +. +. +. +. +. +. +. +. + +ok | 6 passed (21 steps) | 0 failed ([WILDCARD]) + diff --git a/tests/testdata/test/steps/passing_steps.out b/tests/testdata/test/steps/passing_steps.out new file mode 100644 index 000000000..0757a4ed3 --- /dev/null +++ b/tests/testdata/test/steps/passing_steps.out @@ -0,0 +1,44 @@ +[WILDCARD] +running 6 tests from ./test/steps/passing_steps.ts +description ... + step 1 ... + inner 1 ... ok ([WILDCARD]s) + inner 2 ... ok ([WILDCARD]s) + step 1 ... ok ([WILDCARD]s) +description ... ok ([WILDCARD]s) +description function as first arg ... + step1 ... + inner1 ... ok ([WILDCARD]s) + inner1 ... ok ([WILDCARD]s) + step1 ... ok ([WILDCARD]s) +description function as first arg ... ok ([WILDCARD]s) +parallel steps without sanitizers ... + step 1 ... ok ([WILDCARD]) + step 2 ... ok ([WILDCARD]) +parallel steps without sanitizers ... ok ([WILDCARD]) +parallel steps without sanitizers due to parent ... + step 1 ... ok ([WILDCARD]) + step 2 ... ok ([WILDCARD]) +parallel steps without sanitizers due to parent ... ok ([WILDCARD]) +steps with disabled sanitizers, then enabled, then parallel disabled ... + step 1 ... + step 1 ... + step 1 ... + step 1 ... ok ([WILDCARD]) + step 1 ... ok ([WILDCARD]) + step 1 ... ok ([WILDCARD]) + step 2 ... ok ([WILDCARD]) + step 1 ... ok ([WILDCARD]) + step 1 ... ok ([WILDCARD]) +steps with disabled sanitizers, then enabled, then parallel disabled ... ok ([WILDCARD]) +steps buffered then streaming reporting ... + step 1 ... + step 1 - 1 ... ok ([WILDCARD]) + step 1 - 2 ... + step 1 - 2 - 1 ... ok ([WILDCARD]) + step 1 - 2 ... ok ([WILDCARD]) + step 1 ... ok ([WILDCARD]) + step 2 ... ok ([WILDCARD]) +steps buffered then streaming reporting ... ok ([WILDCARD]) + +ok | 6 passed (21 steps) | 0 failed [WILDCARD] diff --git a/tests/testdata/test/steps/passing_steps.tap.out b/tests/testdata/test/steps/passing_steps.tap.out new file mode 100644 index 000000000..20a9fa312 --- /dev/null +++ b/tests/testdata/test/steps/passing_steps.tap.out @@ -0,0 +1,42 @@ +TAP version 14 +# ./test/steps/passing_steps.ts +# Subtest: description + ok 1 - inner 1 + ok 2 - inner 2 + ok 3 - step 1 + 1..3 +ok 1 - description +# Subtest: description function as first arg + ok 1 - inner1 + ok 2 - inner1 + ok 3 - step1 + 1..3 +ok 2 - description function as first arg +# Subtest: parallel steps without sanitizers + ok 1 - step 1 + ok 2 - step 2 + 1..2 +ok 3 - parallel steps without sanitizers +# Subtest: parallel steps without sanitizers due to parent + ok 1 - step 1 + ok 2 - step 2 + 1..2 +ok 4 - parallel steps without sanitizers due to parent +# Subtest: steps with disabled sanitizers, then enabled, then parallel disabled + ok 1 - step 2 + ok 2 - step 1 + ok 3 - step 1 + ok 4 - step 1 + ok 5 - step 1 + ok 6 - step 1 + 1..6 +ok 5 - steps with disabled sanitizers, then enabled, then parallel disabled +# Subtest: steps buffered then streaming reporting + ok 1 - step 1 - 2 - 1 + ok 2 - step 1 - 2 + ok 3 - step 1 - 1 + ok 4 - step 1 + ok 5 - step 2 + 1..5 +ok 6 - steps buffered then streaming reporting +1..6 diff --git a/tests/testdata/test/steps/passing_steps.ts b/tests/testdata/test/steps/passing_steps.ts new file mode 100644 index 000000000..fd145954b --- /dev/null +++ b/tests/testdata/test/steps/passing_steps.ts @@ -0,0 +1,127 @@ +Deno.test("description", async (t) => { + const success = await t.step("step 1", async (t) => { + await t.step("inner 1", () => {}); + await t.step("inner 2", () => {}); + }); + + if (!success) throw new Error("Expected the step to return true."); +}); + +Deno.test("description function as first arg", async (t) => { + const success = await t.step(async function step1(t) { + await t.step(function inner1() {}); + await t.step(function inner1() {}); + }); + + if (!success) throw new Error("Expected the step to return true."); +}); + +Deno.test("parallel steps without sanitizers", async (t) => { + // allowed + await Promise.all([ + t.step({ + name: "step 1", + fn: async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }, + sanitizeOps: false, + sanitizeResources: false, + sanitizeExit: false, + }), + t.step({ + name: "step 2", + fn: async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }, + sanitizeOps: false, + sanitizeResources: false, + sanitizeExit: false, + }), + ]); +}); + +Deno.test({ + name: "parallel steps without sanitizers due to parent", + fn: async (t) => { + // allowed because parent disabled the sanitizers + await Promise.all([ + t.step("step 1", async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }), + t.step("step 2", async () => { + await new Promise((resolve) => setTimeout(resolve, 10)); + }), + ]); + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}); + +Deno.test({ + name: "steps with disabled sanitizers, then enabled, then parallel disabled", + fn: async (t) => { + await t.step("step 1", async (t) => { + await t.step({ + name: "step 1", + fn: async (t) => { + await Promise.all([ + t.step({ + name: "step 1", + fn: async (t) => { + await new Promise((resolve) => setTimeout(resolve, 10)); + await Promise.all([ + t.step("step 1", () => {}), + t.step("step 1", () => {}), + ]); + }, + sanitizeExit: false, + sanitizeResources: false, + sanitizeOps: false, + }), + t.step({ + name: "step 2", + fn: () => {}, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, + }), + ]); + }, + sanitizeResources: true, + sanitizeOps: true, + sanitizeExit: true, + }); + }); + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, +}); + +Deno.test("steps buffered then streaming reporting", async (t) => { + // no sanitizers so this will be buffered + await t.step({ + name: "step 1", + fn: async (t) => { + // also ensure the buffered tests display in order regardless of the second one finishing first + const step2Finished = Promise.withResolvers(); + const step1 = t.step("step 1 - 1", async () => { + await step2Finished.promise; + }); + const step2 = t.step("step 1 - 2", async (t) => { + await t.step("step 1 - 2 - 1", () => {}); + }); + await step2; + step2Finished.resolve(); + await step1; + }, + sanitizeResources: false, + sanitizeOps: false, + sanitizeExit: false, + }); + + // now this will start streaming and we want to + // ensure it flushes the buffer of the last test + await t.step("step 2", async () => {}); +}); -- cgit v1.2.3