FredKSchott / snowpack

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️
https://www.snowpack.dev
MIT License
19.48k stars 922 forks source link

🐛 BUG: web test runner plugin 'Failed to dynamically import module' when tests are not in src directory #3796

Open PindaPixel opened 3 years ago

PindaPixel commented 3 years ago

Quick checklist

What package manager are you using?

yarn berry

What operating system are you using?

Windows

Describe the bug

I cannot get web-test-runner to get to work and I'm not sure where the fault lies. I've seen issues with the same error in the web-test-runner repo, but those are supposedly fixed.

Steps to reproduce

  1. yarn create snowpack-app using template @snowpack/react-typescript
  2. yarn set version berry -> delete node_modules -> yarn install
  3. Change the test script in package.json from web-test-runner \"src/**/*.test.tsx\" to web-test-runner \"tests/**/*.test.{ts,tsx}\"
  4. For vscode:
    • yarn dlx @yarnpkg/sdks vscode
    • Command pallet: TypeScript: Select TypeScript version -> use workspace version.
  5. Create a test:
    
    // tests/test.test.tsx
    import { assert } from 'chai';

describe('Test test', () => { it('Does a test!', () => { assert.equal(1, 1); }); });

6. yarn test
7. This should happen:

$ yarn test [snowpack] starting server... [12:55:54] [snowpack] Ready! [12:55:54] [snowpack] Server started in 33ms. [12:55:54] [snowpack] Local: http://localhost:8080 [12:55:54] [snowpack] Network: http://...:8080

[12:55:54] [snowpack] watching for file changes... [12:55:55] [@snowpack/plugin-typescript] [12:55:55] [@snowpack/plugin-typescript] 11:54:55 AM - Starting compilation in watch mode... tests\test.test.tsx:

🚧 Browser logs: TypeError: Failed to fetch dynamically imported module: http://localhost:8000/tests/test.test.tsx?wtr-session-id=v7oWSrQQbvgJFuIoqzsJT

❌ Could not import your test module. Check the browser logs or open the browser in debug mode for more information.

Chrome: |██████████████████████████████| 1/1 test files | 0 passed, 0 failed

Error while running tests.



### Link to minimal reproducible example (optional)

_No response_
cmditch commented 2 years ago

I'm intermittently seeing this error as well. Mostly in CI, not locally. It's totally intermittent though, afaikt.

TetianaZa commented 2 years ago

I got the same error :( Good to have it fixed

prashantpalikhe commented 1 year ago

Also, getting the same error. Fresh install, simple test case like the OP.

trusktr commented 1 year ago

This looks like it may be a @web/test-runner issue. Posted there:

https://github.com/modernweb-dev/web/issues/2286