Skip to content

Vitest

Plugin vs barrel

WARNING

Config: untestutils/vitest/plugin. Specs: untestutils/vitest. Do not load the barrel in config.

Plugin options

ts
untestutils({
  recipes,              // from defineRecipes(..., import.meta.url)
  prewarm: ['site'],
  browsers: ['chromium'],
  artifactsRoot: undefined,
})
OptionNotes
recipesMap from your recipes module
prewarmIds to prepare/start in global setup
browsersEngines for page / goto (default ['chromium'])
artifactsRootSets UNTESTUTILS_ARTIFACTS_DIR

Override engine per run: UNTESTUTILS_BROWSER=firefox.

useHarness

ts
const app = await useHarness('site')
await app.$fetch('/')
app.url
app.dir
await app.files.read('index.html')

Prefer registered ids so Vitest and Playwright share the prepare cache.

Fixtures

FixtureRole
harnessRecipe id via test.override({ harness })
browserNamechromium | firefox | webkit
baseURLCurrent harness URL
pagePlaywright Page
gotopage.goto (+ Nuxt waitUntil: 'hydration' | 'route')
requestAPIRequestContext
ts
import { describe, test, expect } from 'untestutils/vitest'

describe('ui', () => {
  test.override({ harness: 'site' })

  test('home', async ({ page, goto }) => {
    await goto('/', { waitUntil: 'hydration' })
    await expect(page.getByRole('heading')).toBeVisible()
  })
})

Ensure useHarness or prewarm started the target so baseURL resolves.

Nuxt unit (separate project)

E2e plugin and Nuxt unit env do not share one Vitest config:

  • E2e: untestutils/vitest/plugin
  • Unit: environment: 'untestutils' + untestutils/config / untestutils/runtime

See API overview (config, runtime, module).

Next

Released under the MIT License.