vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Sometimes Vitest extension runs cached tests

Open bennycode opened this issue 1 year ago • 4 comments

Describe the bug

I've noticed that sometimes my tests fail when running them from the VS Code extension. In the screenshot below, you can see a mismatch between my actual test description ("fixes imports from index files") vs. what was run by the Vitest extension ("adds imports from barrel files", which was the previous test description). This indicates a caching problem.

Reproduction

For me this happens when I rename my test snapshot files.

Here is the testing code that I used:

describe('convertFile', () => {
  const fixtures = path.join(process.cwd(), 'src', 'test', 'fixtures');

  it('fixes imports from index files', async () => {
    const projectDir = path.join(fixtures, 'index-import');
    const projectConfig = path.join(projectDir, 'tsconfig.json');
    const snapshot = path.join(projectDir, 'main.snap.ts');
    const project = ProjectUtil.getProject(projectConfig);
    const modifiedFile = convertFile(project, project.getSourceFile('main.ts')!, true);
    await expect(modifiedFile.getText()).toMatchFileSnapshot(snapshot);
  });
});

Output

[INFO 10:47:54 AM] [v1.6.1] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[INFO 10:47:54 AM] [API] Running Vitest v2.1.3 (dist/vitest.config.js) with [email protected]: /home/bennycode/.nvm/versions/node/v20.17.0/bin/node 
[INFO 10:47:54 AM] [API] Running Vitest v2.1.3 (ts2esm/vitest.config.ts) with [email protected]: /home/bennycode/.nvm/versions/node/v20.17.0/bin/node 
[INFO 10:47:54 AM] [API] Vitest v2.1.3 (dist/vitest.config.js) child process 15631 created
[INFO 10:47:54 AM] [API] Vitest v2.1.3 (ts2esm/vitest.config.ts) child process 15632 created
[INFO 10:47:54 AM] [VSCODE] Watching ts2esm with pattern **/*
[INFO 10:50:29 AM] [API] Collecting tests: src/converter/convertFile.test.ts

Version

v1.6.1

Validations

bennycode avatar Oct 25 '24 08:10 bennycode