Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes Vitest extension runs cached tests #512

Open
4 tasks done
bennycode opened this issue Oct 25, 2024 · 4 comments
Open
4 tasks done

Sometimes Vitest extension runs cached tests #512

bennycode opened this issue Oct 25, 2024 · 4 comments

Comments

@bennycode
Copy link

bennycode commented Oct 25, 2024

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
Copy link
Author

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.

@sheremet-va
Copy link
Member

sheremet-va commented Oct 25, 2024

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
Copy link
Member

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

@bennycode
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants