From f0304d430bdc5de3e3c92c472fb070ffda5a30aa Mon Sep 17 00:00:00 2001 From: Tomas Zijdemans Date: Thu, 1 Jan 2026 22:00:46 +0100 Subject: [PATCH 1/2] refactor(testing): remove duplicate TestContext class from bdd_test.ts --- testing/_test_helpers.ts | 2 +- testing/bdd_test.ts | 54 +--------------------------------------- 2 files changed, 2 insertions(+), 54 deletions(-) diff --git a/testing/_test_helpers.ts b/testing/_test_helpers.ts index f98a93d17c5a..323d52542417 100644 --- a/testing/_test_helpers.ts +++ b/testing/_test_helpers.ts @@ -8,7 +8,7 @@ import { import { assertSpyCall, assertSpyCalls, type Spy, spy, stub } from "./mock.ts"; import { TestSuiteInternal } from "./_test_suite.ts"; -class TestContext implements Deno.TestContext { +export class TestContext implements Deno.TestContext { name: string; origin: string; steps: TestContext[]; diff --git a/testing/bdd_test.ts b/testing/bdd_test.ts index 2f7e95bb629d..cdca71cfb590 100644 --- a/testing/bdd_test.ts +++ b/testing/bdd_test.ts @@ -19,59 +19,7 @@ import { } from "./bdd.ts"; import { TestSuiteInternal } from "./_test_suite.ts"; import { assertSpyCall, assertSpyCalls, type Spy, spy, stub } from "./mock.ts"; - -class TestContext implements Deno.TestContext { - name: string; - origin: string; - steps: TestContext[]; - spies: { - step: Spy; - }; - - constructor(name: string) { - this.name = name; - this.origin = "origin"; - this.spies = { - step: spy(this, "step"), - }; - this.steps = []; - } - - async step(t: Deno.TestStepDefinition): Promise; - async step( - name: string, - fn: (t: Deno.TestContext) => void | Promise, - ): Promise; - async step( - fn: (t: Deno.TestContext) => void | Promise, - ): Promise; - async step( - tOrNameOrFn: - | Deno.TestStepDefinition - | string - | ((t: Deno.TestContext) => void | Promise), - fn?: (t: Deno.TestContext) => void | Promise, - ): Promise { - let ignore = false; - if (typeof tOrNameOrFn === "function") { - ignore = false; - fn = tOrNameOrFn; - } else if (typeof tOrNameOrFn === "object") { - ignore = tOrNameOrFn.ignore ?? false; - fn = tOrNameOrFn.fn; - } - - const name = typeof tOrNameOrFn === "string" - ? tOrNameOrFn - : tOrNameOrFn.name; - const context = new TestContext(name); - this.steps.push(context); - if (!ignore) { - await fn!(context); - } - return !ignore; - } -} +import { TestContext } from "./_test_helpers.ts"; const baseStepOptions: Omit = { ignore: false, From 505f325143c44adcc3ead14bbe854fb296efcf83 Mon Sep 17 00:00:00 2001 From: Tomas Zijdemans Date: Thu, 1 Jan 2026 22:00:59 +0100 Subject: [PATCH 2/2] refactor(data_structures): use shared test utilities in binary_search_tree_test.ts --- data_structures/binary_search_tree_test.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/data_structures/binary_search_tree_test.ts b/data_structures/binary_search_tree_test.ts index 4ae14e4f170d..b4ceb28f8ba2 100644 --- a/data_structures/binary_search_tree_test.ts +++ b/data_structures/binary_search_tree_test.ts @@ -7,17 +7,7 @@ import { } from "@std/assert"; import { BinarySearchTree } from "./binary_search_tree.ts"; import { ascend, descend } from "./comparators.ts"; - -class MyMath { - multiply(a: number, b: number): number { - return a * b; - } -} - -interface Container { - id: number; - values: number[]; -} +import { type Container, MyMath } from "./_test_utils.ts"; Deno.test("BinarySearchTree throws if compare is not a function", () => { assertThrows(