Skip to content

revosw/vitest-mms-repro

Repository files navigation

This repo demonstrates the problem with running vitest in --no-threads mode, using mongoose and mongodb-memory-server.

Reproduction

  1. git clone https://github.com/revosw/vitest-mms-repro.git
  2. pnpm i
  3. pnpm exec vitest --no-threads run

The problem arises when there are two tests importing the same model.

 FAIL  test1.test.ts [ test1.test.ts ]
OverwriteModelError: Cannot overwrite `user` model once compiled.
 ❯ Mongoose.model node_modules/.pnpm/[email protected]/node_modules/mongoose/lib/index.js:563:13
 ❯ model.ts:22:31
     20| 
     21| // Create the User model using the schema
     22| export const model = mongoose.model('user', schema);
       |                               ^
     23| 
 ❯ test1.test.ts:1:31

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

 Test Files  1 failed | 1 passed (2)
      Tests  1 passed (1)
   Start at  23:50:08
   Duration  2.13s (transform 30ms, setup 450ms, collect 20ms, tests 1.36s, environment 0ms, prepare 124ms)

Running the same tests without --no-threads works fine.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published