#3796·snowpack

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

Author: PindaPixelCreated Oct 30, 2021Updated May 27, 2023

Quick checklist

  • I am using the latest version of Snowpack and all plugins.

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:
typescript
// tests/test.test.tsx
import { assert } from 'chai';

describe('Test test', () => {
    it('Does a test!', () => {
        assert.equal(1, 1);
    });
});
  1. yarn test
  2. 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