Describe the bug
After updating Vitest from 4.0.18 to 4.1.0, importOriginal from vi.mock is empty when using resetModules and isolate: false.
I run my tests with maxWorkers: 1, isolate: false, and vi.resetModules(); in a beforeEach. When using importOriginal from vi.mock in setupTests.js, the first test suite runs successfully. However, the second test throws this error:
No "connect" export is defined on the "react-redux" mock. Did you forget to return it from "vi.mock"?
If you need to partially mock a module, you can use "importOriginal" helper inside:
When logging original, the first test suite logs all exports from react-redux, but the second suite logs this instead:
[Object: null prototype] [Module] {}
Reproduction
// vitest.config.js
export default defineConfig({
test: {
setupFiles: ['./setupTests.js'],
maxWorkers: 1,
isolate: false,
},
})
// setupTests.js
vi.mock('react-redux', async (importOriginal) => {
const original = await importOriginal();
return {
...original,
useSelector: (callback) => callback(),
useDispatch: () => (callback) => callback(),
};
});
beforeEach(() => {
vi.resetModules();
});
Here is a StackBlitz example, with Lodash instead of react-redux:
https://stackblitz.com/edit/vitest-dev-vitest-z5dhbqpm?file=package.json&view=editor
System Info
Used Package Manager
npm
Validations
Describe the bug
After updating Vitest from 4.0.18 to 4.1.0,
importOriginalfromvi.mockis empty when usingresetModulesandisolate: false.I run my tests with
maxWorkers: 1,isolate: false, andvi.resetModules();in abeforeEach. When usingimportOriginalfromvi.mockinsetupTests.js, the first test suite runs successfully. However, the second test throws this error:When logging
original, the first test suite logs all exports fromreact-redux, but the second suite logs this instead:Reproduction
Here is a StackBlitz example, with Lodash instead of react-redux:
https://stackblitz.com/edit/vitest-dev-vitest-z5dhbqpm?file=package.json&view=editor
System Info
Used Package Manager
npm
Validations