Open ChqThomas opened 1 year ago
It's a bummer that this doesn't work yet, as it prevents Bun from working with (many) SvelteKit projects.
@Jarred-Sumner Is there already a way to define or mock an import for Bun?
For example, it would be sufficient if import { dev } from '$app/environment';
returned a pre-defined constant (false
or true
).
@Dan1ve here are three ways this can be addressed:
1) mock.module
in bun:test
2) virtual modules in Bun.plugin
3) tsconfig.json paths
(probably), which Bun also supports
Thanks a lot! I think this should work:
bunfig.toml
[test]
preload = ['./bun-test-plugins.ts']
bun-test-plugins.ts
import { plugin } from "bun";
plugin({
name: "sveltekit-env",
setup(build) {
build.module("$app/environment", () => {
return {
exports: {
dev: false,
},
loader: "object",
};
});
},
});
Now the only remaining problem is that the test runner runs into a segmentation fault, but this is probably unrelated :grin:
What version of Bun is running?
1.0.2+37edd5a6e389265738e89265bcbdf2999cb81a49
What platform is your computer?
Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 x86_64
What steps can reproduce the bug?
If one of your tests imports a
$app/xxx
module from SvelteKit, thebun test
command cannot find it.Follow this steps:
bun create svelte@latest my-app
cd my-app
bun install
edit
src/index.test.js
run
bun test
What is the expected behavior?
What do you see instead?
Additional information
The issue is the same with all SvelteKit "$app/xxxx" modules: https://kit.svelte.dev/docs/modules
The same code works with Vitest: