lowcrawler
lowcrawler

Reputation: 7599

Vitest running, but not not updating results of tests after modification of files

I'm running tests in Vitest. When I make changes to the code or the tests, the console refreshes and the tests appear to re-run, but they don't ACTUALLY re-run.

This is the scenario.

I have 5 tests, they all pass: enter image description here

I then add a 6th test to the code, the console refreshes, but the result looks exactly the same (still says 5/5 passed... no indication there is a 6th test). If I modify the code in a way that one of the previously-passing tests obviously fails.. again, it appears to re-run the tests, but the exact same results show up: 5/5 tests passing.

If I QUIT the test runner and restart it, it will run the new tests and the new code and show the correct results...

I'm unsure why this is or where to look for fixing it.

My vitest.config.js looks like this:

import react from '@vitejs/plugin-react';
import { defineConfig } from 'vitest/config'

export default defineConfig({
  plugins: [react()],
  test: {
    include: ['**/*.test.js'],
    globals: true
  },
})

my vite.config.js looks like this:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react()],
  server: {
    port: 3002,
    open: '/index.html',
  },
  resolve: {
      extensions: ['.tsx', '.ts', '.jsx', '.js'], // Include both .tsx and .js extensions
    },
})

This is with version 5.1.6 of vite and 1.4.0 of vitest

Upvotes: 4

Views: 3906

Answers (3)

Gabriel Antonio
Gabriel Antonio

Reputation: 71

As I mentioned in my latest answer I was having the same exact problem.

Actually I just tested changing the paths like this issue here. My problem was the baseDir configuration set to ./ that is the base directory of my project. Vitest does not resolve the relative paths by itself and doesn't rerun the updated code on watch mode. I tried changing to relative path from src/application/... to ../src/application/... and solved my problem.

I'm installing vite-tsconfig-paths as a workaround to this and adding as a plugin in vite.config.ts:

import { config } from "dotenv";
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    passWithNoTests: true,
    globals: true,
    coverage: {
      include: ["src/*.ts"],
      provider: "v8",
    },
    env: {
      ...config({ path: "env/.env.test" }).parsed,
    },
  },
  plugins: [tsconfigPaths()],
});

I just found this issue in Vitest repository and tested myself. An user in this issue gave a more detailed answer.

Upvotes: 1

Gabriel Antonio
Gabriel Antonio

Reputation: 71

It is happening to me as well in Vitest 1.6.0 and Typescript 5.5.x. Just forked a project from a course I'm doing. The project was using Jest but I changed to Vitest.

I even tested some older versions of both dependencies 'cause I was building an API some weeks ago with the same setup and it is still working just fine with TS 5.4.5 and Vitest 1.6.0. Changing the versions of this new project to these ones didn't work. I just managed to fresh reinstall all dependencies by deleting node_modules folder but it keeps with the same behavior.

Not really sure what may be causing this: literally the watch mode is broken for a newer project but the same test runner for an older project is still working.

PS: Both projects of mine have the same vitest.config.ts and tsconfig.json configuration sets.

PS2: Just verified that it actually updates the code from the tests files but it does not update the code from my src path.

Upvotes: 0

Matt Booth
Matt Booth

Reputation: 2063

Ok, from your question I cannot tell if this issue applies to you, but I resolved it in my environment. I had been trying to use vitest sveeral levels deep in my VSC file structure. I opened a new VSC window, opening directly into the subfolder which I had my JS source in, and ran vitest (and/or the UI) from there then I modified a test file and the terminal and UI updated immediately. I believe it has an issue looking for something in the root of your VSC folder. So I now just keep a 2nd VSC window open in the background (the subfolder), I don't actually work in that window, I still work in the main window with the main directory but the vitest UI and terminal are connected to the other VSC window.

Upvotes: 0

Related Questions