Closed thebjorn closed 5 months ago
`"vitest": "^0.9.0" works, but "^1.0.0" does not... At this point I can't tell if I'm doing something wrong (I haven't done anything special, so I don't think so..) or if the docs just haven't been updated to a new syntax? (it's literally the first example in the docs, so that too seems unlikely...?)
How do I reproduce this error? Works fine here https://stackblitz.com/github/thebjorn/vitest-problems?file=src%2Ftest-sum.js
modified
vite.config.js
to look for test files in jest format (aside: the nice thing about jest is that it just worked..)
This is intentional https://github.com/vitest-dev/vitest/issues/3530. Considering files like test/test-utils.ts
as test files is not ideal.
How do I reproduce this error?
(dev310) go|c:\srv\tmp> git clone https://github.com/thebjorn/vitest-problems
Cloning into 'vitest-problems'...
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 21 (delta 0), reused 21 (delta 0), pack-reused 0
Receiving objects: 100% (21/21), 31.64 KiB | 675.00 KiB/s, done.
(dev310) go|c:\srv\tmp> cd vitest-problems
(dev310) go|c:\srv\tmp\vitest-problems> node --version
v21.4.0
(dev310) go|c:\srv\tmp\vitest-problems> yarn --version
1.22.21
(dev310) go|c:\srv\tmp\vitest-problems> yarn
yarn install v1.22.21
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "@sveltejs/vite-plugin-svelte > svelte-hmr@0.15.3" has incorrect peer dependency "svelte@^3.19.0 || ^4.0.0".
warning " > @vitest/coverage-c8@0.33.0" has incorrect peer dependency "vitest@>=0.30.0 <1".
[4/4] Building fresh packages...
Done in 1.48s.
(dev310) go|c:\srv\tmp\vitest-problems> npx vitest --run
8:30:51 AM [vite-plugin-svelte] Your are using Svelte 5.0.0-next.80. Svelte 5 support is experimental, breaking changes can occur in any release until this notice is removed.
work in progress:
- svelte-inspector is disabled until dev mode implements node to code mapping
- hmr for .svelte files is disabled until hmr api is implemented
RUN v1.4.0 c:/srv/tmp/vitest-problems
❯ src/test-sum.js (0)
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL src/test-sum.js [ src/test-sum.js ]
TypeError: Cannot read properties of undefined (reading 'test')
❯ src/test-sum.js:3:1
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
Test Files 1 failed (1)
Tests no tests
Start at 08:30:51
Duration 441ms (transform 15ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 123ms)
(dev310) go|c:\srv\tmp\vitest-problems> yarn add -D vitest@0.9.4
yarn add v1.22.21
[1/4] Resolving packages...
⠁ (node:19480) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "@sveltejs/vite-plugin-svelte > svelte-hmr@0.15.3" has incorrect peer dependency "svelte@^3.19.0 || ^4.0.0".
warning " > @vitest/coverage-c8@0.33.0" has incorrect peer dependency "vitest@>=0.30.0 <1".
warning " > @vitest/coverage-v8@1.4.0" has incorrect peer dependency "vitest@1.4.0".
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 14 new dependencies.
info Direct dependencies
└─ vitest@0.9.4
info All dependencies
├─ @types/chai-subset@1.3.5
├─ @types/chai@4.3.12
├─ chai@4.4.1
├─ esbuild-windows-64@0.14.54
├─ function-bind@1.1.2
├─ hasown@2.0.2
├─ is-core-module@2.13.1
├─ local-pkg@0.4.3
├─ path-parse@1.0.7
├─ resolve@1.22.8
├─ supports-preserve-symlinks-flag@1.0.0
├─ tinypool@0.1.3
├─ tinyspy@0.3.3
└─ vitest@0.9.4
Done in 1.53s.
(dev310) go|c:\srv\tmp\vitest-problems> npx vitest --run
RUN v0.9.4 c:/srv/tmp/vitest-problems
8:31:20 AM [vite-plugin-svelte] Your are using Svelte 5.0.0-next.80. Svelte 5 support is experimental, breaking changes can occur in any release until this notice is removed.
work in progress:
- svelte-inspector is disabled until dev mode implements node to code mapping
- hmr for .svelte files is disabled until hmr api is implemented
√ src/test-sum.js (1)
Test Files 1 passed (1)
Tests 1 passed (1)
Time 1.39s (in thread 1ms, 139434.73%)
(dev310) go|c:\srv\tmp\vitest-problems>
modified vite.config.js to look for test files in jest format (aside: the nice thing about jest is that it just worked..)
This is intentional https://github.com/vitest-dev/vitest/issues/3530. Considering files like test/test-utils.ts as test files is not ideal.
That is certainly one opinion (although why you wouldn't simply call it test/utils.js
is a mystery), but for some of us api-stability, backwards compatibility, and compatibility with other languages' testing tools is more important - I realize this isn't true for everyone.
Start by resolving these issues that your package manager is warning about. These are likely pulling multiple version of Vitest into your setup.
(dev310) go|c:\srv\tmp\vitest-problems> yarn yarn install v1.22.21 [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... warning "@sveltejs/vite-plugin-svelte > svelte-hmr@0.15.3" has incorrect peer dependency "svelte@^3.19.0 || ^4.0.0". warning " > @vitest/coverage-c8@0.33.0" has incorrect peer dependency "vitest@>=0.30.0 <1". [4/4] Building fresh packages... Done in 1.48s.
I'm still getting the error after removing the two coverage packages:
(dev310) go|c:\srv\tmp\vitest-problems> rm -rf node_modules yarn.lock
(dev310) go|c:\srv\tmp\vitest-problems> yarn
yarn install v1.22.21
info No lockfile found.
[1/4] Resolving packages...
⠁ (node:55724) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "@sveltejs/vite-plugin-svelte > svelte-hmr@0.15.3" has incorrect peer dependency "svelte@^3.19.0 || ^4.0.0".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 6.94s.
(dev310) go|c:\srv\tmp\vitest-problems> npx vitest --run
9:20:18 AM [vite-plugin-svelte] Your are using Svelte 5.0.0-next.80. Svelte 5 support is experimental, breaking changes can occur in any release until this notice is removed.
work in progress:
- svelte-inspector is disabled until dev mode implements node to code mapping
- hmr for .svelte files is disabled until hmr api is implemented
RUN v1.4.0 c:/srv/tmp/vitest-problems
❯ src/test-sum.js (0)
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL src/test-sum.js [ src/test-sum.js ]
TypeError: Cannot read properties of undefined (reading 'test')
❯ src/test-sum.js:3:1
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
Test Files 1 failed (1)
Tests no tests
Start at 09:20:18
Duration 666ms (transform 22ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 158ms)
Another developer here has verified that they get the problem.
Interestingly, I do not see the problem when running under wsl, nor when running under windows-latest on github...(?)
(dev310) go|c:\srv\tmp\vitest-problems> npx vitest --run
Could you also try if running vitest
through package.json
scripts help? I guess npx
could use another version if it's available as global package. So instead of npx vitest --run
use yarn test
.
same result.
I'm unable to reproduce this issue on Github Codespaces or Stackblitz. It works fine all the time.
Hmm... just for fun I tried using pnpm instead of yarn and that worked...(?)
Neither npm nor yarn works.
Both NPM and Yarn work in Github Codespaces using your reproduction setup. I have no idea how to reproduce this issue. 🤷
Hello @thebjorn. 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.
Describe the bug
Following the docs (https://vitest.dev/guide/#writing-tests), I've created the following minimal test:
and I'm getting the following error:
package.json
if I downgrade vitest to 0.26.0 (random version, saw it in another issue) then everything works.
Reproduction
https://github.com/thebjorn/vitest-problems
Created with
npm create svelte@latest vitest-problems
modifiedvite.config.js
to look for test files in jest format and addedsrc/test-sum.js
(aside: the nice thing about jest is that it just worked..)
System Info
Used Package Manager
yarn
Validations