You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the programmatic API, the setup files are no longer reloaded between runs using browser mode. This behavior seems to have been broken since vitest 2.
Note: this behavior is vital for StrykerJS to work.
The repo has 1 test file that verifies the globalThis.id variable:
import{expect,test}from"vitest";test("global id to be 1",()=>{expect(globalThis.id).toBe("1");});test("global id to be 2",()=>{expect(globalThis.id).toBe("2");});
The main.ts file here uses createVitest to create a vitest instance and writes a setup file that switches the value of globalThis.id:
awaitfs.writeFile(setupFile,"globalThis.id = '1';");// And laterawaitfs.writeFile(setupFile,"globalThis.id = '2';");
Between it will run the vitest (and reset the context). It should log:
['global id to be 1: pass', 'global id to be 2: fail']
['global id to be 1: fail', 'global id to be 2: pass']
But it logs:
['global id to be 1: pass', 'global id to be 2: fail']
['global id to be 1: pass', 'global id to be 2: fail']
This proves the setup file isn't reloaded between runs.
Disabling browser mode will solve this
Downgrading to vitest 1 will solve this: npm i -D vitest@1 @vitest/browser@1.
I did find that you've been supporting custom commands since vite@2. I think we can leverage that instead of the file communication magic with rewriting the setup file between runs 👍
EDIT: Do we have something similar for node? To communicate between the test environment and 'the server'?
Describe the bug
When using the programmatic API, the setup files are no longer reloaded between runs using browser mode. This behavior seems to have been broken since vitest 2.
Note: this behavior is vital for StrykerJS to work.
Reproduction
See https://github.com/nicojs/vitest-browser-reload-file
The repo has 1 test file that verifies the
globalThis.id
variable:The
main.ts
file here usescreateVitest
to create a vitest instance and writes a setup file that switches the value ofglobalThis.id
:Between it will run the vitest (and reset the context). It should log:
But it logs:
This proves the setup file isn't reloaded between runs.
npm i -D vitest@1 @vitest/browser@1
.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: