Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vitest was initialized with native Node instead of Vite Node #13394

Closed
danielroe opened this issue Feb 16, 2022 · 10 comments · Fixed by nuxt/framework#7712
Closed

Vitest was initialized with native Node instead of Vite Node #13394

danielroe opened this issue Feb 16, 2022 · 10 comments · Fixed by nuxt/framework#7712

Comments

@danielroe
Copy link
Member

danielroe commented Feb 16, 2022

The async import doesn't seem to respect the environment of the test runner.

Reproduction: https://github.com/danielroe/test-utils-test

cc: @antfu

@danielroe danielroe changed the title Vitest was initialized with native Node instead of Vite Node Vitest was initialized with native Node instead of Vite Node Feb 16, 2022
@schickling
Copy link

Are you sure this is a problem with Nuxt? I was running into the same problem when running Vitest on pre-compiled .js test files with the following config:

import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    include: ['dist/__test__/**/mapping.spec.js'],
    // include: ['src/__test__/**/mapping.spec.ts'],
    exclude: [],
    watchIgnore: [],
  },
})

Note: Running the tests on the src/**/*.spec.ts files works as expected.

@antfu
Copy link
Member

antfu commented Feb 22, 2022

Vitest v0.5.1 should fix it.

@antfu antfu closed this as completed Feb 22, 2022
@schickling
Copy link

Still doesn't seem to work with 0.5.1. Here's a repro: https://github.com/schickling-test/2022-feb-vitest-effect/tree/repro/dist-bug

Please run:

  • yarn
  • yarn dev:ts (compiles to ./dist)
  • yarn test

You should see:

image

@danielroe
Copy link
Member Author

I can confirm that my issue is no longer reproducible. @schickling, your issue might be a different one that simply has the same symptom - possibly worth raising at the vitest repo?

@jorge-obsidian
Copy link

I can confirm that my issue is no longer reproducible. @schickling, your issue might be a different one that simply has the same symptom - possibly worth raising at the vitest repo?

I've just cloned that repo and i'm currently getting the Error: Vitest was initialized with native Node instead of Vite Node when launching test.

@CodyBontecou
Copy link
Contributor

I'm also running into this. Here's a reproduction repo.

@danielroe danielroe reopened this Apr 28, 2022
@ytr0903
Copy link

ytr0903 commented May 14, 2022

In my case, creating vitest.config.ts with test.deps.inline resolves this error.

import { defineConfig } from "vitest/config";
export default defineConfig({
  test: {
    environment: "jsdom",
    deps: {
      inline: [/@nuxt\/test-utils-edge/],
    },
  },
})

Ref: vitest-dev/vitest#843

@asmerkin
Copy link

This did not work for me. It's now trying to find jest.

Error: [vite]: Rollup failed to resolve import "jest" from "node_modules/@nuxt/test-utils-edge/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-4da11a5e.js:45916:19
 ❯ onwarn node_modules/vite/dist/node/chunks/dep-4da11a5e.js:45714: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/asmerkin/Workspace/intrepits/elearning-front/node_modules/vite/node_modules/rollup/dist/es/shared/rollup.js:22299:32

@danielroe
Copy link
Member Author

@asmerkin Would you open a new issue/discussion with a reproduction?

@asmerkin
Copy link

@danielroe done here: #15315

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants