entry.mjs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { promises } from 'fs';
  2. import { g as getWorkerState, a as resetModules } from './chunk-mock-date.2917be60.mjs';
  3. import { a as envs } from './chunk-env-node.ceb43f1c.mjs';
  4. import { a as setupGlobalEnv, s as startTests, w as withEnv } from './chunk-runtime-error.f5506f40.mjs';
  5. import 'path';
  6. import './chunk-constants.71e8a211.mjs';
  7. import 'tty';
  8. import 'url';
  9. import 'local-pkg';
  10. import 'console';
  11. import 'perf_hooks';
  12. import './chunk-integrations-coverage.99c020eb.mjs';
  13. import './chunk-runtime-hooks.e4219ed5.mjs';
  14. import './chunk-runtime-chain.0ab05798.mjs';
  15. import 'util';
  16. import 'chai';
  17. import './vendor-_commonjsHelpers.4da45ef5.mjs';
  18. import './chunk-runtime-rpc.00a890d2.mjs';
  19. import './chunk-utils-timers.b48455ed.mjs';
  20. import './chunk-utils-source-map.2be5aa48.mjs';
  21. import './spy.mjs';
  22. import 'tinyspy';
  23. async function run(files, config) {
  24. await setupGlobalEnv(config);
  25. const workerState = getWorkerState();
  26. if (config.browser) {
  27. workerState.mockMap.clear();
  28. await startTests(files, config);
  29. return;
  30. }
  31. const filesWithEnv = await Promise.all(files.map(async (file) => {
  32. var _a;
  33. const code = await promises.readFile(file, "utf-8");
  34. const env = ((_a = code.match(/@(?:vitest|jest)-environment\s+?([\w-]+)\b/)) == null ? void 0 : _a[1]) || config.environment || "node";
  35. return {
  36. file,
  37. env
  38. };
  39. }));
  40. const filesByEnv = filesWithEnv.reduce((acc, { file, env }) => {
  41. acc[env] || (acc[env] = []);
  42. acc[env].push(file);
  43. return acc;
  44. }, {});
  45. const orderedEnvs = envs.concat(
  46. Object.keys(filesByEnv).filter((env) => !envs.includes(env))
  47. );
  48. for (const env of orderedEnvs) {
  49. const environment = env;
  50. const files2 = filesByEnv[environment];
  51. if (!files2 || !files2.length)
  52. continue;
  53. await withEnv(environment, config.environmentOptions || {}, async () => {
  54. for (const file of files2) {
  55. if (config.isolate) {
  56. workerState.mockMap.clear();
  57. resetModules(workerState.moduleCache, true);
  58. }
  59. workerState.filepath = file;
  60. await startTests([file], config);
  61. workerState.filepath = void 0;
  62. }
  63. });
  64. }
  65. }
  66. export { run };