vitest-dev / vscode

VS Code extension for Vitest
https://vitest.dev/vscode
MIT License
736 stars 83 forks source link

Error running tests with vitest extension in React project powered by Vite #351

Closed ThomasCode92 closed 4 months ago

ThomasCode92 commented 4 months ago

Describe the bug

I recently updated vitest to version 1.5.0 in my React project, which is powered by Vite. Previously, I was using the Test Explorer in VS Code without any issues. However, after the update, whenever I attempt to run tests using the Test Explorer, I encounter the following error message: An error occurred attempting to run tests: TypeError: Cannot read properties of undefined (reading 'logger') This error seems to be related to the vitest extension, and it's hindering my ability to run tests smoothly. Any guidance or solutions on resolving this issue would be greatly appreciated. Thank you!

Reproduction

  1. Ensure you have the vitest extension installed in your VS Code.
  2. Update the vitest extension to version 1.5.0.
  3. Open your React project powered by Vite in VS Code.
  4. Open the Test Explorer pane.
  5. Attempt to run tests using the Test Explorer.
  6. Observe the error message

This is are the settings in vite.confg.ts for testing

test: {
  globals: true,
  environment: 'jsdom',
  globalSetup: './src/test/test-globals.ts',
  setupFiles: './src/test/setup.ts',
  reporter: ['default', 'junit'],
  outputFile: 'test-results/unit-junit-results.xml',
  overage: {
    src: ['./src'],
    provider: 'v8',
    reporter: ['text', 'lcov']
  },
  clearMocks: true
}

Output

[INFO 10:40:05 AM] [v0.6.3] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[INFO 10:40:05 AM] [API] Running Vitest: v1.5.0 (/PATH/vite.config.ts)
[INFO 10:40:06 AM] [API] Vitest process 167240 created
[INFO 10:40:06 AM] [API] Collecting tests: FOLDERS
[INFO 10:40:07 AM] [API] Collecting tests: FOLDERS
[INFO 10:40:14 AM] Running 1 file(s): FOLDERS

--- Folder paths are substituted with the placeholder "FOLDER" due to the presence of sensitive information ---.

Version

0.6.3

Validations

sheremet-va commented 4 months ago

Do you at least have a stack trace for the error?

ThomasCode92 commented 4 months ago

I just got this message in VS Code image

ThomasCode92 commented 4 months ago

After some searching I found this stack trace in the Window Output


024-04-17 10:57:57.232 [error] Cannot read properties of undefined (reading 'logger'): TypeError: Cannot read properties of undefined (reading 'logger')
    at DefaultReporter.resetLastRunLog (file:///home/thomas/repos/<HIDDENPATH>/node_modules/vitest/dist/vendor/index.kSaPvGW6.js:868:14)
    at DefaultReporter.onWatcherRerun (file:///home/thomas/repos/<HIDDENPATH>/node_modules/vitest/dist/vendor/index.kSaPvGW6.js:871:10)
    at DefaultReporter.onWatcherRerun (file:///home/thomas/repos/d<HIDDENPATH>/node_modules/vitest/dist/vendor/index.kSaPvGW6.js:2229:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
    at async Vitest.report (file:///home/thomas/repos/d<HIDDENPATH>/node_modules/vitest/dist/vendor/cac.qnW6GNL2.js:12076:5)
    at async t.rerunTests (/home/thomas/.vscode/extensions/vitest.explorer-0.6.3/dist/worker.js:3:4385)
    at async t.runTestFiles (/home/thomas/.vscode/extensions/vitest.explorer-0.6.3/dist/worker.js:3:4228)
    at async t.collectTests (/home/thomas/.vscode/extensions/vitest.explorer-0.6.3/dist/worker.js:3:3444)
    at async process.<anonymous> (/home/thomas/.vscode/extensions/vitest.explorer-0.6.3/dist/worker.js:1:3028)
``
ThomasCode92 commented 4 months ago

@sheremet-va, I've identified the root cause of my problem. It turns out I had 'reporter' instead of 'reporters' in my config. Closing the issue now!