oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.24k stars 2.77k forks source link

`bun test` with Astro `experimental_AstroContainer` incompatible with Node #13933

Closed aboqasem closed 1 month ago

aboqasem commented 2 months ago

What version of Bun is running?

1.1.27+267afa293

What platform is your computer?

Darwin 23.6.0 x86_64 i38 OR Linux 6.1.43 x86_64 unknown

What steps can reproduce the bug?

  1. Test file
    
    import { experimental_AstroContainer as AstroContainer } from "astro/container";
    import { expect, test } from "vitest"; // same result with `bun:test`
    import Index from "./index.astro";

const runner = typeof Bun === "undefined" ? "Node" : "Bun";

test(Running with ${runner}, async () => { const container = await AstroContainer.create(); const result = await container.renderToString(Index);

expect(result).toContain("Bun Test?"); });


2. Run
```log
➜ bunx vitest run

 RUN  v2.1.0 /project/workspace

 ✓ src/pages/index.test.ts (1)
   ✓ Running with Node

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  23:28:02
   Duration  1.41s (transform 635ms, setup 0ms, collect 1.14s, tests 59ms, environment 0ms, prepare 58ms)
➜ bun test       
bun test v1.1.27 (267afa29)

src/pages/index.test.ts:
 6 | 
 7 | test(`Running with ${runner}`, async () => {
 8 |   const container = await AstroContainer.create();
 9 |   const result = await container.renderToString(Index);
10 | 
11 |   expect(result).toContain("Bun Test?");
                      ^
error: expect(received).toContain(expected)

Expected to contain: "Bun Test?"
Received: "<!DOCTYPE html></project/workspace/src/pages/index.astro server:root=\"true\"><//project/workspace/src/pages/index.astro>"

      at /project/workspace/src/pages/index.test.ts:11:18
✗ Running with Bun [13.93ms]

 0 pass
 1 fail
 1 expect() calls
Ran 1 tests across 1 files. [345.00ms]

What is the expected behavior?

bun test to work at least when importing bun:test.

What do you see instead?

See above.

Additional information

Codesandbox: https://codesandbox.io/p/devbox/bun-test-astro-container-bug-g4hgsp?file=%2Fsrc%2Fpages%2Findex.test.ts

Jarred-Sumner commented 1 month ago

Thanks for the reproduction

The issue is that there is no loader for .astro files configured for Bun. It only is configured for Vitest. We don't have the engineering resources to implement Vitest plugin support in Bun - you can ask Astro if they want to do an equivalent of their Vitest plugin for bun test. It's probably very similar.