From ac594727f98326087fbf5bdff4ce71748848a2f5 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Thu, 1 May 2025 15:13:40 +0900 Subject: [PATCH] chore: run some test cases in bun in CI --- .github/workflows/ci.yml | 26 ++++ .gitignore | 3 + _tools/node_test_runner/.gitignore | 1 + _tools/node_test_runner/run_test.mjs | 6 +- _tools/node_test_runner/tsconfig_for_bun.json | 15 ++ collections/invert_test.ts | 2 +- deno.json | 1 + fs/_node_fs_file_test.ts | 117 +++++++++------- fs/unstable_chown_test.ts | 10 +- fs/unstable_read_file_test.ts | 64 +++++---- fs/unstable_read_text_file_test.ts | 36 +++-- fs/unstable_remove_test.ts | 130 ++++++++++-------- fs/unstable_truncate_test.ts | 70 ++++++---- fs/unstable_write_file_test.ts | 84 ++++++----- fs/unstable_write_text_file_test.ts | 76 +++++----- 15 files changed, 389 insertions(+), 252 deletions(-) create mode 100644 _tools/node_test_runner/tsconfig_for_bun.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af64e7f021b8..a8491a7f3117 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,6 +102,32 @@ jobs: - name: Run tests run: deno task test:node + test-bun: + runs-on: ${{ matrix.os }} + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + bun: + - latest + os: + - ubuntu-latest + + steps: + - name: Clone repository + uses: actions/checkout@v4 + + - name: Set up Deno + uses: denoland/setup-deno@v2 + + - name: Set up Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: ${{ matrix.node }} + + - name: Run tests + run: deno task test:bun + lint: runs-on: ${{ matrix.os }} timeout-minutes: 30 diff --git a/.gitignore b/.gitignore index 207b5af6ca52..beb80425216f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ coverage/ .vim _tmp/ !_tmp/.keep + +# tsconfig for bun +/tsconfig.json diff --git a/_tools/node_test_runner/.gitignore b/_tools/node_test_runner/.gitignore index d5f19d89b308..8c6b742a34ee 100644 --- a/_tools/node_test_runner/.gitignore +++ b/_tools/node_test_runner/.gitignore @@ -1,2 +1,3 @@ node_modules package-lock.json +bun.lock diff --git a/_tools/node_test_runner/run_test.mjs b/_tools/node_test_runner/run_test.mjs index 187b53585eb2..f33a432144e5 100644 --- a/_tools/node_test_runner/run_test.mjs +++ b/_tools/node_test_runner/run_test.mjs @@ -75,5 +75,9 @@ import "../../fs/unstable_umask_test.ts"; import "../../fs/unstable_utime_test.ts"; for (const testDef of testDefinitions) { - test(testDef.name, testDef.fn); + if (testDef.ignore) { + test.skip(testDef.name, testDef.fn); + } else { + test(testDef.name, testDef.fn); + } } diff --git a/_tools/node_test_runner/tsconfig_for_bun.json b/_tools/node_test_runner/tsconfig_for_bun.json new file mode 100644 index 000000000000..940519e16628 --- /dev/null +++ b/_tools/node_test_runner/tsconfig_for_bun.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "paths": { + "@std/assert": ["./assert/mod.ts"], + "@std/assert/greater-or-equal": ["./assert/greater_or_equal.ts"], + "@std/path": ["./path/mod.ts"], + "@std/internal/format": ["./internal/format.ts"], + "@std/internal/styles": ["./internal/styles.ts"], + "@std/internal/build-message": ["./internal/build_message.ts"], + "@std/internal/diff": ["./internal/diff.ts"], + "@std/internal/diff-str": ["./internal/diff_str.ts"], + "@std/semver": ["./semver/mod.ts"], + } + } +} diff --git a/collections/invert_test.ts b/collections/invert_test.ts index 15474c9989c2..2b1876d0980f 100644 --- a/collections/invert_test.ts +++ b/collections/invert_test.ts @@ -29,7 +29,7 @@ Deno.test("invert() handles nested input", () => { // @ts-expect-error - testing invalid input invertTest({ a: "x", b: Object }, { "x": "a", - "function Object() { [native code] }": "b", + [Object.toString()]: "b", }); // @ts-expect-error - testing invalid input invertTest({ a: "x", b: ["y", "z"] }, { "x": "a", "y,z": "b" }); diff --git a/deno.json b/deno.json index 5737fd089ea3..f901c611cac3 100644 --- a/deno.json +++ b/deno.json @@ -12,6 +12,7 @@ "test:with-unsafe-proto": "deno test --unstable-http --unstable-webgpu --unstable-fs --unstable-unsafe-proto --doc --allow-all --parallel --coverage --trace-leaks --clean", "test:browser": "git grep --name-only \"This module is browser compatible.\" | grep -v deno.json | grep -v .github/workflows | grep -v _tools | grep -v encoding/README.md | grep -v media_types/vendor/update.ts | xargs deno check --config browser-compat.tsconfig.json", "test:node": "(cd _tools/node_test_runner && npm install) && node --import ./_tools/node_test_runner/register_deno_shim.mjs ./_tools/node_test_runner/run_test.mjs", + "test:bun": "(cd _tools/node_test_runner && bun install) && cp _tools/node_test_runner/tsconfig_for_bun.json ./tsconfig.json && bun test --require ./_tools/node_test_runner/register_deno_shim.mjs _tools/node_test_runner/run_test.mjs && rm tsconfig.json", "fmt:licence-headers": "deno run --allow-read --allow-write ./_tools/check_licence.ts", "lint:circular": "deno run --allow-env --allow-read --allow-write --allow-net=deno.land,jsr.io ./_tools/check_circular_package_dependencies.ts", "lint:mod-exports": "deno run --allow-env --allow-read ./_tools/check_mod_exports.ts", diff --git a/fs/_node_fs_file_test.ts b/fs/_node_fs_file_test.ts index c5b03285a58c..ad57c8533280 100644 --- a/fs/_node_fs_file_test.ts +++ b/fs/_node_fs_file_test.ts @@ -13,6 +13,7 @@ import { fileURLToPath } from "node:url"; const moduleDir = dirname(fileURLToPath(import.meta.url)); const testdataDir = resolve(moduleDir, "testdata"); const readTestFile = join(testdataDir, "copy_file.txt"); +const isBun = navigator.userAgent.includes("Bun/"); Deno.test("FsFile object writes to a newly created file", async () => { const tempDirPath = await makeTempDir({ prefix: "FsFile_write_" }); @@ -126,39 +127,47 @@ Deno.test("FsFile object returns the 'stat' of the file handle", async () => { fh.close(); }); -Deno.test("FsFile object handles a ReadableStream", async () => { - const fh = await open(readTestFile); - assert(fh.readable instanceof ReadableStream); - const chunks = []; - for await (const chunk of fh.readable) { - chunks.push(chunk); - } - assertEquals(chunks.length, 1); - if (chunks[0] != null) { - assertEquals(chunks[0].byteLength, 3); - } -}); - -Deno.test("FsFile object handles a WritableStream", async () => { - const tempDirPath = await makeTempDir({ prefix: "FsFile_WritableStream_" }); - const testFile = join(tempDirPath, "testFile.txt"); - const fh = await open(testFile, { create: true, write: true }); - assert(fh.writable instanceof WritableStream); - const rs = new ReadableStream({ - start(controller) { - const encoder = new TextEncoder(); - controller.enqueue(encoder.encode("Hello,")); - controller.enqueue(encoder.encode(" Standard")); - controller.enqueue(encoder.encode(" Library")); - controller.close(); - }, - }); - await rs.pipeTo(fh.writable); - const readText = await readTextFile(testFile); - assertEquals(readText, "Hello, Standard Library"); - - await remove(tempDirPath, { recursive: true }); -}); +Deno.test( + "FsFile object handles a ReadableStream", + { ignore: isBun }, + async () => { + const fh = await open(readTestFile); + assert(fh.readable instanceof ReadableStream); + const chunks = []; + for await (const chunk of fh.readable) { + chunks.push(chunk); + } + assertEquals(chunks.length, 1); + if (chunks[0] != null) { + assertEquals(chunks[0].byteLength, 3); + } + }, +); + +Deno.test( + "FsFile object handles a WritableStream", + { ignore: isBun }, + async () => { + const tempDirPath = await makeTempDir({ prefix: "FsFile_WritableStream_" }); + const testFile = join(tempDirPath, "testFile.txt"); + const fh = await open(testFile, { create: true, write: true }); + assert(fh.writable instanceof WritableStream); + const rs = new ReadableStream({ + start(controller) { + const encoder = new TextEncoder(); + controller.enqueue(encoder.encode("Hello,")); + controller.enqueue(encoder.encode(" Standard")); + controller.enqueue(encoder.encode(" Library")); + controller.close(); + }, + }); + await rs.pipeTo(fh.writable); + const readText = await readTextFile(testFile); + assertEquals(readText, "Hello, Standard Library"); + + await remove(tempDirPath, { recursive: true }); + }, +); Deno.test("FsFile object changes access and modification times with utime", async () => { const tempFile = await makeTempFile({ prefix: "FsFile_utime_" }); @@ -232,28 +241,32 @@ Deno.test("FsFile object synchronously reads from an existing file", () => { fh.close(); }); -Deno.test("FsFile object synchronously truncates a file to zero", () => { - const tempDirPath = makeTempDirSync({ prefix: "FsFile_truncateSync_" }); - const testFile = join(tempDirPath, "testFile.txt"); - let fh = openSync(testFile, { read: true, write: true, create: true }); - - const encoder = new TextEncoder(); - const data = encoder.encode("Hello, Standard Library"); - const writeBytes = fh.writeSync(data); - assertEquals(writeBytes, 23); - fh.close(); +Deno.test( + "FsFile object synchronously truncates a file to zero", + { ignore: isBun }, + () => { + const tempDirPath = makeTempDirSync({ prefix: "FsFile_truncateSync_" }); + const testFile = join(tempDirPath, "testFile.txt"); + let fh = openSync(testFile, { read: true, write: true, create: true }); + + const encoder = new TextEncoder(); + const data = encoder.encode("Hello, Standard Library"); + const writeBytes = fh.writeSync(data); + assertEquals(writeBytes, 23); + fh.close(); - fh = openSync(testFile, { read: true, write: true }); - fh.truncateSync(); + fh = openSync(testFile, { read: true, write: true }); + fh.truncateSync(); - const buf = new Uint8Array(10); - const readBytes = fh.readSync(buf); - // Reading a 0 byte file should return null at EOF. - assertEquals(readBytes, null); - fh.close(); + const buf = new Uint8Array(10); + const readBytes = fh.readSync(buf); + // Reading a 0 byte file should return null at EOF. + assertEquals(readBytes, null); + fh.close(); - removeSync(tempDirPath, { recursive: true }); -}); + removeSync(tempDirPath, { recursive: true }); + }, +); Deno.test("FsFile object synchronously truncates files to multiple sizes", () => { const tempDirPath = makeTempDirSync({ prefix: "FsFile_truncateSync_" }); diff --git a/fs/unstable_chown_test.ts b/fs/unstable_chown_test.ts index e49f9c18ed9d..d58bc754f53c 100644 --- a/fs/unstable_chown_test.ts +++ b/fs/unstable_chown_test.ts @@ -8,6 +8,8 @@ import { remove, removeSync } from "./unstable_remove.ts"; import { platform } from "node:os"; import { spawn } from "node:child_process"; +const isBun = navigator.userAgent.includes("Bun/"); + type IdResult = { id: string; code: number; @@ -64,7 +66,7 @@ async function getUidAndGid(): Promise<{ uid: number; gid: number }> { Deno.test({ name: "chown() changes user and group ids", - ignore: platform() === "win32", + ignore: platform() === "win32" || isBun, fn: async () => { const { uid, gid } = await getUidAndGid(); const tempFile = await makeTempFile({ prefix: "chown_" }); @@ -78,7 +80,7 @@ Deno.test({ Deno.test({ name: "chown() handles `null` id arguments", - ignore: platform() === "win32", + ignore: platform() === "win32" || isBun, fn: async () => { const { uid, gid } = await getUidAndGid(); const tempFile = await makeTempFile({ prefix: "chown_" }); @@ -115,7 +117,7 @@ Deno.test({ Deno.test({ name: "chownSync() changes user and group ids", - ignore: platform() === "win32", + ignore: platform() === "win32" || isBun, fn: async () => { const { uid, gid } = await getUidAndGid(); const tempFile = makeTempFileSync({ prefix: "chownSync_ " }); @@ -130,7 +132,7 @@ Deno.test({ Deno.test({ name: "chownSync() handles `null` id arguments", - ignore: platform() === "win32", + ignore: platform() === "win32" || isBun, fn: async () => { const { uid, gid } = await getUidAndGid(); const tempFile = makeTempFileSync({ prefix: "chownSync_" }); diff --git a/fs/unstable_read_file_test.ts b/fs/unstable_read_file_test.ts index ead5887997f8..5cfce71cb08e 100644 --- a/fs/unstable_read_file_test.ts +++ b/fs/unstable_read_file_test.ts @@ -13,6 +13,8 @@ import { isDeno } from "./_utils.ts"; import { dirname, join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; +const isBun = navigator.userAgent.includes("Bun/"); + const moduleDir = dirname(fileURLToPath(import.meta.url)); const testdataDir = resolve(moduleDir, "testdata"); const testFile = join(testdataDir, "copy_file.txt"); @@ -47,39 +49,47 @@ Deno.test("readFile() handles an AbortSignal", async () => { assertEquals(error.name, "AbortError"); }); -Deno.test("readFile() handles an AbortSignal with a reason", async () => { - const ac = new AbortController(); - const reasonErr = new Error(); - queueMicrotask(() => ac.abort(reasonErr)); - - const error = await assertRejects(async () => { - await readFile(testFile, { signal: ac.signal }); - }, Error); - - if (isDeno) { - assertEquals(error, ac.signal.reason); - } else { - assertEquals(error.cause, ac.signal.reason); - } -}); +Deno.test( + "readFile() handles an AbortSignal with a reason", + { ignore: isBun }, + async () => { + const ac = new AbortController(); + const reasonErr = new Error(); + queueMicrotask(() => ac.abort(reasonErr)); -Deno.test("readFile() handles an AbortSignal with a primitive reason value", async () => { - const ac = new AbortController(); - const reasonErr = "Some string"; - queueMicrotask(() => ac.abort(reasonErr)); + const error = await assertRejects(async () => { + await readFile(testFile, { signal: ac.signal }); + }, Error); - try { - await readFile(testFile, { signal: ac.signal }); - unreachable(); - } catch (error) { if (isDeno) { assertEquals(error, ac.signal.reason); } else { - const errorValue = error as Error; - assertEquals(errorValue.cause, ac.signal.reason); + assertEquals(error.cause, ac.signal.reason); } - } -}); + }, +); + +Deno.test( + "readFile() handles an AbortSignal with a primitive reason value", + { ignore: isBun }, + async () => { + const ac = new AbortController(); + const reasonErr = "Some string"; + queueMicrotask(() => ac.abort(reasonErr)); + + try { + await readFile(testFile, { signal: ac.signal }); + unreachable(); + } catch (error) { + if (isDeno) { + assertEquals(error, ac.signal.reason); + } else { + const errorValue = error as Error; + assertEquals(errorValue.cause, ac.signal.reason); + } + } + }, +); Deno.test("readFile() handles cleanup of an AbortController", async () => { const ac = new AbortController(); diff --git a/fs/unstable_read_text_file_test.ts b/fs/unstable_read_text_file_test.ts index 153292ba821e..d38a2bbeeaac 100644 --- a/fs/unstable_read_text_file_test.ts +++ b/fs/unstable_read_text_file_test.ts @@ -7,6 +7,8 @@ import { isDeno } from "./_utils.ts"; import { NotFound } from "./unstable_errors.js"; import { readTextFile, readTextFileSync } from "./unstable_read_text_file.ts"; +const isBun = navigator.userAgent.includes("Bun/"); + const moduleDir = dirname(fileURLToPath(import.meta.url)); const testDir = resolve(moduleDir, "testdata"); const testFile = join(testDir, "copy_file.txt"); @@ -42,21 +44,25 @@ Deno.test("readTextFile() handles an AbortSignal", async () => { assertEquals(error.name, "AbortError"); }); -Deno.test("readTextFile() handles an AbortSignal with a reason", async () => { - const ac = new AbortController(); - const reasonErr = new Error(); - queueMicrotask(() => ac.abort(reasonErr)); - - const error = await assertRejects(async () => { - await readTextFile(testFile, { signal: ac.signal }); - }, Error); - - if (isDeno) { - assertEquals(error, ac.signal.reason); - } else { - assertEquals(error.cause, ac.signal.reason); - } -}); +Deno.test( + "readTextFile() handles an AbortSignal with a reason", + { ignore: isBun }, + async () => { + const ac = new AbortController(); + const reasonErr = new Error(); + queueMicrotask(() => ac.abort(reasonErr)); + + const error = await assertRejects(async () => { + await readTextFile(testFile, { signal: ac.signal }); + }, Error); + + if (isDeno) { + assertEquals(error, ac.signal.reason); + } else { + assertEquals(error.cause, ac.signal.reason); + } + }, +); Deno.test("readTextFileSync() reads content from txt file", () => { const content = readTextFileSync(testFile); diff --git a/fs/unstable_remove_test.ts b/fs/unstable_remove_test.ts index 087e0848cd9e..dc0d47403579 100644 --- a/fs/unstable_remove_test.ts +++ b/fs/unstable_remove_test.ts @@ -9,6 +9,8 @@ import { makeTempDir, makeTempDirSync } from "./unstable_make_temp_dir.ts"; import { remove, removeSync } from "./unstable_remove.ts"; import { stat, statSync } from "./unstable_stat.ts"; +const isBun = navigator.userAgent.includes("Bun/"); + async function checkExists(path: string | URL) { try { const stated = await stat(path); @@ -33,19 +35,23 @@ function checkExistsSync(path: string | URL) { } } -Deno.test("remove() removes an existing and empty directory", async () => { - const tempDir = await makeTempDir({ prefix: "remove_async_" }); - const existedCheck = await stat(tempDir); - assert(existedCheck.isDirectory === true); - - try { - await remove(tempDir); - const existed = await checkExists(tempDir); - assert(existed === false); - } finally { - await rm(tempDir, { recursive: true, force: true }); - } -}); +Deno.test( + "remove() removes an existing and empty directory", + { ignore: isBun }, + async () => { + const tempDir = await makeTempDir({ prefix: "remove_async_" }); + const existedCheck = await stat(tempDir); + assert(existedCheck.isDirectory === true); + + try { + await remove(tempDir); + const existed = await checkExists(tempDir); + assert(existed === false); + } finally { + await rm(tempDir, { recursive: true, force: true }); + } + }, +); Deno.test("remove() remove a non empty directory", async () => { const tempDir1 = await makeTempDir({ prefix: "remove_async_" }); @@ -74,49 +80,61 @@ Deno.test("remove() remove a non empty directory", async () => { } }); -Deno.test("remove() remove a non existed directory", async () => { - const tempDir = await makeTempDir({ prefix: "remove_async_" }); - const nonExistedDir = join(tempDir, "non", "existed", "dir"); - - try { - await assertRejects(async () => { - await remove(nonExistedDir); - }, NotFound); - await remove(tempDir); - const existed = await checkExists(tempDir); - assert(existed === false); - } finally { - await rm(tempDir, { recursive: true, force: true }); - } -}); - -Deno.test("remove() remove a non existed directory with option", async () => { - const tempDir = await makeTempDir({ prefix: "remove_async_" }); - const nonExistedDir = join(tempDir, "non", "existed", "dir"); - - try { - await assertRejects(async () => { - await remove(nonExistedDir, { recursive: true }); - }, NotFound); - await remove(tempDir); - const existed = await checkExists(tempDir); - assert(existed === false); - } finally { - await rm(tempDir, { recursive: true, force: true }); - } -}); - -Deno.test("removeSync() remove an existed and empty directory", () => { - const tempDir = makeTempDirSync({ prefix: "remove_sync_" }); - assert(statSync(tempDir).isDirectory === true); - - try { - removeSync(tempDir); - assert(checkExistsSync(tempDir) === false); - } finally { - rmSync(tempDir, { recursive: true, force: true }); - } -}); +Deno.test( + "remove() remove a non existed directory", + { ignore: isBun }, + async () => { + const tempDir = await makeTempDir({ prefix: "remove_async_" }); + const nonExistedDir = join(tempDir, "non", "existed", "dir"); + + try { + await assertRejects(async () => { + await remove(nonExistedDir); + }, NotFound); + await remove(tempDir); + const existed = await checkExists(tempDir); + assert(existed === false); + } finally { + await rm(tempDir, { recursive: true, force: true }); + } + }, +); + +Deno.test( + "remove() remove a non existed directory with option", + { ignore: isBun }, + async () => { + const tempDir = await makeTempDir({ prefix: "remove_async_" }); + const nonExistedDir = join(tempDir, "non", "existed", "dir"); + + try { + await assertRejects(async () => { + await remove(nonExistedDir, { recursive: true }); + }, NotFound); + await remove(tempDir); + const existed = await checkExists(tempDir); + assert(existed === false); + } finally { + await rm(tempDir, { recursive: true, force: true }); + } + }, +); + +Deno.test( + "removeSync() remove an existed and empty directory", + { ignore: isBun }, + () => { + const tempDir = makeTempDirSync({ prefix: "remove_sync_" }); + assert(statSync(tempDir).isDirectory === true); + + try { + removeSync(tempDir); + assert(checkExistsSync(tempDir) === false); + } finally { + rmSync(tempDir, { recursive: true, force: true }); + } + }, +); Deno.test("removeSync() remove a non empty directory", () => { const tempDir1 = makeTempDirSync({ prefix: "remove_sync_" }); diff --git a/fs/unstable_truncate_test.ts b/fs/unstable_truncate_test.ts index d8b72a5879fd..a8f67e2a34e3 100644 --- a/fs/unstable_truncate_test.ts +++ b/fs/unstable_truncate_test.ts @@ -8,6 +8,8 @@ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { join, resolve } from "node:path"; import { tmpdir } from "node:os"; +const isBun = navigator.userAgent.includes("Bun/"); + Deno.test("truncate() succeeds in truncating file sizes", async () => { const tempDataDir = await mkdtemp(resolve(tmpdir(), "truncate_")); const testFile = join(tempDataDir, "truncFile.txt"); @@ -23,16 +25,20 @@ Deno.test("truncate() succeeds in truncating file sizes", async () => { await rm(tempDataDir, { recursive: true, force: true }); }); -Deno.test("truncate() truncates the file to zero when 'len' is not provided", async () => { - const tempDataDir = await mkdtemp(resolve(tmpdir(), "truncate_")); - const testFile = join(tempDataDir, "truncFile.txt"); - await writeFile(testFile, "Hello, Standard Library"); +Deno.test( + "truncate() truncates the file to zero when 'len' is not provided", + { ignore: isBun }, + async () => { + const tempDataDir = await mkdtemp(resolve(tmpdir(), "truncate_")); + const testFile = join(tempDataDir, "truncFile.txt"); + await writeFile(testFile, "Hello, Standard Library"); - await truncate(testFile); - assertEquals((await readFile(testFile)).length, 0); + await truncate(testFile); + assertEquals((await readFile(testFile)).length, 0); - await rm(tempDataDir, { recursive: true, force: true }); -}); + await rm(tempDataDir, { recursive: true, force: true }); + }, +); Deno.test("truncate() rejects with Error when passing a non-regular file", async () => { const tempDataDir = await mkdtemp(resolve(tmpdir(), "truncate_")); @@ -44,11 +50,15 @@ Deno.test("truncate() rejects with Error when passing a non-regular file", async await rm(tempDataDir, { recursive: true, force: true }); }); -Deno.test("truncate() rejects with NotFound with a non-existent file", async () => { - await assertRejects(async () => { - await truncate("non-existent-file.txt"); - }, NotFound); -}); +Deno.test( + "truncate() rejects with NotFound with a non-existent file", + { ignore: isBun }, + async () => { + await assertRejects(async () => { + await truncate("non-existent-file.txt"); + }, NotFound); + }, +); Deno.test("truncateSync() succeeds in truncating file sizes", () => { const tempDataDir = mkdtempSync(resolve(tmpdir(), "truncateSync_")); @@ -65,16 +75,20 @@ Deno.test("truncateSync() succeeds in truncating file sizes", () => { rmSync(tempDataDir, { recursive: true, force: true }); }); -Deno.test("truncateSync() truncates the file to zero when 'len' is not provided", () => { - const tempDataDir = mkdtempSync(resolve(tmpdir(), "truncateSync_")); - const testFile = join(tempDataDir, "truncFile.txt"); - writeFileSync(testFile, "Hello, Standard Library"); +Deno.test( + "truncateSync() truncates the file to zero when 'len' is not provided", + { ignore: isBun }, + () => { + const tempDataDir = mkdtempSync(resolve(tmpdir(), "truncateSync_")); + const testFile = join(tempDataDir, "truncFile.txt"); + writeFileSync(testFile, "Hello, Standard Library"); - truncateSync(testFile); - assertEquals((readFileSync(testFile)).length, 0); + truncateSync(testFile); + assertEquals((readFileSync(testFile)).length, 0); - rmSync(tempDataDir, { recursive: true, force: true }); -}); + rmSync(tempDataDir, { recursive: true, force: true }); + }, +); Deno.test("truncateSync() throws with Error with a non-regular file", () => { const tempDataDir = mkdtempSync(resolve(tmpdir(), "truncateSync_")); @@ -86,8 +100,12 @@ Deno.test("truncateSync() throws with Error with a non-regular file", () => { rmSync(tempDataDir, { recursive: true, force: true }); }); -Deno.test("truncateSync() throws with NotFound with a non-existent file", () => { - assertThrows(() => { - truncateSync("non-existent-file.txt"); - }, NotFound); -}); +Deno.test( + "truncateSync() throws with NotFound with a non-existent file", + { ignore: isBun }, + () => { + assertThrows(() => { + truncateSync("non-existent-file.txt"); + }, NotFound); + }, +); diff --git a/fs/unstable_write_file_test.ts b/fs/unstable_write_file_test.ts index fccb0cb4b442..cdf9836e8c89 100644 --- a/fs/unstable_write_file_test.ts +++ b/fs/unstable_write_file_test.ts @@ -19,6 +19,8 @@ import { rm } from "node:fs/promises"; import { platform } from "node:os"; import { join } from "node:path"; +const isBun = navigator.userAgent.includes("Bun/"); + function assertMissing(path: string | URL) { if (pathExists(path)) { throw new Error("File: ${path} exists"); @@ -177,53 +179,61 @@ Deno.test("writeFile() handles an AbortSignal", async () => { await rm(tempDirPath, { recursive: true, force: true }); }); -Deno.test("writeFile() handles an AbortSignal with a reason", async () => { - const ac = new AbortController(); - const reasonErr = new Error(); - queueMicrotask(() => ac.abort(reasonErr)); +Deno.test( + "writeFile() handles an AbortSignal with a reason", + { ignore: isBun }, + async () => { + const ac = new AbortController(); + const reasonErr = new Error(); + queueMicrotask(() => ac.abort(reasonErr)); - const tempDirPath = await makeTempDir({ prefix: "writeFile_" }); - const testFile = join(tempDirPath, "testFile.txt"); + const tempDirPath = await makeTempDir({ prefix: "writeFile_" }); + const testFile = join(tempDirPath, "testFile.txt"); - const encoder = new TextEncoder(); - const data = encoder.encode("Hello"); + const encoder = new TextEncoder(); + const data = encoder.encode("Hello"); - const error = await assertRejects(async () => { - await writeFile(testFile, data, { signal: ac.signal }); - }, Error); + const error = await assertRejects(async () => { + await writeFile(testFile, data, { signal: ac.signal }); + }, Error); - if (isDeno) { - assertEquals(error, ac.signal.reason); - } else { - assertEquals(error.cause, ac.signal.reason); - } + if (isDeno) { + assertEquals(error, ac.signal.reason); + } else { + assertEquals(error.cause, ac.signal.reason); + } - await rm(tempDirPath, { recursive: true, force: true }); -}); + await rm(tempDirPath, { recursive: true, force: true }); + }, +); -Deno.test("writeFile() handles an AbortSignal with a primitive value", async () => { - const ac = new AbortController(); - const reasonErr = "This is a primitive string"; - queueMicrotask(() => ac.abort(reasonErr)); +Deno.test( + "writeFile() handles an AbortSignal with a primitive value", + { ignore: isBun }, + async () => { + const ac = new AbortController(); + const reasonErr = "This is a primitive string"; + queueMicrotask(() => ac.abort(reasonErr)); - const tempDirPath = await makeTempDir({ prefix: "writeFile_" }); - const testFile = join(tempDirPath, "testFile.txt"); + const tempDirPath = await makeTempDir({ prefix: "writeFile_" }); + const testFile = join(tempDirPath, "testFile.txt"); - const encoder = new TextEncoder(); - const data = encoder.encode("Hello"); + const encoder = new TextEncoder(); + const data = encoder.encode("Hello"); - try { - await writeFile(testFile, data, { signal: ac.signal }); - } catch (error) { - if (isDeno) { - assertEquals(error, ac.signal.reason); - } else { - const errorValue = error as Error; - assertEquals(errorValue.cause, ac.signal.reason); + try { + await writeFile(testFile, data, { signal: ac.signal }); + } catch (error) { + if (isDeno) { + assertEquals(error, ac.signal.reason); + } else { + const errorValue = error as Error; + assertEquals(errorValue.cause, ac.signal.reason); + } + await rm(tempDirPath, { recursive: true, force: true }); } - await rm(tempDirPath, { recursive: true, force: true }); - } -}); + }, +); Deno.test("writeFile() writes to a file successfully with an attached AbortSignal", async () => { const ac = new AbortController(); diff --git a/fs/unstable_write_text_file_test.ts b/fs/unstable_write_text_file_test.ts index b7853615e0c5..874c300d7566 100644 --- a/fs/unstable_write_text_file_test.ts +++ b/fs/unstable_write_text_file_test.ts @@ -21,6 +21,8 @@ import { remove, removeSync } from "./unstable_remove.ts"; import { join } from "node:path"; import { platform } from "node:os"; +const isBun = navigator.userAgent.includes("Bun/"); + function assertMissing(path: string | URL) { if (pathExists(path)) { throw new Error(`File: ${path} exists`); @@ -152,48 +154,56 @@ Deno.test("writeTextFile() handles an AbortSignal", async () => { await remove(tempDirPath, { recursive: true }); }); -Deno.test("writeTextFile() handles an AbortSignal with a reason", async () => { - const ac = new AbortController(); - const reasonErr = new Error(); - queueMicrotask(() => ac.abort(reasonErr)); +Deno.test( + "writeTextFile() handles an AbortSignal with a reason", + { ignore: isBun }, + async () => { + const ac = new AbortController(); + const reasonErr = new Error(); + queueMicrotask(() => ac.abort(reasonErr)); - const tempDirPath = await makeTempDir({ prefix: "writeTextFile_" }); - const testFile = join(tempDirPath, "testFile.txt"); + const tempDirPath = await makeTempDir({ prefix: "writeTextFile_" }); + const testFile = join(tempDirPath, "testFile.txt"); - const error = await assertRejects(async () => { - await writeTextFile(testFile, "Hello", { signal: ac.signal }); - }, Error); + const error = await assertRejects(async () => { + await writeTextFile(testFile, "Hello", { signal: ac.signal }); + }, Error); - if (isDeno) { - assertEquals(error, ac.signal.reason); - } else { - assertEquals(error.cause, ac.signal.reason); - } + if (isDeno) { + assertEquals(error, ac.signal.reason); + } else { + assertEquals(error.cause, ac.signal.reason); + } - await remove(tempDirPath, { recursive: true }); -}); + await remove(tempDirPath, { recursive: true }); + }, +); -Deno.test("writeTextFile() handles an AbortSignal with a primitive reason", async () => { - const ac = new AbortController(); - const reasonErr = "This is a primitive string."; - queueMicrotask(() => ac.abort(reasonErr)); +Deno.test( + "writeTextFile() handles an AbortSignal with a primitive reason", + { ignore: isBun }, + async () => { + const ac = new AbortController(); + const reasonErr = "This is a primitive string."; + queueMicrotask(() => ac.abort(reasonErr)); - const tempDirPath = await makeTempDir({ prefix: "writeTextFile_" }); - const testFile = join(tempDirPath, "testFile.txt"); + const tempDirPath = await makeTempDir({ prefix: "writeTextFile_" }); + const testFile = join(tempDirPath, "testFile.txt"); - try { - await writeTextFile(testFile, "Hello", { signal: ac.signal }); - } catch (error) { - if (isDeno) { - assertEquals(error, ac.signal.reason); - } else { - const errorValue = error as Error; - assertEquals(errorValue.cause, ac.signal.reason); + try { + await writeTextFile(testFile, "Hello", { signal: ac.signal }); + } catch (error) { + if (isDeno) { + assertEquals(error, ac.signal.reason); + } else { + const errorValue = error as Error; + assertEquals(errorValue.cause, ac.signal.reason); + } } - } - await remove(tempDirPath, { recursive: true }); -}); + await remove(tempDirPath, { recursive: true }); + }, +); Deno.test("writeTextFile() writes to a file successfully with an attached AbortSignal", async () => { const ac = new AbortController();