yamatatsu / vitest-dynamodb-lite

vitest-dynamodb-lite
https://www.npmjs.com/package/vitest-dynamodb-lite
3 stars 2 forks source link

Doesn't work with singleThread or singleFork #16

Open danielholmes opened 1 month ago

danielholmes commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce

See for a full reproduction: https://github.com/danielholmes/vitest-dynamodb-lite-threads-bug

Steps to reproduce the behavior in repo:

  1. clone repo
  2. npm ci
  3. npm run test:all:fail

General steps to reproduce the behavior:

  1. Create a vite config with pool: "threads" or pool: "forks" and singleThread: true or singleFork: true
  2. Have more than 1 test
  3. Run all tests (npx vitest run)

Expected behavior vitest-dynamodb-lite should run its beforeAll and afterAll for each test context, not just the first one.

Desktop (please complete the following information):

Additional context This appears to be because of node's module caching. i.e. on the first test the beforeAll and afterAll from vitest-dynamodb-lite are run, but on second, third, etc tests they aren't.

You can work around this by dynamically importing with a cache busting query string. e.g. see https://github.com/danielholmes/vitest-dynamodb-lite-threads-bug/blob/main/src/setup-tests-success.js#L2 . One solution is for vitest to not use module cache for node_modules setupFiles (they already seem to not use the cache for in project setupFiles ). However I'm not sure if that would have some other implications. In