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

I made a video showing the error: https://www.youtube.com/watch?v=eHspbQGqGE4

It happens when I rename the directories of my snapshot files. In my test cases I assemble paths using path.join:

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);
});

When I now rename a directory (i.e. index-import to renamed), the Vitest extension fails to recognize the change.

bennycode avatar Oct 25 '24 09:10 bennycode

If you manually add "vitest.filesWatcherInclude": "*/**" to your .vscode/settings.json file, does it make a difference?

By the way, if Vitest is stuck, you can click on "Refresh Tests" button instead of reinstalling the extension or opening/closing the IDE.

Screenshot 2024-10-25 at 16 49 46

sheremet-va avatar Oct 25 '24 14:10 sheremet-va

Does it stop working after you rename a folder? Does it work before that?

sheremet-va avatar Oct 25 '24 14:10 sheremet-va

It stops working after I rename a folder (as shown in the video). Before renaming the folder, the extension works fine!

bennycode avatar Oct 26 '24 19:10 bennycode