vitest-dev / vscode

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

Get a error during test discovery, when I clicked `Refresh Tests` button #341

Closed justorez closed 4 months ago

justorez commented 4 months ago

Describe the bug

Snipaste_2024-04-15_11-56-23

[Error 11:50:28] [Error TypeError] Cannot read properties of undefined (reading 'file')
TypeError: Cannot read properties of undefined (reading 'file')
    at wn (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:17:385)
    at nt.discoverFileTests (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:15:4684)
    at Xt.resolveTestFile (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:17:11904)
    at Xt.testController.resolveHandler [as h] (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:17:8857)
    at n.M (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:23125)
    at n.J (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:22638)
    at n.H (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:22327)
    at n.I (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:22346)
    at n.z (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:21159)
    at n.w (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:20336)
    at H.t.listener (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:22315)
    at Object.add (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:24851)
    at nt.getOrCreateFileTestItem (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:15:3441)
    at nt.discoverAllTestFiles (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:15:2694)
    at nt.watchTestFilesInWorkspace (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:15:4042)
    at Xt.defineTestProfiles (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:17:10483)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async r.$refreshTests (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:154:8490)

Reproduction

https://stackblitz.com/edit/stackblitz-starters-tn8las?file=package.json&view=editor

Output

[INFO 11:54:28 AM] [v0.6.0] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[INFO 11:54:29 AM] [API] Running Vitest: v1.5.0 (E:/Workspace/test/cmd-test/vitest.config.ts)
[INFO 11:54:29 AM] [API] Vitest process 13272 created
[Error 11:54:29 AM] [Error TypeError] Cannot read properties of undefined (reading 'file')
TypeError: Cannot read properties of undefined (reading 'file')
    at wn (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:17:385)
    at nt.discoverFileTests (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:15:4684)
    at Xt.resolveTestFile (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:17:11904)
    at Xt.testController.resolveHandler [as h] (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:17:8857)
    at n.M (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:23125)
    at n.J (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:22638)
    at n.H (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:22327)
    at n.I (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:22346)
    at n.z (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:21159)
    at n.w (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:20336)
    at H.t.listener (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:22315)
    at Object.add (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:140:24851)
    at nt.getOrCreateFileTestItem (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:15:3441)
    at nt.discoverAllTestFiles (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:15:2694)
    at nt.watchTestFilesInWorkspace (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:15:4042)
    at Xt.defineTestProfiles (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:17:10483)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Xt.activate (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:17:12789)
    at async Ic (c:\Users\alone\.vscode\extensions\vitest.explorer-0.6.0\dist\extension.js:17:8373)
    at async a.n (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:142:6237)
    at async a.m (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:142:6200)
    at async a.l (e:\Applications\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:142:5657)

Version

0.6.0

Validations

ffMathy commented 4 months ago

Hmmm interesting how the source maps don't seem to work?

justorez commented 4 months ago

Hmmm interesting how the source maps don't seem to work?

But I find bug seems to be here: src/testTree.ts#L311

getTestData(testItem) returned a undefined value.

function getAPIFromTestItem(testItem: vscode.TestItem): VitestFolderAPI | null {
  const data = getTestData(testItem)
  // API is stored in test files - if this is a folder, try to find a file inside,
  // otherwise go up until we find a file, this should never be a folder
  if (data instanceof TestFolder)
    return getAPIFromFolder(testItem)

  if (data instanceof TestFile)
    return data.api
  return data.file.api
}
sheremet-va commented 4 months ago

I cannot reproduce it with the link. Do you use other extensions? On your screenshot, this is not how we display tests.

ffMathy commented 4 months ago

@sheremet-va not sure if you're aware, but in the test explorer, you can still display tests as a list instead of a tree. This is a vscode feature. It's in the "..." menu. Maybe that could explain the screenshot difference.

sheremet-va commented 4 months ago

Does it throw an error in the latest version? if it does, the error should be more descriptive at least.

github-actions[bot] commented 4 months ago

Hello @justorez. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

justorez commented 4 months ago

Does it throw an error in the latest version? if it does, the error should be more descriptive at least.

@sheremet-va Thanks, I saw it. And I know how to reproduce, just change testing view as list and refresh, view as tree is ok.

Snipaste_2024-04-17_11-58-07

sheremet-va commented 4 months ago

Fixed in https://github.com/vitest-dev/vscode/commit/7ce92f16db7f0e33e5ec2596bd20e4075a86cc4a