Skip to content

Unable to get a running env with nuxt/test-utils #15073

Closed as not planned
Closed as not planned
@joesobo

Description

@joesobo

Environment

- Operating System: `Darwin`
- Node Version:     `v16.16.0`
- Nuxt Version:     `3.0.0-rc.11`
- Nitro Version:    `0.5.4`
- Package Manager:  `yarn@1.22.11`
- Builder:          `vite`

Though I have also tested with rc 10, 8, 5, & 4

Reproduction

This is fairly short so ill avoid reproduction unless theres a strong need

From a fresh Nuxt 3 Project:

// package.json

{
  "scripts": {
    ...
    "build": "nuxt build",
    "test": "vitest run"
  },
  "devDependencies": {
    "nuxt": "3.0.0-rc.11"
  },
  "dependencies": {
    "@nuxt/test-utils": "3.0.0-rc.11",
    "vitest": "^0.23.4"
  }
}
// vite.config.ts

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    globals: true,
  },
});
// pages/index.vue

<template>
  <h1>Hello World!</h1>
</template>
// pages/index.spec.ts

import { describe, test, expect } from 'vitest'
import { setup, $fetch } from '@nuxt/test-utils'

describe('My test', async () => {
  await setup({
    runner: 'vitest',
  })

  test('my test', () => {
    const html = $fetch('/')

    expect(html).toContain('Hello World!')
  })
})

Describe the bug

During the beforeAll section of the setup in my test it crashes with this result:

Error: [vite]: Rollup failed to resolve import "jest" from "node_modules/@nuxt/test-utils/dist/index.mjs".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`

This is strange since the runner is clearly vitest, so it shouldnt be trying to import jest.

Took a brief look at the index.mjs and my hooks.ctx.options.runner is properly recieving vitest.

The error ends with:

 Segmentfault Error Detected 
  FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal.
  Refer to https://github.com/nodejs/node/issues/42407

Additional context

I havent been able to find a solid working example to base my own code. I was hoping this issue was just the RC version that I was using, but so far I havent had any luck with changing it.

I tried cloning the nuxt-ionic repository as I saw it was on a later RC version and using vitest, however even with that I ran into issues. Is there a good working example I can be pointed in the direction of?

Logs

$ vitest run

 RUN  v0.23.4 /Users/*********************/test-utils

 ❯ pages/index.spec.ts (1)
 1: 0x103ab6ef5 node::Abort() (.cold.1) [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]
 ❯ pages/index.spec.ts (1) 4104ms
   ❯ My test (1) 4103ms
     ⠙ [ beforeAll ]
     · my test

 2: 0x1027aa869 node::Abort() [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]
 3: 0x1027aa9df node::OnFatalError(char const*, char const*) [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  pages/index.spec.ts > My test
 4: 0x10292ed00 v8::V8::ToLocalEmpty() [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]
Error: [vite]: Rollup failed to resolve import "jest" from "node_modules/@nuxt/test-utils/dist/index.mjs".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
 ❯ onRollupWarning node_modules/vite/dist/node/chunks/dep-6b3a5aff.js:45908:19
 5: 0x1027a596f node::fs::FSReqPromise<node::AliasedBufferBase<double, v8::Float64Array, void> >::Resolve(v8::Local<v8::Value>) [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]
 ❯ onwarn node_modules/vite/dist/node/chunks/dep-6b3a5aff.js:45706:13
 ❯ Object.onwarn node_modules/vite/node_modules/rollup/dist/es/shared/rollup.js:23225:13
 ❯ ModuleLoader.handleResolveId node_modules/vite/node_modules/rollup/dist/es/shared/rollup.js:22352:26
 ❯ ModuleLoader.resolveDynamicImport node_modules/vite/node_modules/rollup/dist/es/shared/rollup.js:22404:120
 ❯ async file:/Users/*********************/test-utils/node_modules/vite/node_modules/rollup/dist/es/shared/rollup.js:22299:32

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
 6: 0x1027afa40 node::fs::AfterStat(uv_fs_s*) [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]
 7: 0x103176598 uv__work_done [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]
 8: 0x10317b75b uv__async_io [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]
 9: 0x10318f54b uv__io_poll [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]
Serialized Error: Object {
  "watchFiles": [Array],
}
10: 0x10317bce1 uv_run [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]


⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

11: 0x1026dbf9f node::SpinEventLoop(node::Environment*) [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]
Test Files  1 failed (1)
     Tests   (1)
12: 0x102852cae node::worker::Worker::Run() [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]
13: 0x1028566a2 node::worker::Worker::StartThread(v8::FunctionCallbackInfo<v8::Value> const&)::$_3::__invoke(void*) [/Users/*********************/.nvm/versions/node/v16.16.0/bin/node]
14: 0x7ff8042ef4e1 _pthread_start [/usr/lib/system/libsystem_pthread.dylib]
15: 0x7ff8042eaf6b thread_start [/usr/lib/system/libsystem_pthread.dylib]

 Segmentfault Error Detected 
  FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal.
  Refer to https://github.com/nodejs/node/issues/42407

It seems to be an upstream bug of Node.js. To improve the test stability,
you could pass --segfault-retry=3 or set env VITEST_SEGFAULT_RETRY=3 to
have Vitest auto retries on flaky segfaults.

error Command failed with exit code 1.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions