Create a vite config with pool: "threads" or pool: "forks" and singleThread: true or singleFork: true
Have more than 1 test
Run all tests (npx vitest run)
Expected behaviorvitest-dynamodb-lite should run its beforeAll and afterAll for each test context, not just the first one.
Desktop (please complete the following information):
OS: Mac OS, Ubuntu
Browser: N/A - Node 20.14.0
Version: 3.1.1
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.
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:
npm ci
npm run test:all:fail
General steps to reproduce the behavior:
pool: "threads"
orpool: "forks"
andsingleThread: true
orsingleFork: true
npx vitest run
)Expected behavior
vitest-dynamodb-lite
should run itsbeforeAll
andafterAll
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 projectsetupFiles
). However I'm not sure if that would have some other implications. In