vitest: Running tests crashes node w/ JSDOM and vue 2 vite plugin
Describe the bug
The issue I keep running into is my tests keep crashing whenever I run vitest. I have also noticed that my tests are not properly isolated from one another, and I’m using @testing-library/vue
version 5.8.2 as well as @testing-library/jest-dom
for additional matchers. I end up in situations where I can see clearly from the error messages from @testing-library/vue
that its re-rendering my components in a non isolated fashion.
Note that all of these tests run fine when using Jest.
My config
import { defineConfig } from 'vitest/config';
import { createVuePlugin } from 'vite-plugin-vue2';
import path from 'path';
import { fileURLToPath } from 'url';
const root = path.dirname(fileURLToPath(import.meta.url));
export default defineConfig({
plugins: [createVuePlugin()],
css: {
preprocessorOptions: {
scss: {
additionalData: `@import "${path.resolve(root, 'style/variables/index.scss')}";`
}
}
},
resolve: {
mainFields: ['module', 'es2015', 'browser', 'jsnext:main', 'jsnext', 'main'],
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.less', '.css', '.scss', '.vue'],
alias: [
{
find: /^@test\/utils$/,
replacement: path.join(root, 'test-utils', 'index.ts')
}
]
},
test: {
environment: 'jsdom',
clearMocks: true,
restoreMocks: true,
mockReset: true,
watch: false,
isolate: true,
transformMode: {
web: [/\.([cm]?[jt]sx?|json|vue)$/]
}
}
});
This is the error I run into whenever I run tests. its not a ton of tests, its approximately 74 total
#
# Fatal error in , line 0
# Check failed: result.second.
#
#
#
#FailureMessage Object: 0x70000c1d7400
1: 0x106042a52 node::NodePlatform::GetStackTracePrinter()::$_3::__invoke() [~/.nvm/versions/node/v16.14.2/bin/node]
2: 0x107016d43 V8_Fatal(char const*, ...) [~/.nvm/versions/node/v16.14.2/bin/node]
3: 0x10643075e v8::internal::GlobalBackingStoreRegistry::Register(std::__1::shared_ptr<v8::internal::BackingStore>) [~/.nvm/versions/node/v16.14.2/bin/node]
4: 0x106166f46 v8::ArrayBuffer::GetBackingStore() [~/.nvm/versions/node/v16.14.2/bin/node]
5: 0x105facd6b node::Buffer::Data(v8::Local<v8::Value>) [~/.nvm/versions/node/v16.14.2/bin/node]
6: 0x105fdc77b node::fs::Read(v8::FunctionCallbackInfo<v8::Value> const&) [~/.nvm/versions/node/v16.14.2/bin/node]
7: 0x1061bd219 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [~/.nvm/versions/node/v16.14.2/bin/node]
8: 0x1061bcce6 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [~/.nvm/versions/node/v16.14.2/bin/node]
9: 0x1061bc45f v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [~/.nvm/versions/node/v16.14.2/bin/node]
10: 0x106a2f959 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [~/.nvm/versions/node/v16.14.2/bin/node]
11: 0x65d8cd21e
12: 0x65d8cc9f9
13: 0x65d8ce22d
[1] 29228 illegal hardware instruction npm run test
Reproduction
Between my companies policy of privacy around the repository in question and the fact we use a custom registry with pre-built dependencies (so the dependencies are not available on github) I’m not able to really at a reproduction.
What I can do is partner with a repo maintainer to troubleshoot the issue in a live session, though I get why this is way less than ideal. I’m going to try and see if I can get something up by reproducing it via hard extracting some packages we pre-built (this may be feasible).
System Info
System:
OS: macOS 12.3.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 1.62 GB / 32.00 GB
Shell: 5.8.1 - /usr/local/bin/zsh
Binaries:
Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
Yarn: 1.22.18 - ~/.nvm/versions/node/v16.14.2/bin/yarn
npm: 8.7.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
Browsers:
Chrome: 100.0.4896.127
Chrome Canary: 103.0.5012.0
Edge: 100.0.1185.44
Firefox: 99.0.1
Firefox Developer Edition: 100.0
Safari: 15.4
Safari Technology Preview: 15.4
npmPackages:
vite: ^2.9.5 => 2.9.5
vitest: ^0.9.3 => 0.9.3
Used 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.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 24 (2 by maintainers)
Commits related to this issue
- docs(useMouse): update example (#1171) — committed to chaii3/vitest by scottbedard 2 years ago
For me, this error only occurs when I try to create a coverage report, but it only happens occasionally (sometimes on every run, sometimes on every second or third run).
Version:
vitest@0.12.6
Configuration:
I had been experiencing this issue, but it was resolved after upgrading to Node 16.17.0 (due to this fix: https://github.com/nodejs/node/pull/42874)
I’m getting this issue with node 16 and vitest, node environment
I’m seeing the same error in a Vue 3 project, both with
jsdom
&happy-dom
. Tried to reproduce in a sharable project, but could not reproduce it in a simple setup (can’t spend more time on it right now).It’s worth mentioning, that I’m only getting this error when running
node@16
… I’m not able to reproduce in eithernode@14
,node@17
&node@18
.@ScottAwesome can you confirm this? (kind reminder to do a
rm -rf node_modules/ && yarn
when switching node-version 🙂).EDIT: Seems to happen after a few runs, easiest to trigger in watch mode.