@nuxt/cli
Version:
Nuxt CLI
53 lines (52 loc) • 1.54 kB
JavaScript
import { h as defineCommand, l as rootDirArgs } from "./_shared-B9W-9akb.mjs";
import { D as ActionableError } from "./startup-clock-SyYej6uN.mjs";
import { i as resolveRootDir } from "./paths-BipyohVL.mjs";
import process from "node:process";
import { pathToFileURL } from "node:url";
import { resolveModulePath } from "exsolve";
// src/commands/test.ts
var test_default = defineCommand({
meta: {
name: "test",
description: "Run tests"
},
args: {
...rootDirArgs,
dev: {
type: "boolean",
description: "Run in dev mode"
},
watch: {
type: "boolean",
description: "Watch mode"
}
},
async run(ctx) {
process.env.NODE_ENV = process.env.NODE_ENV || "test";
const cwd = resolveRootDir(ctx.args);
const { runTests } = await importTestUtils(cwd);
await runTests({
rootDir: cwd,
dev: ctx.args.dev,
watch: ctx.args.watch
});
}
});
async function importTestUtils(rootDir) {
for (const pkg of [
"@nuxt/test-utils-nightly",
"@nuxt/test-utils-edge",
"@nuxt/test-utils"
]) {
const entry = resolveModulePath(pkg, {
from: rootDir,
try: true
});
if (!entry) continue;
const exports = await import(pathToFileURL(entry).href);
if (typeof exports.runTests !== "function") throw new ActionableError(`The installed version of \`${pkg}\` does not support \`nuxt test\`.`);
return exports;
}
throw new ActionableError("`@nuxt/test-utils` is not installed in this project. Install it as a development dependency to use `nuxt test`.");
}
export { test_default as default, importTestUtils };