UNPKG

@nuxt/test-utils

Version:
83 lines (79 loc) 2.24 kB
export { b as buildFixture, c as createBrowser, a as createPage, d as createTest, g as getBrowser, l as loadFixture, e as setup, s as setupMaps, w as waitForHydration } from './shared/test-utils.BIDY1MqP.mjs'; import { u as useTestContext } from './shared/test-utils.CHPAu7TP.mjs'; export { $ as $fetch, c as createTestContext, e as exposeContextToEnv, f as fetch, i as isDev, r as recoverContextFromEnv, s as setTestContext, a as startServer, b as stopServer, d as url } from './shared/test-utils.CHPAu7TP.mjs'; import { consola } from 'consola'; import { resolve } from 'pathe'; import { distDir } from '#dirs'; import 'node:fs'; import 'node:path'; import 'defu'; import '@nuxt/kit'; import 'tinyexec'; import 'get-port-please'; import 'ofetch'; import 'ufo'; import 'std-env'; function mockFn() { const ctx = useTestContext(); return ctx.mockFn; } function mockLogger() { const mocks = {}; consola.mockTypes((type) => { mocks[type] = mockFn(); return mocks[type]; }); return mocks; } const RunTestDefaults = { runner: "vitest", globalSetup: true }; async function runTests(opts) { opts = { ...RunTestDefaults, ...opts }; if (opts.runner !== "vitest") { throw new Error(`Unsupported runner: ${opts.runner}. Currently only vitest runner is supported.`); } if (opts.dev) { process.env.NUXT_TEST_DEV = "true"; } process.env.NUXT_TEST_OPTIONS = JSON.stringify(opts); const { startVitest } = await import('vitest/node'); const succeeded = await startVitest( "test", [], // Vitest options { root: opts.rootDir, run: !opts.watch, deps: { inline: [/@nuxt\/test-utils/] } }, // Vite options { esbuild: { tsconfigRaw: "{}" }, test: { dir: opts.rootDir, deps: { inline: [ distDir, "@nuxt/test-utils", "@nuxt/test-utils-nightly", "@nuxt/test-utils-edge" ] }, globals: true, globalSetup: [ ...opts.globalSetup ? [resolve(distDir, "./runtime/global-setup")] : [] ] } } ); if (!succeeded) { process.exit(1); } } export { mockFn, mockLogger, runTests, useTestContext };