From 2a786ec6ffefbc9b41eb6412599bcecd3fed2f4e Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Thu, 12 Feb 2026 15:09:54 +0000 Subject: [PATCH] refactor(test): use tempDir pattern and remove custom timeout Address review feedback: replace tmpdirSync/beforeEach with the `using` tempDir pattern for automatic cleanup, and remove unnecessary setDefaultTimeout/beforeAll. Co-Authored-By: Claude --- test/regression/issue/26970.test.ts | 93 ++++++++++------------------- 1 file changed, 30 insertions(+), 63 deletions(-) diff --git a/test/regression/issue/26970.test.ts b/test/regression/issue/26970.test.ts index 2c154e1249..0055e5bf04 100644 --- a/test/regression/issue/26970.test.ts +++ b/test/regression/issue/26970.test.ts @@ -1,34 +1,18 @@ import { spawnSync } from "bun"; -import { beforeAll, beforeEach, expect, setDefaultTimeout, test } from "bun:test"; -import { writeFileSync } from "fs"; -import { bunEnv, bunExe, tmpdirSync } from "harness"; - -let cwd: string; - -beforeAll(() => { - setDefaultTimeout(1000 * 60 * 5); -}); - -beforeEach(() => { - cwd = tmpdirSync(); -}); +import { expect, test } from "bun:test"; +import { bunEnv, bunExe, tempDir } from "harness"; test("missing literal workspace path should not error", () => { - writeFileSync( - `${cwd}/package.json`, - JSON.stringify( - { - name: "test", - workspaces: ["terraform"], - }, - null, - 2, - ), - ); + using dir = tempDir("issue-26970", { + "package.json": JSON.stringify({ + name: "test", + workspaces: ["terraform"], + }), + }); const { stderr, exitCode } = spawnSync({ cmd: [bunExe(), "install"], - cwd, + cwd: String(dir), env: bunEnv, stderr: "pipe", stdout: "pipe", @@ -40,21 +24,16 @@ test("missing literal workspace path should not error", () => { }); test("missing glob workspace pattern should not error", () => { - writeFileSync( - `${cwd}/package.json`, - JSON.stringify( - { - name: "test", - workspaces: ["terraform*"], - }, - null, - 2, - ), - ); + using dir = tempDir("issue-26970", { + "package.json": JSON.stringify({ + name: "test", + workspaces: ["terraform*"], + }), + }); const { stderr, exitCode } = spawnSync({ cmd: [bunExe(), "install"], - cwd, + cwd: String(dir), env: bunEnv, stderr: "pipe", stdout: "pipe", @@ -66,43 +45,31 @@ test("missing glob workspace pattern should not error", () => { }); test("literal and glob missing workspaces behave the same", () => { - // Test literal path - writeFileSync( - `${cwd}/package.json`, - JSON.stringify( - { - name: "test", - workspaces: ["nonexistent"], - }, - null, - 2, - ), - ); + using literalDir = tempDir("issue-26970", { + "package.json": JSON.stringify({ + name: "test", + workspaces: ["nonexistent"], + }), + }); const literalResult = spawnSync({ cmd: [bunExe(), "install"], - cwd, + cwd: String(literalDir), env: bunEnv, stderr: "pipe", stdout: "pipe", }); - // Test glob pattern - writeFileSync( - `${cwd}/package.json`, - JSON.stringify( - { - name: "test", - workspaces: ["nonexistent*"], - }, - null, - 2, - ), - ); + using globDir = tempDir("issue-26970", { + "package.json": JSON.stringify({ + name: "test", + workspaces: ["nonexistent*"], + }), + }); const globResult = spawnSync({ cmd: [bunExe(), "install"], - cwd, + cwd: String(globDir), env: bunEnv, stderr: "pipe", stdout: "pipe",