版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

118 строки
6.4 KiB

  1. import { normalize } from 'pathe';
  2. import cac from 'cac';
  3. import c from 'picocolors';
  4. import { v as version, s as startVitest, d as divider } from './chunk-node-pkg.30d8b37e.js';
  5. import './chunk-constants.bc18a549.js';
  6. import './chunk-integrations-coverage.d93ee824.js';
  7. import './chunk-env-node.affdd278.js';
  8. import 'node:console';
  9. import 'local-pkg';
  10. import './chunk-utils-env.6b856dbf.js';
  11. import 'std-env';
  12. import '@vitest/runner/utils';
  13. import './chunk-utils-global.fd174983.js';
  14. import '@vitest/utils';
  15. import 'vite';
  16. import 'node:path';
  17. import 'node:url';
  18. import 'node:process';
  19. import 'node:fs';
  20. import 'path';
  21. import 'os';
  22. import 'util';
  23. import 'stream';
  24. import 'events';
  25. import 'fs';
  26. import './vendor-_commonjsHelpers.addc3445.js';
  27. import 'vite-node/utils';
  28. import 'vite-node/client';
  29. import 'node:fs/promises';
  30. import './vendor-index.2cbcdd1e.js';
  31. import 'node:buffer';
  32. import 'node:child_process';
  33. import 'child_process';
  34. import 'node:os';
  35. import 'assert';
  36. import 'buffer';
  37. import 'source-map';
  38. import 'module';
  39. import 'acorn';
  40. import 'acorn-walk';
  41. import './chunk-utils-base.b5ddfcc9.js';
  42. import 'crypto';
  43. import './chunk-paths.e36446b4.js';
  44. import 'node:v8';
  45. import './vendor-index.783e7f3e.js';
  46. import 'node:worker_threads';
  47. import 'tinypool';
  48. import 'perf_hooks';
  49. import './chunk-utils-tasks.8781fd71.js';
  50. import '@vitest/utils/diff';
  51. import 'vite-node/server';
  52. import './vendor-magic-string.es.b3bc5745.js';
  53. import 'node:module';
  54. import 'node:crypto';
  55. import 'strip-literal';
  56. import 'readline';
  57. const cli = cac("vitest");
  58. cli.version(version).option("-r, --root <path>", "Root path").option("-c, --config <path>", "Path to config file").option("-u, --update", "Update snapshot").option("-w, --watch", "Enable watch mode").option("-t, --testNamePattern <pattern>", "Run tests with full names matching the specified regexp pattern").option("--dir <path>", "Base directory to scan for the test files").option("--ui", "Enable UI").option("--open", "Open UI automatically (default: !process.env.CI))").option("--api [api]", "Serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort").option("--threads", "Enabled threads (default: true)").option("--single-thread", "Run tests inside a single thread, requires --threads (default: false)").option("--silent", "Silent console output from tests").option("--isolate", "Isolate environment for each test file (default: true)").option("--reporter <name>", "Specify reporters").option("--outputDiffMaxSize <length>", "Object diff output max size (default: 10000)").option("--outputDiffMaxLines <length>", "Max lines in diff output window (default: 50)").option("--outputTruncateLength <length>", "Diff output line length (default: 80)").option("--outputDiffLines <lines>", "Number of lines in single diff (default: 15)").option("--outputFile <filename/-s>", "Write test results to a file when supporter reporter is also specified, use cac's dot notation for individual outputs of multiple reporters").option("--coverage", "Enable coverage report").option("--run", "Disable watch mode").option("--mode <name>", "Override Vite mode (default: test)").option("--globals", "Inject apis globally").option("--dom", "Mock browser api with happy-dom").option("--browser [options]", "Run tests in the browser (default: false)").option("--environment <env>", "Specify runner environment, if not running in the browser (default: node)").option("--passWithNoTests", "Pass when no tests found").option("--logHeapUsage", "Show the size of heap for each test").option("--allowOnly", "Allow tests and suites that are marked as only (default: !process.env.CI)").option("--dangerouslyIgnoreUnhandledErrors", "Ignore any unhandled errors that occur").option("--shard <shard>", "Test suite shard to execute in a format of <index>/<count>").option("--changed [since]", "Run tests that are affected by the changed files (default: false)").option("--sequence <options>", "Define in what order to run tests (use --sequence.shuffle to run tests in random order)").option("--segfaultRetry <times>", "Return tests on segment fault (default: 0)", { default: 0 }).option("--no-color", "Removes colors from the console output").option("--inspect", "Enable Node.js inspector").option("--inspect-brk", "Enable Node.js inspector with break").option("--test-timeout <time>", "Default timeout of a test in milliseconds (default: 5000)").help();
  59. cli.command("run [...filters]").action(run);
  60. cli.command("related [...filters]").action(runRelated);
  61. cli.command("watch [...filters]").action(watch);
  62. cli.command("dev [...filters]").action(watch);
  63. cli.command("bench [...filters]").action(benchmark);
  64. cli.command("typecheck [...filters]").action(typecheck);
  65. cli.command("[...filters]").action((filters, options) => start("test", filters, options));
  66. cli.parse();
  67. async function runRelated(relatedFiles, argv) {
  68. argv.related = relatedFiles;
  69. argv.passWithNoTests ?? (argv.passWithNoTests = true);
  70. await start("test", [], argv);
  71. }
  72. async function watch(cliFilters, options) {
  73. options.watch = true;
  74. await start("test", cliFilters, options);
  75. }
  76. async function run(cliFilters, options) {
  77. options.run = true;
  78. await start("test", cliFilters, options);
  79. }
  80. async function benchmark(cliFilters, options) {
  81. console.warn(c.yellow("Benchmarking is an experimental feature.\nBreaking changes might not follow semver, please pin Vitest's version when using it."));
  82. await start("benchmark", cliFilters, options);
  83. }
  84. async function typecheck(cliFilters = [], options = {}) {
  85. console.warn(c.yellow("Testing types with tsc and vue-tsc is an experimental feature.\nBreaking changes might not follow semver, please pin Vitest's version when using it."));
  86. await start("typecheck", cliFilters, options);
  87. }
  88. function normalizeCliOptions(argv) {
  89. if (argv.root)
  90. argv.root = normalize(argv.root);
  91. else
  92. delete argv.root;
  93. if (argv.config)
  94. argv.config = normalize(argv.config);
  95. else
  96. delete argv.config;
  97. if (argv.dir)
  98. argv.dir = normalize(argv.dir);
  99. else
  100. delete argv.dir;
  101. return argv;
  102. }
  103. async function start(mode, cliFilters, options) {
  104. try {
  105. const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(options));
  106. if (!(ctx == null ? void 0 : ctx.shouldKeepServer()))
  107. await (ctx == null ? void 0 : ctx.exit());
  108. return ctx;
  109. } catch (e) {
  110. console.error(`
  111. ${c.red(divider(c.bold(c.inverse(" Unhandled Error "))))}`);
  112. console.error(e);
  113. console.error("\n\n");
  114. process.exit(1);
  115. }
  116. }