-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
os: windowsp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
Describe the bug
When adding vitest to an existing project & all tests are failing with TypeError: Cannot read properties of undefined (reading 'test').
Looks like this is due to my windows cmd line having a lower-case drive letter. Tests successfully run in powershell, & vs code console.
Adding a vitest.config.ts file w/ a normalized root property worked around the issue.
export default mergeConfig(
viteConfig,
defineConfig({
test: {
environment: 'jsdom',
exclude: [...configDefaults.exclude, 'e2e/*']
// including this line, it works, commenting out, it fails
// , root: fileURLToPath(new URL('./', import.meta.url))
}
})
)Below is the stack from the test exception getting thrown - note the varying drive letters:
TypeError: Cannot read properties of undefined (reading 'test')
at Object.<anonymous> (file:///c:/github/vue/vitest-repro/node_modules/@vitest/runner/dist/index.js:256:22)
at Module.chain2 (file:///c:/github/vue/vitest-repro/node_modules/@vitest/runner/dist/chunk-tasks.js:98:17)
at c:\github\vue\vitest-repro\src\components\__tests__\HelloWorld.spec.ts:7:1
at VitestExecutor.runModule (file:///C:/github/vue/vitest-repro/node_modules/vite-node/dist/client.mjs:362:5)
at VitestExecutor.directRequest (file:///C:/github/vue/vitest-repro/node_modules/vite-node/dist/client.mjs:346:5)
at VitestExecutor.cachedRequest (file:///C:/github/vue/vitest-repro/node_modules/vite-node/dist/client.mjs:189:14)
at VitestExecutor.executeId (file:///C:/github/vue/vitest-repro/node_modules/vite-node/dist/client.mjs:165:12)
at collectTests (file:///C:/github/vue/vitest-repro/node_modules/@vitest/runner/dist/index.js:578:7)
at startTests (file:///C:/github/vue/vitest-repro/node_modules/@vitest/runner/dist/index.js:908:17)
at file:///C:/github/vue/vitest-repro/node_modules/vitest/dist/chunks/runtime-runBaseTests.9RbsHRbU.js:114:7
Reproduction
Using the default example on StackBlitz
Download to a local folder on windows - i.e. C:\repro\vitest-repro.
From a windows cmd line (not powershell or vs code console), make sure your drive prompt is lower-case.
cd c:\repro\vitest-reproRun tests
npm run test
DEV v1.3.1 c:/work/vite-repro
❯ test/suite.test.ts (0)
❯ test/basic.test.ts (0)
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 2 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL test/basic.test.ts [ test/basic.test.ts ]
TypeError: Cannot read properties of undefined (reading 'test')
❯ test/basic.test.ts:6:1
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯
FAIL test/suite.test.ts [ test/suite.test.ts ]
Error: No test suite found in file C:/work/vite-repro/test/suite.test.ts
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯
Test Files 2 failed (2)
Tests no tests
Start at 11:53:59
Duration 847ms (transform 107ms, setup 0ms, collect 208ms, tests 0ms, environment 1ms, prepare 475ms)
If you add a vitest.config.ts w/ the root property as above, it resolves
System Info
System:
OS: Windows 11 10.0.22621
CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
Memory: 4.73 GB / 15.92 GB
Binaries:
Node: 18.13.0 - C:\Program Files\nodejs\node.EXE
npm: 8.10.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 121.0.6167.185
Edge: Chromium (121.0.2277.128)
Internet Explorer: 11.0.22621.1Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
alexandersorokin
Metadata
Metadata
Assignees
Labels
os: windowsp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)