import process from 'node:process';
import { d as defineCommand, b as legacyRootDirArgs, l as logLevelArgs, c as cwdArgs } from '../shared/nuxi.C0YEEVs2.mjs';
import { l as logger } from '../shared/nuxi.DQjfoGl0.mjs';
import { r as resolve } from '../shared/nuxi.Do0aYBCO.mjs';
import 'node:crypto';
import 'node:path';
import 'node:tty';
import 'node:url';
import 'node:util';

const test = defineCommand({
  meta: {
    name: "test",
    description: "Run tests"
  },
  args: {
    ...cwdArgs,
    ...logLevelArgs,
    ...legacyRootDirArgs,
    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 = resolve(ctx.args.cwd || ctx.args.rootDir);
    const { runTests } = await importTestUtils();
    await runTests({
      rootDir: cwd,
      dev: ctx.args.dev,
      watch: ctx.args.watch,
      ...{}
    });
  }
});
async function importTestUtils() {
  let err;
  for (const pkg of [
    "@nuxt/test-utils-nightly",
    "@nuxt/test-utils-edge",
    "@nuxt/test-utils"
  ]) {
    try {
      const exports = await import(pkg);
      if (!exports.runTests) {
        throw new Error("Invalid version of `@nuxt/test-utils` is installed!");
      }
      return exports;
    } catch (_err) {
      err = _err;
    }
  }
  logger.error(err);
  throw new Error("`@nuxt/test-utils` seems missing. Run `npm i -D @nuxt/test-utils` or `yarn add -D @nuxt/test-utils` to install.");
}

export { test as default };
