Skip to content

Commit 734363d

Browse files
committed
Bun tests
1 parent 768f523 commit 734363d

11 files changed

Lines changed: 137 additions & 38 deletions

File tree

.github/workflows/build.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ jobs:
6767
- run: deno task test:node
6868
working-directory: ${{ github.workspace }}/fedify/
6969

70+
test-bun:
71+
strategy:
72+
matrix:
73+
os: [macos-latest, ubuntu-latest, windows-latest]
74+
fail-fast: false
75+
runs-on: ${{ matrix.os }}
76+
steps:
77+
- uses: actions/checkout@v4
78+
- uses: denoland/setup-deno@v2
79+
with:
80+
deno-version: v2.x
81+
- uses: actions/setup-node@v4
82+
with:
83+
node-version: lts/*
84+
- uses: oven-sh/setup-bun@v1
85+
with:
86+
bun-version: latest
87+
- uses: pnpm/action-setup@v4
88+
with:
89+
version: 10
90+
- run: deno task test:bun
91+
working-directory: ${{ github.workspace }}/fedify/
92+
7093
lint:
7194
runs-on: ubuntu-latest
7295
steps:
@@ -106,7 +129,7 @@ jobs:
106129
working-directory: ${{ github.workspace }}/cli/
107130

108131
publish:
109-
needs: [test, test-node, lint, release-test]
132+
needs: [test, test-node, test-bun, lint, release-test]
110133
runs-on: ubuntu-latest
111134
permissions:
112135
id-token: write

fedify/codegen/__snapshots__/class.test.ts.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15638,7 +15638,6 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi
1563815638
if (\\"publicKey\\" in values && values.publicKey != null) {
1563915639
if (
1564015640
// @ts-ignore: CryptoKey exists in the global scope.
15641-
// dnt-shim-ignore
1564215641
values.publicKey instanceof CryptoKey
1564315642
) {
1564415643
// @ts-ignore: type is checked above.
@@ -15700,7 +15699,6 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi
1570015699
if (\\"publicKey\\" in values && values.publicKey != null) {
1570115700
if (
1570215701
// @ts-ignore: CryptoKey exists in the global scope.
15703-
// dnt-shim-ignore
1570415702
values.publicKey instanceof CryptoKey
1570515703
) {
1570615704
// @ts-ignore: type is checked above.
@@ -16429,7 +16427,6 @@ controller?: Application | Group | Organization | Person | Service | URL | null;
1642916427
if (\\"publicKey\\" in values && values.publicKey != null) {
1643016428
if (
1643116429
// @ts-ignore: CryptoKey exists in the global scope.
16432-
// dnt-shim-ignore
1643316430
values.publicKey instanceof CryptoKey
1643416431
) {
1643516432
// @ts-ignore: type is checked above.
@@ -16491,7 +16488,6 @@ controller?: Application | Group | Organization | Person | Service | URL | null;
1649116488
if (\\"publicKey\\" in values && values.publicKey != null) {
1649216489
if (
1649316490
// @ts-ignore: CryptoKey exists in the global scope.
16494-
// dnt-shim-ignore
1649516491
values.publicKey instanceof CryptoKey
1649616492
) {
1649716493
// @ts-ignore: type is checked above.

fedify/codegen/type.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ const scalarTypes: Record<string, ScalarType> = {
305305
typeGuard(v) {
306306
return `
307307
// @ts-ignore: CryptoKey exists in the global scope.
308-
// dnt-shim-ignore
309308
${v} instanceof CryptoKey
310309
`;
311310
},
@@ -328,7 +327,6 @@ const scalarTypes: Record<string, ScalarType> = {
328327
typeGuard(v) {
329328
return `
330329
// @ts-ignore: CryptoKey exists in the global scope.
331-
// dnt-shim-ignore
332330
${v} instanceof CryptoKey
333331
`;
334332
},

fedify/deno.json

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,38 @@
9797
"codegen"
9898
]
9999
},
100-
"npm": "pnpm install && pnpm pack",
101-
"test:node": "pnpm install && pnpm test",
100+
"pnpm:install": "pnpm install",
101+
"pnpm:build": {
102+
"command": "pnpm exec tsdown",
103+
"dependencies": [
104+
"codegen",
105+
"pnpm:install"
106+
]
107+
},
108+
"npm": {
109+
"command": "pnpm pack",
110+
"dependencies": [
111+
"pnpm:install"
112+
]
113+
},
114+
"test:node": {
115+
"command": "cd dist/ && node --test",
116+
"dependencies": [
117+
"pnpm:build"
118+
]
119+
},
120+
"test:bun": {
121+
"command": "cd dist/ && bun test",
122+
"dependencies": [
123+
"pnpm:build"
124+
]
125+
},
102126
"test-all": {
103127
"dependencies": [
104128
"check",
105129
"test",
106-
"test:node"
130+
"test:node",
131+
"test:bun"
107132
]
108133
}
109134
}

fedify/federation/mq.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,14 @@ const queues: Record<string, () => Promise<MessageQueue>> = {
9999
};
100100
if (
101101
// @ts-ignore: Works on Deno
102-
// dnt-shim-ignore
103102
"Deno" in globalThis && "openKv" in globalThis.Deno &&
104103
// @ts-ignore: Works on Deno
105-
// dnt-shim-ignore
106104
typeof globalThis.Deno.openKv === "function"
107105
) {
108106
const { DenoKvMessageQueue } = await import(".." + "/x/denokv.ts");
109107
queues.DenoKvMessageQueue = async () =>
110108
new DenoKvMessageQueue(
111109
// @ts-ignore: Works on Deno
112-
// dnt-shim-ignore
113110
await globalThis.Deno.openKv(":memory:"),
114111
);
115112
}

fedify/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
"@opentelemetry/api": "^1.9.0",
8888
"@opentelemetry/semantic-conventions": "^1.27.0",
8989
"@phensley/language-tag": "^1.9.0",
90-
"@types/bun": "^1.2.14",
9190
"asn1js": "^3.0.5",
9291
"byte-encodings": "^1.0.11",
9392
"json-canon": "^1.0.1",
@@ -114,6 +113,7 @@
114113
"build": "deno task codegen && tsdown",
115114
"prepack": "deno task codegen && tsdown",
116115
"prepublish": "deno task codegen && tsdown",
117-
"test": "deno task codegen && tsdown && cd dist/ && node --test"
116+
"test": "deno task codegen && tsdown && cd dist/ && node --test",
117+
"test:bun": "deno task codegen && tsdown && cd dist/ && bun test"
118118
}
119119
}

fedify/pnpm-lock.yaml

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fedify/runtime/docloader.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ test("kvCache()", async (t) => {
543543
});
544544

545545
test("getUserAgent()", () => {
546-
// dnt-shim-ignore
547546
if ("Deno" in globalThis) {
548547
assertEquals(
549548
getUserAgent(),
@@ -564,8 +563,7 @@ test("getUserAgent()", () => {
564563
}),
565564
`MyApp/1.0.0 (Fedify/${metadata.version}; Deno/${Deno.version.deno}; +https://example.com/)`,
566565
);
567-
} // dnt-shim-ignore
568-
else if ("Bun" in globalThis) {
566+
} else if ("Bun" in globalThis) {
569567
assertEquals(
570568
getUserAgent(),
571569
// @ts-ignore: `Bun` is a global variable in Bun

fedify/runtime/docloader.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,13 @@ export function getUserAgent(
513513
{ software, url }: GetUserAgentOptions = {},
514514
): string {
515515
const fedify = `Fedify/${metadata.version}`;
516-
const runtime = // dnt-shim-ignore
516+
const runtime =
517517
// deno-lint-ignore no-explicit-any
518518
(globalThis as any).Deno?.version?.deno != null
519519
? `Deno/${Deno.version.deno}`
520-
// dnt-shim-ignore
521520
// deno-lint-ignore no-explicit-any
522521
: (globalThis as any).process?.versions?.bun != null
523522
? `Bun/${process.versions.bun}`
524-
// dnt-shim-ignore
525523
// deno-lint-ignore no-explicit-any
526524
: (globalThis as any).process?.versions?.node != null
527525
? `Node.js/${process.versions.node}`

fedify/testing/mod.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,63 @@ export function test(
6868
}
6969
},
7070
});
71+
} else if ("Bun" in globalThis) {
72+
let failed: unknown = undefined;
73+
// deno-lint-ignore no-inner-declarations
74+
function step(def: Deno.TestStepDefinition): Promise<boolean>;
75+
// deno-lint-ignore no-inner-declarations
76+
function step(
77+
name: string,
78+
fn: (ctx: Deno.TestContext) => void | Promise<void>,
79+
): Promise<boolean>;
80+
// deno-lint-ignore no-inner-declarations
81+
function step(
82+
fn: (ctx: Deno.TestContext) => void | Promise<void>,
83+
): Promise<boolean>;
84+
// deno-lint-ignore no-inner-declarations
85+
async function step(
86+
defOrNameOrFn:
87+
| Deno.TestStepDefinition
88+
| string
89+
| ((ctx: Deno.TestContext) => void | Promise<void>),
90+
fn?: (ctx: Deno.TestContext) => void | Promise<void>,
91+
): Promise<boolean> {
92+
let def: Deno.TestStepDefinition;
93+
if (typeof defOrNameOrFn === "string") {
94+
def = { name: defOrNameOrFn, fn: fn! };
95+
} else if (typeof defOrNameOrFn === "function") {
96+
def = { name: defOrNameOrFn.name, fn: defOrNameOrFn };
97+
} else {
98+
def = defOrNameOrFn;
99+
}
100+
if (def.ignore) return true;
101+
try {
102+
await def.fn({
103+
name: def.name,
104+
origin: "",
105+
step,
106+
});
107+
} catch (e) {
108+
failed ??= e;
109+
return false;
110+
}
111+
return true;
112+
}
113+
const ctx: Deno.TestContext = {
114+
name: def.name,
115+
origin: "",
116+
step,
117+
};
118+
// deno-lint-ignore no-inner-declarations
119+
async function fn() {
120+
await def.fn(ctx);
121+
if (failed) throw failed;
122+
}
123+
// @ts-ignore: Bun exists in the global scope in Bun
124+
const bunTest = Bun.jest(caller()).test;
125+
if (def.ignore) bunTest.skip(def.name, fn);
126+
else if (def.only) bunTest.only(def.name, fn);
127+
else bunTest(def.name, fn);
71128
} else {
72129
nodeTest(def.name, { only: def.only, skip: def.ignore }, async (t) => {
73130
await def.fn(intoDenoTestContext(def.name, t));
@@ -120,3 +177,21 @@ function intoDenoTestContext(
120177
};
121178
return denoCtx;
122179
}
180+
181+
// Below code is borrowed from https://github.com/oven-sh/bun/issues/11660#issuecomment-2506832106
182+
183+
/** Retrieve caller test file. */
184+
function caller() {
185+
const Trace = Error as unknown as {
186+
prepareStackTrace: (error: Error, stack: CallSite[]) => unknown;
187+
};
188+
const _ = Trace.prepareStackTrace;
189+
Trace.prepareStackTrace = (_, stack) => stack;
190+
const { stack } = new Error();
191+
Trace.prepareStackTrace = _;
192+
const caller = (stack as unknown as CallSite[])[2];
193+
return caller.getFileName().replaceAll("\\", "/");
194+
}
195+
196+
/** V8 CallSite (subset). */
197+
type CallSite = { getFileName: () => string };

0 commit comments

Comments
 (0)