From e0b9c745c15720914f14996bf357d5b375e2dbd8 Mon Sep 17 00:00:00 2001 From: HasanAlrimawi <141642411+HasanAlrimawi@users.noreply.github.com> Date: Mon, 16 Sep 2024 22:38:40 +0300 Subject: chore: deprecate test itests (#25512) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR is part of #22907 --------- Signed-off-by: HasanAlrimawi <141642411+HasanAlrimawi@users.noreply.github.com> Co-authored-by: Bartek IwaƄczuk --- .../specs/test/steps_invalid_usage/__test__.jsonc | 5 + .../test/steps_invalid_usage/invalid_usage.out | 82 ++++++++++++++ .../test/steps_invalid_usage/invalid_usage.ts | 118 +++++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 tests/specs/test/steps_invalid_usage/__test__.jsonc create mode 100644 tests/specs/test/steps_invalid_usage/invalid_usage.out create mode 100644 tests/specs/test/steps_invalid_usage/invalid_usage.ts (limited to 'tests/specs/test/steps_invalid_usage') diff --git a/tests/specs/test/steps_invalid_usage/__test__.jsonc b/tests/specs/test/steps_invalid_usage/__test__.jsonc new file mode 100644 index 000000000..763ec2a20 --- /dev/null +++ b/tests/specs/test/steps_invalid_usage/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "test invalid_usage.ts", + "exitCode": 1, + "output": "invalid_usage.out" +} diff --git a/tests/specs/test/steps_invalid_usage/invalid_usage.out b/tests/specs/test/steps_invalid_usage/invalid_usage.out new file mode 100644 index 000000000..413a97cfd --- /dev/null +++ b/tests/specs/test/steps_invalid_usage/invalid_usage.out @@ -0,0 +1,82 @@ +[WILDCARD] +running 7 tests from [WILDCARD]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 => [WILDCARD]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 => [WILDCARD]invalid_usage.ts:[WILDCARD] +error: Didn't complete before parent. Await step with `await t.step(...)`. + +inner missing await ... step ... inner => [WILDCARD]invalid_usage.ts:[WILDCARD] +error: Didn't complete before parent. Await step with `await t.step(...)`. + +parallel steps with sanitizers ... step 2 => [WILDCARD]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 => [WILDCARD]invalid_usage.ts:[WILDCARD] +error: Didn't complete before parent. Await step with `await t.step(...)`. + +parallel steps when first has sanitizer ... step 2 => [WILDCARD]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 => [WILDCARD]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 => [WILDCARD]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 => [WILDCARD]invalid_usage.ts:1:6 +top level missing await ... step => [WILDCARD]invalid_usage.ts:[WILDCARD] +inner missing await ... step ... inner => [WILDCARD]invalid_usage.ts:[WILDCARD] +parallel steps with sanitizers ... step 2 => [WILDCARD]invalid_usage.ts:[WILDCARD] +parallel steps with sanitizers ... step 1 => [WILDCARD]invalid_usage.ts:[WILDCARD] +parallel steps when first has sanitizer ... step 2 => [WILDCARD]invalid_usage.ts:[WILDCARD] +parallel steps when second has sanitizer ... step 2 => [WILDCARD]invalid_usage.ts:[WILDCARD] +parallel steps where only inner tests have sanitizers ... step 2 ... step inner => [WILDCARD]invalid_usage.ts:[WILDCARD] + +FAILED | 0 passed (5 steps) | 7 failed (9 steps) ([WILDCARD]) + +error: Test failed diff --git a/tests/specs/test/steps_invalid_usage/invalid_usage.ts b/tests/specs/test/steps_invalid_usage/invalid_usage.ts new file mode 100644 index 000000000..1acfc874c --- /dev/null +++ b/tests/specs/test/steps_invalid_usage/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, +}); -- cgit v1.2.3