Skip to content

Migrating from nuxt-vitest #644

@danielroe

Description

@danielroe

If you previously used nuxt-vitest, we have now merged it into @nuxt/test-utils, as well as implementing a range of fixes. Here are the required steps:

  1. Uninstall nuxt-vitest, update your vitest versions to v1, and update @nuxt/test-utils and vitest-environment-nuxt to the alpha versions:

      "devDependencies": {
    -   "@nuxt/test-utils": "^3.8.1",
    +   "@nuxt/test-utils": "^3.9.0-alpha.1",
    -   "@vitest/coverage-v8": "0.33.0",
    +   "@vitest/coverage-v8": "^1.0.4",
        "@vue/test-utils": "^2.4.3",
    -   "nuxt-vitest": "^0.11.5",
    -   "vitest": "^0.33.0",
    +   "vitest": "^1.0.4",
    +   "vitest-environment-nuxt": "^1.0.0-alpha.1"
      },
  2. Update your nuxt.config if you have added the nuxt-vitest module to it:

      export default defineNuxtConfig({
       modules: [
    -    'nuxt-vitest'
    +    '@nuxt/test-utils/module'
       ]
      })
  3. Update any imports from nuxt-vitest and vitest-environment-nuxt:

    -  import { mountSuspended } from 'nuxt-vitest/utils' // or 'vitest-environment-nuxt/utils'
    +  import { mountSuspended } from '@nuxt/test-utils/runtime'
    
    -  import { defineVitestConfig } from 'vitest-environment-nuxt/config' // or 'nuxt-vitest/config'
    +  import { defineVitestConfig } from '@nuxt/test-utils/config'
    
    -  import { setup, $fetch } from '@nuxt/test-utils'
    +  import { setup, $fetch } from '@nuxt/test-utils/e2e'
  4. Ensure vitest is running in a module context (either by checking you have type: 'module' set in your package.json, or by renaming your vitest.config file to vitest.config.mts or vitest.config.mjs.

If you encounter any problems with this upgrade path, please let us know by raising an issue. 🙏


📖 You can read more in this draft documentation: nuxt/nuxt#24658.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions