vitest 0.22.1 → 0.23.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/LICENSE.md +29 -29
  2. package/dist/browser.d.ts +5 -4
  3. package/dist/browser.mjs +10 -8
  4. package/dist/{chunk-api-setup.377c28aa.mjs → chunk-api-setup.11cfd513.mjs} +89 -86
  5. package/dist/{chunk-integrations-coverage.d205bd87.mjs → chunk-env-node.ceb43f1c.mjs} +31 -179
  6. package/dist/chunk-integrations-coverage.99c020eb.mjs +166 -0
  7. package/dist/{chunk-integrations-globals.60af7da3.mjs → chunk-integrations-globals.ad5b1b51.mjs} +5 -6
  8. package/dist/{chunk-magic-string.efe26975.mjs → chunk-magic-string.56b2b543.mjs} +30 -10
  9. package/dist/{chunk-mock-date.304e29b1.mjs → chunk-mock-date.2917be60.mjs} +25 -4
  10. package/dist/{chunk-node-git.9a7e3153.mjs → chunk-node-git.a44b4872.mjs} +14 -8
  11. package/dist/{chunk-runtime-chain.be610650.mjs → chunk-runtime-chain.7a7f3c3b.mjs} +494 -172
  12. package/dist/{chunk-runtime-error.1104e45a.mjs → chunk-runtime-error.2723946b.mjs} +219 -75
  13. package/dist/{chunk-runtime-hooks.5d7073db.mjs → chunk-runtime-hooks.1a0bc3fd.mjs} +18 -12
  14. package/dist/{chunk-runtime-mocker.49d21aa6.mjs → chunk-runtime-mocker.8d4a2494.mjs} +18 -11
  15. package/dist/{chunk-runtime-rpc.57586b73.mjs → chunk-runtime-rpc.00a890d2.mjs} +1 -2
  16. package/dist/{chunk-utils-source-map.bbf3ad19.mjs → chunk-utils-source-map.2be5aa48.mjs} +10 -4
  17. package/dist/{chunk-vite-node-client.cddda63d.mjs → chunk-vite-node-client.da0a17ff.mjs} +49 -12
  18. package/dist/{chunk-vite-node-externalize.c843f497.mjs → chunk-vite-node-externalize.f55c4577.mjs} +547 -218
  19. package/dist/{chunk-vite-node-utils.b432150c.mjs → chunk-vite-node-utils.473cd0b2.mjs} +39 -41
  20. package/dist/cli-wrapper.mjs +17 -13
  21. package/dist/cli.mjs +26 -14
  22. package/dist/config.cjs +2 -2
  23. package/dist/config.d.ts +4 -3
  24. package/dist/config.mjs +2 -2
  25. package/dist/entry.mjs +18 -13
  26. package/dist/environments.d.ts +23 -0
  27. package/dist/environments.mjs +3 -0
  28. package/dist/{global-fe52f84b.d.ts → global-d05ffb3f.d.ts} +140 -19
  29. package/dist/{index-ea17aa0c.d.ts → index-60e2a8e1.d.ts} +3 -2
  30. package/dist/index.d.ts +6 -5
  31. package/dist/index.mjs +5 -6
  32. package/dist/loader.mjs +5 -6
  33. package/dist/node.d.ts +5 -4
  34. package/dist/node.mjs +11 -9
  35. package/dist/suite.mjs +4 -5
  36. package/dist/vendor-index.0557b03a.mjs +147 -0
  37. package/dist/worker.mjs +16 -14
  38. package/package.json +20 -13
  39. package/dist/chunk-utils-global.fa20c2f6.mjs +0 -5
package/LICENSE.md CHANGED
@@ -529,6 +529,35 @@ Repository: https://github.com/mathiasbynens/emoji-regex.git
529
529
 
530
530
  ---------------------------------------
531
531
 
532
+ ## event-target-polyfill
533
+ License: MIT
534
+ By: Ben Lesh
535
+ Repository: git+https://github.com/benlesh/event-target-polyfill.git
536
+
537
+ > MIT License
538
+ >
539
+ > Copyright (c) 2020 Ben Lesh
540
+ >
541
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
542
+ > of this software and associated documentation files (the "Software"), to deal
543
+ > in the Software without restriction, including without limitation the rights
544
+ > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
545
+ > copies of the Software, and to permit persons to whom the Software is
546
+ > furnished to do so, subject to the following conditions:
547
+ >
548
+ > The above copyright notice and this permission notice shall be included in all
549
+ > copies or substantial portions of the Software.
550
+ >
551
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
552
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
553
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
554
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
555
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
556
+ > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
557
+ > SOFTWARE.
558
+
559
+ ---------------------------------------
560
+
532
561
  ## execa
533
562
  License: MIT
534
563
  By: Sindre Sorhus
@@ -1058,35 +1087,6 @@ Repository: git+https://github.com/isaacs/isexe.git
1058
1087
 
1059
1088
  ---------------------------------------
1060
1089
 
1061
- ## jsonc-parser
1062
- License: MIT
1063
- By: Microsoft Corporation
1064
- Repository: https://github.com/microsoft/node-jsonc-parser
1065
-
1066
- > The MIT License (MIT)
1067
- >
1068
- > Copyright (c) Microsoft
1069
- >
1070
- > Permission is hereby granted, free of charge, to any person obtaining a copy
1071
- > of this software and associated documentation files (the "Software"), to deal
1072
- > in the Software without restriction, including without limitation the rights
1073
- > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1074
- > copies of the Software, and to permit persons to whom the Software is
1075
- > furnished to do so, subject to the following conditions:
1076
- >
1077
- > The above copyright notice and this permission notice shall be included in all
1078
- > copies or substantial portions of the Software.
1079
- >
1080
- > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1081
- > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1082
- > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1083
- > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1084
- > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1085
- > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1086
- > SOFTWARE.
1087
-
1088
- ---------------------------------------
1089
-
1090
1090
  ## kleur
1091
1091
  License: MIT
1092
1092
  By: Luke Edwards
package/dist/browser.d.ts CHANGED
@@ -1,13 +1,14 @@
1
- export { E as EnhancedSpy, q as Mock, r as MockContext, p as MockInstance, u as Mocked, v as MockedClass, n as MockedFunction, o as MockedObject, S as SpyInstance, h as afterAll, k as afterEach, g as beforeAll, j as beforeEach, m as createExpect, e as describe, l as expect, i as it, d as suite, t as test } from './index-ea17aa0c.js';
2
- import { R as ResolvedConfig } from './global-fe52f84b.js';
3
- export { z as AfterSuiteRunMeta, A as ApiConfig, O as ArgumentsType, L as Arrayable, K as Awaitable, aa as BaseCoverageOptions, B as BuiltinEnvironment, Y as Constructable, ac as CoverageC8Options, ab as CoverageIstanbulOptions, a8 as CoverageOptions, a5 as CoverageProvider, a6 as CoverageProviderModule, a7 as CoverageReporter, Q as DeepMerge, D as DoneCallback, $ as Environment, E as EnvironmentOptions, _ as EnvironmentReturn, a3 as ErrorWithDiff, a as File, l as HookCleanupCallback, H as HookListener, I as InlineConfig, J as JSDOMOptions, P as MergeInsertions, Z as ModuleCache, M as ModuleGraphData, X as MutableArray, N as Nullable, a4 as OnServerRestartHandler, a2 as ParsedStack, a1 as Position, b as Reporter, y as ResolveIdFunction, R as ResolvedConfig, a9 as ResolvedCoverageOptions, c as RunMode, p as RuntimeContext, r as SnapshotData, u as SnapshotMatchOptions, v as SnapshotResult, t as SnapshotStateOptions, x as SnapshotSummary, s as SnapshotUpdateState, S as Suite, k as SuiteAPI, n as SuiteCollector, o as SuiteFactory, m as SuiteHooks, h as Task, e as TaskBase, f as TaskResult, T as TaskResultPack, d as TaskState, g as Test, j as TestAPI, q as TestContext, i as TestFunction, w as UncheckedSnapshot, U as UserConfig, a0 as UserConsoleLog, V as Vitest, W as WorkerContext, G as WorkerGlobalState, C as WorkerRPC } from './global-fe52f84b.js';
1
+ export { E as EnhancedSpy, r as Mock, u as MockContext, q as MockInstance, v as Mocked, w as MockedClass, o as MockedFunction, p as MockedObject, S as SpyInstance, j as afterAll, l as afterEach, h as beforeAll, k as beforeEach, n as createExpect, e as describe, m as expect, i as it, d as suite, t as test } from './index-60e2a8e1.js';
2
+ import { R as ResolvedConfig } from './global-d05ffb3f.js';
3
+ export { L as AfterSuiteRunMeta, A as ApiConfig, Y as ArgumentsType, X as Arrayable, P as Awaitable, ae as BaseCoverageOptions, ak as BenchFunction, ai as Benchmark, al as BenchmarkAPI, aj as BenchmarkResult, ah as BenchmarkUserOptions, B as BuiltinEnvironment, C as CSSModuleScopeStrategy, a0 as Constructable, ag as CoverageC8Options, af as CoverageIstanbulOptions, ac as CoverageOptions, a9 as CoverageProvider, aa as CoverageProviderModule, ab as CoverageReporter, _ as DeepMerge, D as DoneCallback, a3 as Environment, E as EnvironmentOptions, a2 as EnvironmentReturn, a7 as ErrorWithDiff, a as File, n as HookCleanupCallback, H as HookListener, I as InlineConfig, J as JSDOMOptions, Z as MergeInsertions, a1 as ModuleCache, M as ModuleGraphData, $ as MutableArray, Q as Nullable, a8 as OnServerRestartHandler, a6 as ParsedStack, a5 as Position, b as Reporter, K as ResolveIdFunction, R as ResolvedConfig, ad as ResolvedCoverageOptions, d as RunMode, r as RuntimeContext, u as SnapshotData, x as SnapshotMatchOptions, y as SnapshotResult, w as SnapshotStateOptions, G as SnapshotSummary, v as SnapshotUpdateState, S as Suite, m as SuiteAPI, p as SuiteCollector, q as SuiteFactory, o as SuiteHooks, i as Task, f as TaskBase, g as TaskResult, T as TaskResultPack, e as TaskState, h as Test, l as TestAPI, s as TestContext, j as TestFunction, k as TestOptions, z as UncheckedSnapshot, U as UserConfig, a4 as UserConsoleLog, t as Vitest, V as VitestEnvironment, c as VitestRunMode, W as WorkerContext, O as WorkerGlobalState, N as WorkerRPC } from './global-d05ffb3f.js';
4
4
  import * as chai from 'chai';
5
5
  export { chai };
6
6
  export { assert, should } from 'chai';
7
+ export { Bench as BenchFactory, Options as BenchOptions, Task as BenchTask, TaskResult as BenchTaskResult } from 'tinybench';
7
8
  import 'tinyspy';
8
9
  import 'vite';
9
- import 'worker_threads';
10
10
  import 'fs';
11
+ import 'worker_threads';
11
12
 
12
13
  declare function startTests(paths: string[], config: ResolvedConfig): Promise<void>;
13
14
 
package/dist/browser.mjs CHANGED
@@ -1,22 +1,24 @@
1
- export { c as createExpect, d as describe, b as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.be610650.mjs';
2
- export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach } from './chunk-runtime-hooks.5d7073db.mjs';
3
- export { a as setupGlobalEnv, s as startTests } from './chunk-runtime-error.1104e45a.mjs';
1
+ export { c as createExpect, d as describe, e as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.7a7f3c3b.mjs';
2
+ export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach } from './chunk-runtime-hooks.1a0bc3fd.mjs';
3
+ export { a as setupGlobalEnv, s as startTests } from './chunk-runtime-error.2723946b.mjs';
4
4
  import * as chai from 'chai';
5
5
  export { chai };
6
6
  export { assert, should } from 'chai';
7
7
  import 'util';
8
- import './chunk-mock-date.304e29b1.mjs';
8
+ import './chunk-mock-date.2917be60.mjs';
9
9
  import 'path';
10
10
  import './chunk-constants.71e8a211.mjs';
11
11
  import 'tty';
12
12
  import 'url';
13
13
  import 'local-pkg';
14
14
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
15
- import './chunk-runtime-rpc.57586b73.mjs';
16
- import './chunk-utils-global.fa20c2f6.mjs';
15
+ import './chunk-runtime-rpc.00a890d2.mjs';
17
16
  import './chunk-utils-timers.b48455ed.mjs';
18
17
  import 'fs';
19
- import './chunk-utils-source-map.bbf3ad19.mjs';
18
+ import './chunk-utils-source-map.2be5aa48.mjs';
20
19
  import './spy.mjs';
21
20
  import 'tinyspy';
22
- import './chunk-integrations-coverage.d205bd87.mjs';
21
+ import 'perf_hooks';
22
+ import './chunk-integrations-coverage.99c020eb.mjs';
23
+ import './chunk-env-node.ceb43f1c.mjs';
24
+ import 'console';
@@ -1,5 +1,5 @@
1
1
  import { promises } from 'fs';
2
- import { c as createBirpc } from './chunk-vite-node-client.cddda63d.mjs';
2
+ import { c as createBirpc } from './chunk-vite-node-client.da0a17ff.mjs';
3
3
  import require$$0$1 from 'stream';
4
4
  import require$$0 from 'zlib';
5
5
  import require$$3 from 'net';
@@ -10,16 +10,16 @@ import require$$1 from 'https';
10
10
  import require$$2$1 from 'http';
11
11
  import url from 'url';
12
12
  import { A as API_PATH } from './chunk-constants.71e8a211.mjs';
13
- import { j as interpretSourcePos, p as parseStacktrace } from './chunk-utils-source-map.bbf3ad19.mjs';
13
+ import { i as interpretSourcePos, p as parseStacktrace } from './chunk-utils-source-map.2be5aa48.mjs';
14
14
  import 'module';
15
15
  import 'vm';
16
- import './chunk-vite-node-utils.b432150c.mjs';
16
+ import './chunk-vite-node-utils.473cd0b2.mjs';
17
17
  import 'path';
18
18
  import 'assert';
19
19
  import 'util';
20
20
  import 'debug';
21
21
  import 'tty';
22
- import './chunk-mock-date.304e29b1.mjs';
22
+ import './chunk-mock-date.2917be60.mjs';
23
23
  import 'local-pkg';
24
24
 
25
25
  /*! (c) 2020 Andrea Giammarchi */
@@ -4417,94 +4417,97 @@ function setup(ctx) {
4417
4417
  });
4418
4418
  });
4419
4419
  function setupClient(ws) {
4420
- const rpc = createBirpc({
4421
- async onWatcherStart() {
4422
- await ctx.report("onWatcherStart");
4423
- },
4424
- async onFinished() {
4425
- await ctx.report("onFinished");
4426
- },
4427
- async onCollected(files) {
4428
- ctx.state.collectFiles(files);
4429
- await ctx.report("onCollected", files);
4430
- },
4431
- async onTaskUpdate(packs) {
4432
- ctx.state.updateTasks(packs);
4433
- await ctx.report("onTaskUpdate", packs);
4434
- },
4435
- getFiles() {
4436
- return ctx.state.getFiles();
4437
- },
4438
- async getPaths() {
4439
- return await ctx.state.getPaths();
4440
- },
4441
- readFile(id) {
4442
- return promises.readFile(id, "utf-8");
4443
- },
4444
- writeFile(id, content) {
4445
- return promises.writeFile(id, content, "utf-8");
4446
- },
4447
- async rerun(files) {
4448
- await ctx.rerunFiles(files);
4449
- },
4450
- getConfig() {
4451
- return ctx.config;
4452
- },
4453
- async getTransformResult(id) {
4454
- const result = await ctx.vitenode.transformRequest(id);
4455
- if (result) {
4456
- try {
4457
- result.source = result.source || await promises.readFile(id, "utf-8");
4458
- } catch {
4420
+ const rpc = createBirpc(
4421
+ {
4422
+ async onWatcherStart() {
4423
+ await ctx.report("onWatcherStart");
4424
+ },
4425
+ async onFinished() {
4426
+ await ctx.report("onFinished");
4427
+ },
4428
+ async onCollected(files) {
4429
+ ctx.state.collectFiles(files);
4430
+ await ctx.report("onCollected", files);
4431
+ },
4432
+ async onTaskUpdate(packs) {
4433
+ ctx.state.updateTasks(packs);
4434
+ await ctx.report("onTaskUpdate", packs);
4435
+ },
4436
+ getFiles() {
4437
+ return ctx.state.getFiles();
4438
+ },
4439
+ async getPaths() {
4440
+ return await ctx.state.getPaths();
4441
+ },
4442
+ readFile(id) {
4443
+ return promises.readFile(id, "utf-8");
4444
+ },
4445
+ writeFile(id, content) {
4446
+ return promises.writeFile(id, content, "utf-8");
4447
+ },
4448
+ async rerun(files) {
4449
+ await ctx.rerunFiles(files);
4450
+ },
4451
+ getConfig() {
4452
+ return ctx.config;
4453
+ },
4454
+ async getTransformResult(id) {
4455
+ const result = await ctx.vitenode.transformRequest(id);
4456
+ if (result) {
4457
+ try {
4458
+ result.source = result.source || await promises.readFile(id, "utf-8");
4459
+ } catch {
4460
+ }
4461
+ return result;
4459
4462
  }
4460
- return result;
4461
- }
4462
- },
4463
- async getModuleGraph(id) {
4464
- const graph = {};
4465
- const externalized = /* @__PURE__ */ new Set();
4466
- const inlined = /* @__PURE__ */ new Set();
4467
- function clearId(id2) {
4468
- return (id2 == null ? void 0 : id2.replace(/\?v=\w+$/, "")) || "";
4469
- }
4470
- async function get(mod, seen = /* @__PURE__ */ new Map()) {
4471
- if (!mod || !mod.id)
4472
- return;
4473
- if (seen.has(mod))
4474
- return seen.get(mod);
4475
- let id2 = clearId(mod.id);
4476
- seen.set(mod, id2);
4477
- const rewrote = await ctx.vitenode.shouldExternalize(id2);
4478
- if (rewrote) {
4479
- id2 = rewrote;
4480
- externalized.add(id2);
4463
+ },
4464
+ async getModuleGraph(id) {
4465
+ const graph = {};
4466
+ const externalized = /* @__PURE__ */ new Set();
4467
+ const inlined = /* @__PURE__ */ new Set();
4468
+ function clearId(id2) {
4469
+ return (id2 == null ? void 0 : id2.replace(/\?v=\w+$/, "")) || "";
4470
+ }
4471
+ async function get(mod, seen = /* @__PURE__ */ new Map()) {
4472
+ if (!mod || !mod.id)
4473
+ return;
4474
+ if (seen.has(mod))
4475
+ return seen.get(mod);
4476
+ let id2 = clearId(mod.id);
4481
4477
  seen.set(mod, id2);
4482
- } else {
4483
- inlined.add(id2);
4478
+ const rewrote = await ctx.vitenode.shouldExternalize(id2);
4479
+ if (rewrote) {
4480
+ id2 = rewrote;
4481
+ externalized.add(id2);
4482
+ seen.set(mod, id2);
4483
+ } else {
4484
+ inlined.add(id2);
4485
+ }
4486
+ const mods = Array.from(mod.importedModules).filter((i) => i.id && !i.id.includes("/vitest/dist/"));
4487
+ graph[id2] = (await Promise.all(mods.map((m) => get(m, seen)))).filter(Boolean);
4488
+ return id2;
4484
4489
  }
4485
- const mods = Array.from(mod.importedModules).filter((i) => i.id && !i.id.includes("/vitest/dist/"));
4486
- graph[id2] = (await Promise.all(mods.map((m) => get(m, seen)))).filter(Boolean);
4487
- return id2;
4490
+ await get(ctx.server.moduleGraph.getModuleById(id));
4491
+ return {
4492
+ graph,
4493
+ externalized: Array.from(externalized),
4494
+ inlined: Array.from(inlined)
4495
+ };
4496
+ },
4497
+ updateSnapshot(file) {
4498
+ if (!file)
4499
+ return ctx.updateSnapshot();
4500
+ return ctx.updateSnapshot([file.filepath]);
4488
4501
  }
4489
- await get(ctx.server.moduleGraph.getModuleById(id));
4490
- return {
4491
- graph,
4492
- externalized: Array.from(externalized),
4493
- inlined: Array.from(inlined)
4494
- };
4495
4502
  },
4496
- updateSnapshot(file) {
4497
- if (!file)
4498
- return ctx.updateSnapshot();
4499
- return ctx.updateSnapshot([file.filepath]);
4503
+ {
4504
+ post: (msg) => ws.send(msg),
4505
+ on: (fn) => ws.on("message", fn),
4506
+ eventNames: ["onUserConsoleLog", "onFinished", "onCollected"],
4507
+ serialize: stringify,
4508
+ deserialize: parse$3
4500
4509
  }
4501
- }, {
4502
- post: (msg) => ws.send(msg),
4503
- on: (fn) => ws.on("message", fn),
4504
- eventNames: ["onUserConsoleLog", "onFinished", "onCollected"],
4505
- serialize: stringify,
4506
- deserialize: parse$3
4507
- });
4510
+ );
4508
4511
  clients.set(ws, rpc);
4509
4512
  ws.on("close", () => {
4510
4513
  clients.delete(ws);
@@ -1,173 +1,13 @@
1
+ import { Console } from 'console';
1
2
  import { importModule } from 'local-pkg';
2
3
 
3
- /*
4
- How it works:
5
- `this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.
6
- */
7
-
8
- class Node {
9
- value;
10
- next;
11
-
12
- constructor(value) {
13
- this.value = value;
14
- }
15
- }
16
-
17
- class Queue {
18
- #head;
19
- #tail;
20
- #size;
21
-
22
- constructor() {
23
- this.clear();
24
- }
25
-
26
- enqueue(value) {
27
- const node = new Node(value);
28
-
29
- if (this.#head) {
30
- this.#tail.next = node;
31
- this.#tail = node;
32
- } else {
33
- this.#head = node;
34
- this.#tail = node;
35
- }
36
-
37
- this.#size++;
38
- }
39
-
40
- dequeue() {
41
- const current = this.#head;
42
- if (!current) {
43
- return;
44
- }
45
-
46
- this.#head = this.#head.next;
47
- this.#size--;
48
- return current.value;
49
- }
50
-
51
- clear() {
52
- this.#head = undefined;
53
- this.#tail = undefined;
54
- this.#size = 0;
55
- }
56
-
57
- get size() {
58
- return this.#size;
59
- }
60
-
61
- * [Symbol.iterator]() {
62
- let current = this.#head;
63
-
64
- while (current) {
65
- yield current.value;
66
- current = current.next;
67
- }
68
- }
69
- }
70
-
71
- function pLimit(concurrency) {
72
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
73
- throw new TypeError('Expected `concurrency` to be a number from 1 and up');
74
- }
75
-
76
- const queue = new Queue();
77
- let activeCount = 0;
78
-
79
- const next = () => {
80
- activeCount--;
81
-
82
- if (queue.size > 0) {
83
- queue.dequeue()();
84
- }
85
- };
86
-
87
- const run = async (fn, resolve, args) => {
88
- activeCount++;
89
-
90
- const result = (async () => fn(...args))();
91
-
92
- resolve(result);
93
-
94
- try {
95
- await result;
96
- } catch {}
97
-
98
- next();
99
- };
100
-
101
- const enqueue = (fn, resolve, args) => {
102
- queue.enqueue(run.bind(undefined, fn, resolve, args));
103
-
104
- (async () => {
105
- // This function needs to wait until the next microtask before comparing
106
- // `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
107
- // when the run function is dequeued and called. The comparison in the if-statement
108
- // needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
109
- await Promise.resolve();
110
-
111
- if (activeCount < concurrency && queue.size > 0) {
112
- queue.dequeue()();
113
- }
114
- })();
115
- };
116
-
117
- const generator = (fn, ...args) => new Promise(resolve => {
118
- enqueue(fn, resolve, args);
119
- });
120
-
121
- Object.defineProperties(generator, {
122
- activeCount: {
123
- get: () => activeCount,
124
- },
125
- pendingCount: {
126
- get: () => queue.size,
127
- },
128
- clearQueue: {
129
- value: () => {
130
- queue.clear();
131
- },
132
- },
133
- });
134
-
135
- return generator;
136
- }
137
-
138
- const CoverageProviderMap = {
139
- c8: "@vitest/coverage-c8",
140
- istanbul: "@vitest/coverage-istanbul"
141
- };
142
- async function resolveCoverageProvider(provider) {
143
- if (typeof provider === "string") {
144
- const pkg = CoverageProviderMap[provider];
145
- if (!pkg)
146
- throw new Error(`Unknown coverage provider: ${provider}`);
147
- return await importModule(pkg);
148
- } else {
149
- return provider;
150
- }
151
- }
152
- async function getCoverageProvider(options) {
153
- if ((options == null ? void 0 : options.enabled) && (options == null ? void 0 : options.provider)) {
154
- const { getProvider } = await resolveCoverageProvider(options.provider);
155
- return await getProvider();
156
- }
157
- return null;
158
- }
159
- async function takeCoverageInsideWorker(options) {
160
- if (options.enabled && options.provider) {
161
- const { takeCoverage } = await resolveCoverageProvider(options.provider);
162
- return await (takeCoverage == null ? void 0 : takeCoverage());
163
- }
164
- }
165
-
166
4
  var node = {
167
5
  name: "node",
168
- async setup() {
6
+ async setup(global) {
7
+ global.console.Console = Console;
169
8
  return {
170
- teardown() {
9
+ teardown(global2) {
10
+ delete global2.console.Console;
171
11
  }
172
12
  };
173
13
  }
@@ -422,7 +262,9 @@ function isClassLikeName(name) {
422
262
  function populateGlobal(global, win, options = {}) {
423
263
  const { bindFunctions = false } = options;
424
264
  const keys = getWindowKeys(global, win);
425
- const originals = new Map(allowRewrite.filter((key) => key in global).map((key) => [key, global[key]]));
265
+ const originals = new Map(
266
+ allowRewrite.filter((key) => key in global).map((key) => [key, global[key]])
267
+ );
426
268
  const overrideObject = /* @__PURE__ */ new Map();
427
269
  for (const key of keys) {
428
270
  const boundFunction = bindFunctions && typeof win[key] === "function" && !isClassLikeName(key) && win[key].bind(win);
@@ -476,18 +318,21 @@ var jsdom = {
476
318
  cookieJar = false,
477
319
  ...restOptions
478
320
  } = jsdom;
479
- const dom = new JSDOM(html, {
480
- pretendToBeVisual,
481
- resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
482
- runScripts,
483
- url,
484
- virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : void 0,
485
- cookieJar: cookieJar ? new CookieJar() : void 0,
486
- includeNodeLocations,
487
- contentType,
488
- userAgent,
489
- ...restOptions
490
- });
321
+ const dom = new JSDOM(
322
+ html,
323
+ {
324
+ pretendToBeVisual,
325
+ resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
326
+ runScripts,
327
+ url,
328
+ virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : void 0,
329
+ cookieJar: cookieJar ? new CookieJar() : void 0,
330
+ includeNodeLocations,
331
+ contentType,
332
+ userAgent,
333
+ ...restOptions
334
+ }
335
+ );
491
336
  const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true });
492
337
  return {
493
338
  teardown(global2) {
@@ -547,5 +392,12 @@ const envPackageNames = {
547
392
  "happy-dom": "happy-dom",
548
393
  "edge-runtime": "@edge-runtime/vm"
549
394
  };
395
+ const getEnvPackageName = (env) => {
396
+ if (env === "node")
397
+ return null;
398
+ if (env in envPackageNames)
399
+ return envPackageNames[env];
400
+ return `vitest-environment-${env}`;
401
+ };
550
402
 
551
- export { CoverageProviderMap as C, envPackageNames as a, envs as b, environments as e, getCoverageProvider as g, pLimit as p, takeCoverageInsideWorker as t };
403
+ export { envs as a, environments as e, getEnvPackageName as g, populateGlobal as p };