Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waku processes .test.ts files during development, causing issues with bun:test #1264

Open
mrsekut opened this issue Feb 24, 2025 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@mrsekut
Copy link

mrsekut commented Feb 24, 2025

Description

While using waku with bun, I noticed that .test.ts files are being processed when running bun run dev. This leads to an error if the test files use bun:test, as Vite attempts to resolve it during import analysis.

However, test files are typically not needed during runtime and should not be loaded in the first place. This behavior suggests that vite is unintentionally including .test.ts files when resolving dependencies.

This is not a critical issue, as switching from bun:test to vitest resolves the problem. I wanted to share this behavior in case it is unintended and might be worth addressing.


Steps to Reproduce

  1. In a waku + bun project, create a test file (e.g., sample.test.ts):
    import { expect, test } from 'bun:test';
    
    test('sample test', async () => {
      expect(1).toBe(1);
    });
  2. Run:
    bun run dev
    
  3. The following error occurs:
    Error: Failed to resolve import "bun:test" from "src/sample.test.ts". Does the file exist?
    

Expected Behavior

  • .test.ts files should not be processed during development server startup, as they are only needed in test environments.
  • vite should not attempt to resolve bun:test during the import-analysis phase.

Possible Causes

  • vite's optimizeDeps.entries might be unintentionally including .test.ts files.
  • The processModule function in dev-server-impl.js could be processing .test.ts files when it shouldn't.
  • The willBeHandled logic might not be properly filtering out .test.ts files.

Additional Notes

  • Switching to vitest instead of bun:test resolved the issue, so this is not blocking my work.
  • This issue may not affect many users, but I wanted to share it in case it's an unintended behavior that could be improved.

Let me know if you need any more details. Thanks!

@dai-shi
Copy link
Owner

dai-shi commented Feb 24, 2025

Thanks for reporting! The possible causes sound like a good hint.
I'm interested in what the root cause is.

Would anyone like to dig into it?

@dai-shi dai-shi added the help wanted Extra attention is needed label Feb 25, 2025
@hamlim
Copy link
Contributor

hamlim commented Feb 25, 2025

I might be able to take a look at this sometime this week!

@hamlim
Copy link
Contributor

hamlim commented Feb 25, 2025

Oddly, I don't see this error:

Error: Failed to resolve import "bun:test" from "src/sample.test.ts". Does the file exist?

When trying to replicate this issue.

I created a reproduction repo here: https://github.com/hamlim/waku-bun-test-bug-reproduction

The app seemed to work fine in dev mode when the test file was only within src, moving it into src/pages seemed to throw an error when loading the app however.

@mrsekut could you possibly create a simplified reproduction and share it? (or see what might be different between mine linked above and yours?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants