Skip to content

Commit d9df5c7

Browse files
authored
chore: run some test cases in bun in CI (#6635)
1 parent bfd0096 commit d9df5c7

15 files changed

+389
-252
lines changed

.github/workflows/ci.yml

+26
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,32 @@ jobs:
102102
- name: Run tests
103103
run: deno task test:node
104104

105+
test-bun:
106+
runs-on: ${{ matrix.os }}
107+
timeout-minutes: 30
108+
strategy:
109+
fail-fast: false
110+
matrix:
111+
bun:
112+
- latest
113+
os:
114+
- ubuntu-latest
115+
116+
steps:
117+
- name: Clone repository
118+
uses: actions/checkout@v4
119+
120+
- name: Set up Deno
121+
uses: denoland/setup-deno@v2
122+
123+
- name: Set up Bun
124+
uses: oven-sh/setup-bun@v2
125+
with:
126+
bun-version: ${{ matrix.node }}
127+
128+
- name: Run tests
129+
run: deno task test:bun
130+
105131
lint:
106132
runs-on: ${{ matrix.os }}
107133
timeout-minutes: 30

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ coverage/
1717
.vim
1818
_tmp/
1919
!_tmp/.keep
20+
21+
# tsconfig for bun
22+
/tsconfig.json

_tools/node_test_runner/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
package-lock.json
3+
bun.lock

_tools/node_test_runner/run_test.mjs

+5-1
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,9 @@ import "../../fs/unstable_umask_test.ts";
7575
import "../../fs/unstable_utime_test.ts";
7676

7777
for (const testDef of testDefinitions) {
78-
test(testDef.name, testDef.fn);
78+
if (testDef.ignore) {
79+
test.skip(testDef.name, testDef.fn);
80+
} else {
81+
test(testDef.name, testDef.fn);
82+
}
7983
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"paths": {
4+
"@std/assert": ["./assert/mod.ts"],
5+
"@std/assert/greater-or-equal": ["./assert/greater_or_equal.ts"],
6+
"@std/path": ["./path/mod.ts"],
7+
"@std/internal/format": ["./internal/format.ts"],
8+
"@std/internal/styles": ["./internal/styles.ts"],
9+
"@std/internal/build-message": ["./internal/build_message.ts"],
10+
"@std/internal/diff": ["./internal/diff.ts"],
11+
"@std/internal/diff-str": ["./internal/diff_str.ts"],
12+
"@std/semver": ["./semver/mod.ts"],
13+
}
14+
}
15+
}

collections/invert_test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Deno.test("invert() handles nested input", () => {
2929
// @ts-expect-error - testing invalid input
3030
invertTest({ a: "x", b: Object }, {
3131
"x": "a",
32-
"function Object() { [native code] }": "b",
32+
[Object.toString()]: "b",
3333
});
3434
// @ts-expect-error - testing invalid input
3535
invertTest({ a: "x", b: ["y", "z"] }, { "x": "a", "y,z": "b" });

deno.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"test:with-unsafe-proto": "deno test --unstable-http --unstable-webgpu --unstable-fs --unstable-unsafe-proto --doc --allow-all --parallel --coverage --trace-leaks --clean",
1313
"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",
1414
"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",
15+
"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",
1516
"fmt:licence-headers": "deno run --allow-read --allow-write ./_tools/check_licence.ts",
1617
"lint:circular": "deno run --allow-env --allow-read --allow-write --allow-net=deno.land,jsr.io ./_tools/check_circular_package_dependencies.ts",
1718
"lint:mod-exports": "deno run --allow-env --allow-read ./_tools/check_mod_exports.ts",

fs/_node_fs_file_test.ts

+65-52
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { fileURLToPath } from "node:url";
1313
const moduleDir = dirname(fileURLToPath(import.meta.url));
1414
const testdataDir = resolve(moduleDir, "testdata");
1515
const readTestFile = join(testdataDir, "copy_file.txt");
16+
const isBun = navigator.userAgent.includes("Bun/");
1617

1718
Deno.test("FsFile object writes to a newly created file", async () => {
1819
const tempDirPath = await makeTempDir({ prefix: "FsFile_write_" });
@@ -126,39 +127,47 @@ Deno.test("FsFile object returns the 'stat' of the file handle", async () => {
126127
fh.close();
127128
});
128129

129-
Deno.test("FsFile object handles a ReadableStream", async () => {
130-
const fh = await open(readTestFile);
131-
assert(fh.readable instanceof ReadableStream);
132-
const chunks = [];
133-
for await (const chunk of fh.readable) {
134-
chunks.push(chunk);
135-
}
136-
assertEquals(chunks.length, 1);
137-
if (chunks[0] != null) {
138-
assertEquals(chunks[0].byteLength, 3);
139-
}
140-
});
141-
142-
Deno.test("FsFile object handles a WritableStream", async () => {
143-
const tempDirPath = await makeTempDir({ prefix: "FsFile_WritableStream_" });
144-
const testFile = join(tempDirPath, "testFile.txt");
145-
const fh = await open(testFile, { create: true, write: true });
146-
assert(fh.writable instanceof WritableStream);
147-
const rs = new ReadableStream({
148-
start(controller) {
149-
const encoder = new TextEncoder();
150-
controller.enqueue(encoder.encode("Hello,"));
151-
controller.enqueue(encoder.encode(" Standard"));
152-
controller.enqueue(encoder.encode(" Library"));
153-
controller.close();
154-
},
155-
});
156-
await rs.pipeTo(fh.writable);
157-
const readText = await readTextFile(testFile);
158-
assertEquals(readText, "Hello, Standard Library");
159-
160-
await remove(tempDirPath, { recursive: true });
161-
});
130+
Deno.test(
131+
"FsFile object handles a ReadableStream",
132+
{ ignore: isBun },
133+
async () => {
134+
const fh = await open(readTestFile);
135+
assert(fh.readable instanceof ReadableStream);
136+
const chunks = [];
137+
for await (const chunk of fh.readable) {
138+
chunks.push(chunk);
139+
}
140+
assertEquals(chunks.length, 1);
141+
if (chunks[0] != null) {
142+
assertEquals(chunks[0].byteLength, 3);
143+
}
144+
},
145+
);
146+
147+
Deno.test(
148+
"FsFile object handles a WritableStream",
149+
{ ignore: isBun },
150+
async () => {
151+
const tempDirPath = await makeTempDir({ prefix: "FsFile_WritableStream_" });
152+
const testFile = join(tempDirPath, "testFile.txt");
153+
const fh = await open(testFile, { create: true, write: true });
154+
assert(fh.writable instanceof WritableStream);
155+
const rs = new ReadableStream({
156+
start(controller) {
157+
const encoder = new TextEncoder();
158+
controller.enqueue(encoder.encode("Hello,"));
159+
controller.enqueue(encoder.encode(" Standard"));
160+
controller.enqueue(encoder.encode(" Library"));
161+
controller.close();
162+
},
163+
});
164+
await rs.pipeTo(fh.writable);
165+
const readText = await readTextFile(testFile);
166+
assertEquals(readText, "Hello, Standard Library");
167+
168+
await remove(tempDirPath, { recursive: true });
169+
},
170+
);
162171

163172
Deno.test("FsFile object changes access and modification times with utime", async () => {
164173
const tempFile = await makeTempFile({ prefix: "FsFile_utime_" });
@@ -232,28 +241,32 @@ Deno.test("FsFile object synchronously reads from an existing file", () => {
232241
fh.close();
233242
});
234243

235-
Deno.test("FsFile object synchronously truncates a file to zero", () => {
236-
const tempDirPath = makeTempDirSync({ prefix: "FsFile_truncateSync_" });
237-
const testFile = join(tempDirPath, "testFile.txt");
238-
let fh = openSync(testFile, { read: true, write: true, create: true });
239-
240-
const encoder = new TextEncoder();
241-
const data = encoder.encode("Hello, Standard Library");
242-
const writeBytes = fh.writeSync(data);
243-
assertEquals(writeBytes, 23);
244-
fh.close();
244+
Deno.test(
245+
"FsFile object synchronously truncates a file to zero",
246+
{ ignore: isBun },
247+
() => {
248+
const tempDirPath = makeTempDirSync({ prefix: "FsFile_truncateSync_" });
249+
const testFile = join(tempDirPath, "testFile.txt");
250+
let fh = openSync(testFile, { read: true, write: true, create: true });
251+
252+
const encoder = new TextEncoder();
253+
const data = encoder.encode("Hello, Standard Library");
254+
const writeBytes = fh.writeSync(data);
255+
assertEquals(writeBytes, 23);
256+
fh.close();
245257

246-
fh = openSync(testFile, { read: true, write: true });
247-
fh.truncateSync();
258+
fh = openSync(testFile, { read: true, write: true });
259+
fh.truncateSync();
248260

249-
const buf = new Uint8Array(10);
250-
const readBytes = fh.readSync(buf);
251-
// Reading a 0 byte file should return null at EOF.
252-
assertEquals(readBytes, null);
253-
fh.close();
261+
const buf = new Uint8Array(10);
262+
const readBytes = fh.readSync(buf);
263+
// Reading a 0 byte file should return null at EOF.
264+
assertEquals(readBytes, null);
265+
fh.close();
254266

255-
removeSync(tempDirPath, { recursive: true });
256-
});
267+
removeSync(tempDirPath, { recursive: true });
268+
},
269+
);
257270

258271
Deno.test("FsFile object synchronously truncates files to multiple sizes", () => {
259272
const tempDirPath = makeTempDirSync({ prefix: "FsFile_truncateSync_" });

fs/unstable_chown_test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { remove, removeSync } from "./unstable_remove.ts";
88
import { platform } from "node:os";
99
import { spawn } from "node:child_process";
1010

11+
const isBun = navigator.userAgent.includes("Bun/");
12+
1113
type IdResult = {
1214
id: string;
1315
code: number;
@@ -64,7 +66,7 @@ async function getUidAndGid(): Promise<{ uid: number; gid: number }> {
6466

6567
Deno.test({
6668
name: "chown() changes user and group ids",
67-
ignore: platform() === "win32",
69+
ignore: platform() === "win32" || isBun,
6870
fn: async () => {
6971
const { uid, gid } = await getUidAndGid();
7072
const tempFile = await makeTempFile({ prefix: "chown_" });
@@ -78,7 +80,7 @@ Deno.test({
7880

7981
Deno.test({
8082
name: "chown() handles `null` id arguments",
81-
ignore: platform() === "win32",
83+
ignore: platform() === "win32" || isBun,
8284
fn: async () => {
8385
const { uid, gid } = await getUidAndGid();
8486
const tempFile = await makeTempFile({ prefix: "chown_" });
@@ -115,7 +117,7 @@ Deno.test({
115117

116118
Deno.test({
117119
name: "chownSync() changes user and group ids",
118-
ignore: platform() === "win32",
120+
ignore: platform() === "win32" || isBun,
119121
fn: async () => {
120122
const { uid, gid } = await getUidAndGid();
121123
const tempFile = makeTempFileSync({ prefix: "chownSync_ " });
@@ -130,7 +132,7 @@ Deno.test({
130132

131133
Deno.test({
132134
name: "chownSync() handles `null` id arguments",
133-
ignore: platform() === "win32",
135+
ignore: platform() === "win32" || isBun,
134136
fn: async () => {
135137
const { uid, gid } = await getUidAndGid();
136138
const tempFile = makeTempFileSync({ prefix: "chownSync_" });

fs/unstable_read_file_test.ts

+37-27
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { isDeno } from "./_utils.ts";
1313
import { dirname, join, resolve } from "node:path";
1414
import { fileURLToPath } from "node:url";
1515

16+
const isBun = navigator.userAgent.includes("Bun/");
17+
1618
const moduleDir = dirname(fileURLToPath(import.meta.url));
1719
const testdataDir = resolve(moduleDir, "testdata");
1820
const testFile = join(testdataDir, "copy_file.txt");
@@ -47,39 +49,47 @@ Deno.test("readFile() handles an AbortSignal", async () => {
4749
assertEquals(error.name, "AbortError");
4850
});
4951

50-
Deno.test("readFile() handles an AbortSignal with a reason", async () => {
51-
const ac = new AbortController();
52-
const reasonErr = new Error();
53-
queueMicrotask(() => ac.abort(reasonErr));
54-
55-
const error = await assertRejects(async () => {
56-
await readFile(testFile, { signal: ac.signal });
57-
}, Error);
58-
59-
if (isDeno) {
60-
assertEquals(error, ac.signal.reason);
61-
} else {
62-
assertEquals(error.cause, ac.signal.reason);
63-
}
64-
});
52+
Deno.test(
53+
"readFile() handles an AbortSignal with a reason",
54+
{ ignore: isBun },
55+
async () => {
56+
const ac = new AbortController();
57+
const reasonErr = new Error();
58+
queueMicrotask(() => ac.abort(reasonErr));
6559

66-
Deno.test("readFile() handles an AbortSignal with a primitive reason value", async () => {
67-
const ac = new AbortController();
68-
const reasonErr = "Some string";
69-
queueMicrotask(() => ac.abort(reasonErr));
60+
const error = await assertRejects(async () => {
61+
await readFile(testFile, { signal: ac.signal });
62+
}, Error);
7063

71-
try {
72-
await readFile(testFile, { signal: ac.signal });
73-
unreachable();
74-
} catch (error) {
7564
if (isDeno) {
7665
assertEquals(error, ac.signal.reason);
7766
} else {
78-
const errorValue = error as Error;
79-
assertEquals(errorValue.cause, ac.signal.reason);
67+
assertEquals(error.cause, ac.signal.reason);
8068
}
81-
}
82-
});
69+
},
70+
);
71+
72+
Deno.test(
73+
"readFile() handles an AbortSignal with a primitive reason value",
74+
{ ignore: isBun },
75+
async () => {
76+
const ac = new AbortController();
77+
const reasonErr = "Some string";
78+
queueMicrotask(() => ac.abort(reasonErr));
79+
80+
try {
81+
await readFile(testFile, { signal: ac.signal });
82+
unreachable();
83+
} catch (error) {
84+
if (isDeno) {
85+
assertEquals(error, ac.signal.reason);
86+
} else {
87+
const errorValue = error as Error;
88+
assertEquals(errorValue.cause, ac.signal.reason);
89+
}
90+
}
91+
},
92+
);
8393

8494
Deno.test("readFile() handles cleanup of an AbortController", async () => {
8595
const ac = new AbortController();

0 commit comments

Comments
 (0)