vitest 0.10.5 → 0.12.1
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.
- package/dist/{chunk-api-setup.2c4e9375.js → chunk-api-setup.a6d28d1e.js} +4 -4
- package/dist/{chunk-constants.54c46a47.js → chunk-constants.07c1f709.js} +1 -1
- package/dist/{chunk-defaults.c143550b.js → chunk-defaults.9b4b1577.js} +17 -3
- package/dist/{chunk-install-pkg.73b84ae1.js → chunk-install-pkg.fd8d1022.js} +1 -1
- package/dist/{chunk-integrations-globals.d3383e75.js → chunk-integrations-globals.bc12987e.js} +8 -8
- package/dist/{chunk-integrations-spy.f036df6f.js → chunk-integrations-spy.bee66426.js} +1 -1
- package/dist/{chunk-runtime-chain.d0bd6df6.js → chunk-runtime-chain.da3a4a85.js} +116 -90
- package/dist/{chunk-runtime-mocker.0871693a.js → chunk-runtime-mocker.c6de56c0.js} +15 -8
- package/dist/{chunk-runtime-rpc.710f6f7f.js → chunk-runtime-rpc.5148195e.js} +1 -1
- package/dist/{chunk-utils-global.eb31f3da.js → chunk-utils-global.7092f9ed.js} +4 -4
- package/dist/{chunk-utils-timers.27e0c6e9.js → chunk-utils-timers.d1b169ca.js} +1 -1
- package/dist/{chunk-vite-node-externalize.965e6527.js → chunk-vite-node-externalize.dcc18b18.js} +13 -15
- package/dist/{chunk-vite-node-utils.6b0ec89a.js → chunk-vite-node-utils.ebc9e052.js} +17 -8
- package/dist/cli.js +7 -7
- package/dist/config.cjs +15 -1
- package/dist/config.d.ts +67 -0
- package/dist/config.js +15 -1
- package/dist/entry.js +7 -7
- package/dist/index.d.ts +84 -13
- package/dist/index.js +5 -5
- package/dist/node.d.ts +89 -14
- package/dist/node.js +8 -8
- package/dist/spy.js +1 -1
- package/dist/{vendor-entry.9551d577.js → vendor-entry.3062f869.js} +181 -74
- package/dist/{vendor-index.40be925a.js → vendor-index.6c69a0a8.js} +0 -0
- package/dist/worker.js +14 -15
- package/package.json +4 -4
package/dist/node.d.ts
CHANGED
|
@@ -211,6 +211,72 @@ declare type OldPlugin = {
|
|
|
211
211
|
declare type Plugin = NewPlugin | OldPlugin;
|
|
212
212
|
declare type Plugins = Array<Plugin>;
|
|
213
213
|
|
|
214
|
+
// Type definitions for @sinonjs/fake-timers 8.1
|
|
215
|
+
// Project: https://github.com/sinonjs/fake-timers
|
|
216
|
+
// Definitions by: Wim Looman <https://github.com/Nemo157>
|
|
217
|
+
// Rogier Schouten <https://github.com/rogierschouten>
|
|
218
|
+
// Yishai Zehavi <https://github.com/zyishai>
|
|
219
|
+
// Remco Haszing <https://github.com/remcohaszing>
|
|
220
|
+
// Jaden Simon <https://github.com/JadenSimon>
|
|
221
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
222
|
+
// TypeScript Version: 2.3
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Names of clock methods that may be faked by install.
|
|
226
|
+
*/
|
|
227
|
+
type FakeMethod =
|
|
228
|
+
| 'setTimeout'
|
|
229
|
+
| 'clearTimeout'
|
|
230
|
+
| 'setImmediate'
|
|
231
|
+
| 'clearImmediate'
|
|
232
|
+
| 'setInterval'
|
|
233
|
+
| 'clearInterval'
|
|
234
|
+
| 'Date'
|
|
235
|
+
| 'nextTick'
|
|
236
|
+
| 'hrtime'
|
|
237
|
+
| 'requestAnimationFrame'
|
|
238
|
+
| 'cancelAnimationFrame'
|
|
239
|
+
| 'requestIdleCallback'
|
|
240
|
+
| 'cancelIdleCallback'
|
|
241
|
+
| 'performance'
|
|
242
|
+
| 'queueMicrotask';
|
|
243
|
+
|
|
244
|
+
interface FakeTimerInstallOpts {
|
|
245
|
+
/**
|
|
246
|
+
* Installs fake timers with the specified unix epoch (default: 0)
|
|
247
|
+
*/
|
|
248
|
+
now?: number | Date | undefined;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* An array with names of global methods and APIs to fake. By default, `@sinonjs/fake-timers` does not replace `nextTick()` and `queueMicrotask()`.
|
|
252
|
+
* For instance, `FakeTimers.install({ toFake: ['setTimeout', 'nextTick'] })` will fake only `setTimeout()` and `nextTick()`
|
|
253
|
+
*/
|
|
254
|
+
toFake?: FakeMethod[] | undefined;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The maximum number of timers that will be run when calling runAll() (default: 1000)
|
|
258
|
+
*/
|
|
259
|
+
loopLimit?: number | undefined;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Tells @sinonjs/fake-timers to increment mocked time automatically based on the real system time shift (e.g. the mocked time will be incremented by
|
|
263
|
+
* 20ms for every 20ms change in the real system time) (default: false)
|
|
264
|
+
*/
|
|
265
|
+
shouldAdvanceTime?: boolean | undefined;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Relevant only when using with shouldAdvanceTime: true. increment mocked time by advanceTimeDelta ms every advanceTimeDelta ms change
|
|
269
|
+
* in the real system time (default: 20)
|
|
270
|
+
*/
|
|
271
|
+
advanceTimeDelta?: number | undefined;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Tells FakeTimers to clear 'native' (i.e. not fake) timers by delegating to their respective handlers. These are not cleared by
|
|
275
|
+
* default, leading to potentially unexpected behavior if timers existed prior to installing FakeTimers. (default: false)
|
|
276
|
+
*/
|
|
277
|
+
shouldClearNativeTimers?: boolean | undefined;
|
|
278
|
+
}
|
|
279
|
+
|
|
214
280
|
declare abstract class BaseReporter implements Reporter {
|
|
215
281
|
start: number;
|
|
216
282
|
end: number;
|
|
@@ -405,6 +471,7 @@ interface C8Options {
|
|
|
405
471
|
skipFull?: boolean;
|
|
406
472
|
extension?: string | string[];
|
|
407
473
|
all?: boolean;
|
|
474
|
+
src?: string[];
|
|
408
475
|
100?: boolean;
|
|
409
476
|
lines?: number;
|
|
410
477
|
functions?: number;
|
|
@@ -520,6 +587,7 @@ declare type TaskResultPack = [id: string, result: TaskResult | undefined];
|
|
|
520
587
|
interface Suite extends TaskBase {
|
|
521
588
|
type: 'suite';
|
|
522
589
|
tasks: Task[];
|
|
590
|
+
filepath?: string;
|
|
523
591
|
}
|
|
524
592
|
interface File extends Suite {
|
|
525
593
|
filepath: string;
|
|
@@ -535,8 +603,8 @@ interface Test<ExtraContext = {}> extends TaskBase {
|
|
|
535
603
|
declare type Task = Test | Suite | File;
|
|
536
604
|
declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return | void>;
|
|
537
605
|
interface SuiteHooks {
|
|
538
|
-
beforeAll: HookListener<[Suite], () => Awaitable<void>>[];
|
|
539
|
-
afterAll: HookListener<[Suite]>[];
|
|
606
|
+
beforeAll: HookListener<[Suite | File], () => Awaitable<void>>[];
|
|
607
|
+
afterAll: HookListener<[Suite | File]>[];
|
|
540
608
|
beforeEach: HookListener<[TestContext, Suite], () => Awaitable<void>>[];
|
|
541
609
|
afterEach: HookListener<[TestContext, Suite]>[];
|
|
542
610
|
}
|
|
@@ -769,7 +837,7 @@ interface InlineConfig {
|
|
|
769
837
|
/**
|
|
770
838
|
* Pattern of file paths to be ignore from triggering watch rerun
|
|
771
839
|
*
|
|
772
|
-
* @default [
|
|
840
|
+
* @default [/\/node_modules\//, /\/dist\//]
|
|
773
841
|
*/
|
|
774
842
|
watchIgnore?: (string | RegExp)[];
|
|
775
843
|
/**
|
|
@@ -854,10 +922,22 @@ interface InlineConfig {
|
|
|
854
922
|
* Resolve custom snapshot path
|
|
855
923
|
*/
|
|
856
924
|
resolveSnapshotPath?: (path: string, extension: string) => string;
|
|
925
|
+
/**
|
|
926
|
+
* Pass with no tests
|
|
927
|
+
*/
|
|
928
|
+
passWithNoTests?: boolean;
|
|
929
|
+
/**
|
|
930
|
+
* Allow tests and suites that are marked as only
|
|
931
|
+
*/
|
|
932
|
+
allowOnly?: boolean;
|
|
857
933
|
/**
|
|
858
934
|
* Show heap usage after each test. Usefull for debugging memory leaks.
|
|
859
935
|
*/
|
|
860
936
|
logHeapUsage?: boolean;
|
|
937
|
+
/**
|
|
938
|
+
* Options for @sinon/fake-timers
|
|
939
|
+
*/
|
|
940
|
+
fakeTimers?: FakeTimerInstallOpts;
|
|
861
941
|
}
|
|
862
942
|
interface UserConfig extends InlineConfig {
|
|
863
943
|
/**
|
|
@@ -874,14 +954,6 @@ interface UserConfig extends InlineConfig {
|
|
|
874
954
|
* Use happy-dom
|
|
875
955
|
*/
|
|
876
956
|
dom?: boolean;
|
|
877
|
-
/**
|
|
878
|
-
* Pass with no tests
|
|
879
|
-
*/
|
|
880
|
-
passWithNoTests?: boolean;
|
|
881
|
-
/**
|
|
882
|
-
* Allow tests and suites that are marked as only
|
|
883
|
-
*/
|
|
884
|
-
allowOnly?: boolean;
|
|
885
957
|
/**
|
|
886
958
|
* Run tests that cover a list of source files
|
|
887
959
|
*/
|
|
@@ -926,7 +998,6 @@ declare class SnapshotManager {
|
|
|
926
998
|
declare type RunWithFiles = (files: string[], invalidates?: string[]) => Promise<void>;
|
|
927
999
|
interface WorkerPool {
|
|
928
1000
|
runTests: RunWithFiles;
|
|
929
|
-
collectTests: RunWithFiles;
|
|
930
1001
|
close: () => Promise<void>;
|
|
931
1002
|
}
|
|
932
1003
|
|
|
@@ -1016,6 +1087,10 @@ interface CliOptions extends UserConfig {
|
|
|
1016
1087
|
declare function startVitest(cliFilters: string[], options: CliOptions, viteOverrides?: UserConfig$1): Promise<boolean>;
|
|
1017
1088
|
|
|
1018
1089
|
declare type Callback = (...args: any[]) => unknown;
|
|
1090
|
+
interface ViteRunnerRequest {
|
|
1091
|
+
(dep: string): any;
|
|
1092
|
+
callstack: string[];
|
|
1093
|
+
}
|
|
1019
1094
|
declare class VitestMocker {
|
|
1020
1095
|
options: ExecuteOptions;
|
|
1021
1096
|
private moduleCache;
|
|
@@ -1024,7 +1099,7 @@ declare class VitestMocker {
|
|
|
1024
1099
|
private request;
|
|
1025
1100
|
private root;
|
|
1026
1101
|
private callbacks;
|
|
1027
|
-
constructor(options: ExecuteOptions, moduleCache: ModuleCacheMap, request?:
|
|
1102
|
+
constructor(options: ExecuteOptions, moduleCache: ModuleCacheMap, request?: ViteRunnerRequest);
|
|
1028
1103
|
get mockMap(): MockMap;
|
|
1029
1104
|
on(event: string, cb: Callback): void;
|
|
1030
1105
|
private emit;
|
|
@@ -1049,7 +1124,7 @@ declare class VitestMocker {
|
|
|
1049
1124
|
requestWithMock(dep: string): Promise<any>;
|
|
1050
1125
|
queueMock(id: string, importer: string, factory?: () => unknown): void;
|
|
1051
1126
|
queueUnmock(id: string, importer: string): void;
|
|
1052
|
-
withRequest(request:
|
|
1127
|
+
withRequest(request: ViteRunnerRequest): VitestMocker;
|
|
1053
1128
|
}
|
|
1054
1129
|
|
|
1055
1130
|
interface ExecuteOptions extends ViteNodeRunnerOptions {
|
package/dist/node.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.
|
|
2
|
-
export { V as VitestRunner } from './chunk-runtime-mocker.
|
|
1
|
+
export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.dcc18b18.js';
|
|
2
|
+
export { V as VitestRunner } from './chunk-runtime-mocker.c6de56c0.js';
|
|
3
3
|
import 'buffer';
|
|
4
4
|
import 'path';
|
|
5
5
|
import 'child_process';
|
|
6
6
|
import 'process';
|
|
7
|
-
import './vendor-index.
|
|
7
|
+
import './vendor-index.6c69a0a8.js';
|
|
8
8
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
9
9
|
import 'fs';
|
|
10
10
|
import 'assert';
|
|
@@ -13,19 +13,19 @@ import 'stream';
|
|
|
13
13
|
import 'util';
|
|
14
14
|
import 'url';
|
|
15
15
|
import 'os';
|
|
16
|
-
import './chunk-utils-global.
|
|
16
|
+
import './chunk-utils-global.7092f9ed.js';
|
|
17
17
|
import 'tty';
|
|
18
18
|
import 'local-pkg';
|
|
19
19
|
import 'vite';
|
|
20
|
-
import './chunk-constants.
|
|
20
|
+
import './chunk-constants.07c1f709.js';
|
|
21
21
|
import 'readline';
|
|
22
|
-
import './chunk-vite-node-utils.
|
|
22
|
+
import './chunk-vite-node-utils.ebc9e052.js';
|
|
23
23
|
import 'module';
|
|
24
24
|
import 'vm';
|
|
25
|
-
import './chunk-defaults.
|
|
25
|
+
import './chunk-defaults.9b4b1577.js';
|
|
26
26
|
import 'worker_threads';
|
|
27
27
|
import 'tinypool';
|
|
28
28
|
import 'perf_hooks';
|
|
29
|
-
import './chunk-utils-timers.
|
|
29
|
+
import './chunk-utils-timers.d1b169ca.js';
|
|
30
30
|
import './chunk-magic-string.d5e0e473.js';
|
|
31
31
|
import './vendor-index.405e58ef.js';
|
package/dist/spy.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { f as fn, i as isMockFunction, a as spies, s as spyOn } from './chunk-integrations-spy.
|
|
1
|
+
export { f as fn, i as isMockFunction, a as spies, s as spyOn } from './chunk-integrations-spy.bee66426.js';
|
|
2
2
|
import 'tinyspy';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { promises } from 'fs';
|
|
2
|
-
import {
|
|
2
|
+
import { a as getWorkerState, t as toArray, G as clone, E as getType, l as relative, A as stdout, H as partitionSuiteChildren, I as hasTests, q as hasFailed, o as getFullName, r as resetModules } from './chunk-utils-global.7092f9ed.js';
|
|
3
3
|
import { Console } from 'console';
|
|
4
4
|
import { Writable } from 'stream';
|
|
5
5
|
import { importModule } from 'local-pkg';
|
|
6
|
-
import { s as suite, t as test, d as describe, i as it, r as runOnce, a as isFirstRun, b as beforeAll, c as afterAll, e as beforeEach, f as afterEach, w as withCallback, g as createExpect, h as expect, v as vitest, j as vi, k as getRunningMode, l as isWatchMode, m as resetRunOnceCounter, R as RealDate, n as clearCollectorContext, o as defaultSuite, p as setHooks, q as getHooks, u as collectorContext, x as getSnapshotClient, y as setState, z as getFn, A as getState } from './chunk-runtime-chain.
|
|
6
|
+
import { s as suite, t as test, d as describe, i as it, r as runOnce, a as isFirstRun, b as beforeAll, c as afterAll, e as beforeEach, f as afterEach, w as withCallback, g as createExpect, h as expect, v as vitest, j as vi, k as getRunningMode, l as isWatchMode, m as resetRunOnceCounter, R as RealDate, n as clearCollectorContext, o as defaultSuite, p as setHooks, q as getHooks, u as collectorContext, x as getSnapshotClient, y as setState, z as getFn, A as getState } from './chunk-runtime-chain.da3a4a85.js';
|
|
7
7
|
import chai, { assert, should, util } from 'chai';
|
|
8
|
-
import { r as rpc } from './chunk-runtime-rpc.
|
|
9
|
-
import { d as clearTimeout, c as setTimeout, s as stringify } from './chunk-utils-timers.
|
|
10
|
-
import { t as takeCoverage } from './chunk-defaults.
|
|
8
|
+
import { r as rpc } from './chunk-runtime-rpc.5148195e.js';
|
|
9
|
+
import { d as clearTimeout, c as setTimeout, s as stringify } from './chunk-utils-timers.d1b169ca.js';
|
|
10
|
+
import { t as takeCoverage } from './chunk-defaults.9b4b1577.js';
|
|
11
11
|
import { createHash } from 'crypto';
|
|
12
12
|
import { format } from 'util';
|
|
13
13
|
|
|
@@ -212,6 +212,7 @@ const OTHER_KEYS = [
|
|
|
212
212
|
"atob",
|
|
213
213
|
"blur",
|
|
214
214
|
"btoa",
|
|
215
|
+
"cancelAnimationFrame",
|
|
215
216
|
"close",
|
|
216
217
|
"confirm",
|
|
217
218
|
"createPopup",
|
|
@@ -240,6 +241,7 @@ const OTHER_KEYS = [
|
|
|
240
241
|
"print",
|
|
241
242
|
"prompt",
|
|
242
243
|
"removeEventListener",
|
|
244
|
+
"requestAnimationFrame",
|
|
243
245
|
"resizeBy",
|
|
244
246
|
"resizeTo",
|
|
245
247
|
"screen",
|
|
@@ -262,20 +264,118 @@ const OTHER_KEYS = [
|
|
|
262
264
|
];
|
|
263
265
|
const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
|
|
264
266
|
|
|
265
|
-
const allowRewrite =
|
|
267
|
+
const allowRewrite = [
|
|
266
268
|
"Event",
|
|
267
269
|
"EventTarget"
|
|
268
|
-
]
|
|
270
|
+
];
|
|
271
|
+
const skipKeys = [
|
|
272
|
+
"window",
|
|
273
|
+
"self",
|
|
274
|
+
"top",
|
|
275
|
+
"parent"
|
|
276
|
+
];
|
|
269
277
|
function getWindowKeys(global, win) {
|
|
270
278
|
const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => {
|
|
271
|
-
if (k.startsWith("_"))
|
|
279
|
+
if (k.startsWith("_") || skipKeys.includes(k))
|
|
272
280
|
return false;
|
|
273
281
|
if (k in global)
|
|
274
|
-
return allowRewrite.
|
|
282
|
+
return allowRewrite.includes(k);
|
|
275
283
|
return true;
|
|
276
284
|
}));
|
|
277
285
|
return keys;
|
|
278
286
|
}
|
|
287
|
+
function populateGlobal(global, win, options = {}) {
|
|
288
|
+
const { bindFunctions = false } = options;
|
|
289
|
+
const keys = getWindowKeys(global, win);
|
|
290
|
+
const overrideObject = /* @__PURE__ */ new Map();
|
|
291
|
+
for (const key of keys) {
|
|
292
|
+
const shouldBind = bindFunctions && typeof win[key] === "function";
|
|
293
|
+
Object.defineProperty(global, key, {
|
|
294
|
+
get() {
|
|
295
|
+
if (overrideObject.has(key))
|
|
296
|
+
return overrideObject.get(key);
|
|
297
|
+
if (shouldBind)
|
|
298
|
+
return win[key].bind(win);
|
|
299
|
+
return win[key];
|
|
300
|
+
},
|
|
301
|
+
set(v) {
|
|
302
|
+
overrideObject.set(key, v);
|
|
303
|
+
},
|
|
304
|
+
configurable: true
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
const globalKeys = /* @__PURE__ */ new Set(["window", "self", "top", "parent"]);
|
|
308
|
+
const globalProxy = new Proxy(win.window, {
|
|
309
|
+
get(target, p, receiver) {
|
|
310
|
+
if (overrideObject.has(p))
|
|
311
|
+
return overrideObject.get(p);
|
|
312
|
+
return Reflect.get(target, p, receiver);
|
|
313
|
+
},
|
|
314
|
+
set(target, p, value, receiver) {
|
|
315
|
+
try {
|
|
316
|
+
Object.defineProperty(global, p, {
|
|
317
|
+
get: () => overrideObject.get(p),
|
|
318
|
+
set: (value2) => overrideObject.set(p, value2),
|
|
319
|
+
configurable: true
|
|
320
|
+
});
|
|
321
|
+
overrideObject.set(p, value);
|
|
322
|
+
Reflect.set(target, p, value, receiver);
|
|
323
|
+
} catch {
|
|
324
|
+
}
|
|
325
|
+
return true;
|
|
326
|
+
},
|
|
327
|
+
deleteProperty(target, p) {
|
|
328
|
+
Reflect.deleteProperty(global, p);
|
|
329
|
+
overrideObject.delete(p);
|
|
330
|
+
return Reflect.deleteProperty(target, p);
|
|
331
|
+
},
|
|
332
|
+
defineProperty(target, p, attributes) {
|
|
333
|
+
if (attributes.writable && "value" in attributes) ; else if (attributes.get) {
|
|
334
|
+
overrideObject.delete(p);
|
|
335
|
+
Reflect.defineProperty(global, p, attributes);
|
|
336
|
+
}
|
|
337
|
+
return Reflect.defineProperty(target, p, attributes);
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
globalKeys.forEach((key) => {
|
|
341
|
+
if (!win[key])
|
|
342
|
+
return;
|
|
343
|
+
Object.defineProperty(global, key, {
|
|
344
|
+
get() {
|
|
345
|
+
return globalProxy;
|
|
346
|
+
},
|
|
347
|
+
configurable: true
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
const globalThisProxy = new Proxy(global.globalThis, {
|
|
351
|
+
set(target, key, value, receiver) {
|
|
352
|
+
overrideObject.set(key, value);
|
|
353
|
+
return Reflect.set(target, key, value, receiver);
|
|
354
|
+
},
|
|
355
|
+
deleteProperty(target, key) {
|
|
356
|
+
overrideObject.delete(key);
|
|
357
|
+
return Reflect.deleteProperty(target, key);
|
|
358
|
+
},
|
|
359
|
+
defineProperty(target, p, attributes) {
|
|
360
|
+
if (attributes.writable && "value" in attributes) ; else if (attributes.get && !globalKeys.has(p)) {
|
|
361
|
+
globalKeys.forEach((key) => {
|
|
362
|
+
if (win[key])
|
|
363
|
+
Object.defineProperty(win[key], p, attributes);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
return Reflect.defineProperty(target, p, attributes);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
global.globalThis = globalThisProxy;
|
|
370
|
+
if (global.global)
|
|
371
|
+
global.global = globalThisProxy;
|
|
372
|
+
skipKeys.forEach((k) => keys.add(k));
|
|
373
|
+
return {
|
|
374
|
+
keys,
|
|
375
|
+
skipKeys,
|
|
376
|
+
allowRewrite
|
|
377
|
+
};
|
|
378
|
+
}
|
|
279
379
|
|
|
280
380
|
var __defProp$1 = Object.defineProperty;
|
|
281
381
|
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
@@ -348,24 +448,12 @@ var jsdom = {
|
|
|
348
448
|
contentType,
|
|
349
449
|
userAgent
|
|
350
450
|
}, restOptions));
|
|
351
|
-
const keys =
|
|
352
|
-
const
|
|
353
|
-
for (const key of keys) {
|
|
354
|
-
Object.defineProperty(global, key, {
|
|
355
|
-
get() {
|
|
356
|
-
if (overrideObject.has(key))
|
|
357
|
-
return overrideObject.get(key);
|
|
358
|
-
return dom.window[key];
|
|
359
|
-
},
|
|
360
|
-
set(v) {
|
|
361
|
-
overrideObject.set(key, v);
|
|
362
|
-
},
|
|
363
|
-
configurable: true
|
|
364
|
-
});
|
|
365
|
-
}
|
|
451
|
+
const { keys, allowRewrite } = populateGlobal(global, dom.window);
|
|
452
|
+
const originals = new Map(allowRewrite.map(([key]) => [key, global[key]]));
|
|
366
453
|
return {
|
|
367
454
|
teardown(global2) {
|
|
368
455
|
keys.forEach((key) => delete global2[key]);
|
|
456
|
+
originals.forEach((v, k) => global2[k] = v);
|
|
369
457
|
}
|
|
370
458
|
};
|
|
371
459
|
}
|
|
@@ -376,25 +464,13 @@ var happy = {
|
|
|
376
464
|
async setup(global) {
|
|
377
465
|
const { Window, GlobalWindow } = await importModule("happy-dom");
|
|
378
466
|
const win = new (GlobalWindow || Window)();
|
|
379
|
-
const keys =
|
|
380
|
-
const
|
|
381
|
-
for (const key of keys) {
|
|
382
|
-
Object.defineProperty(global, key, {
|
|
383
|
-
get() {
|
|
384
|
-
if (overrideObject.has(key))
|
|
385
|
-
return overrideObject.get(key);
|
|
386
|
-
return win[key];
|
|
387
|
-
},
|
|
388
|
-
set(v) {
|
|
389
|
-
overrideObject.set(key, v);
|
|
390
|
-
},
|
|
391
|
-
configurable: true
|
|
392
|
-
});
|
|
393
|
-
}
|
|
467
|
+
const { keys, allowRewrite } = populateGlobal(global, win, { bindFunctions: true });
|
|
468
|
+
const originals = new Map(allowRewrite.map(([key]) => [key, global[key]]));
|
|
394
469
|
return {
|
|
395
470
|
teardown(global2) {
|
|
396
471
|
win.happyDOM.cancelAsync();
|
|
397
472
|
keys.forEach((key) => delete global2[key]);
|
|
473
|
+
originals.forEach((v, k) => global2[k] = v);
|
|
398
474
|
}
|
|
399
475
|
};
|
|
400
476
|
}
|
|
@@ -419,7 +495,7 @@ async function setupGlobalEnv(config) {
|
|
|
419
495
|
globalSetup = true;
|
|
420
496
|
setupConsoleLogSpy();
|
|
421
497
|
if (config.globals)
|
|
422
|
-
(await import('./chunk-integrations-globals.
|
|
498
|
+
(await import('./chunk-integrations-globals.bc12987e.js')).registerApiGlobally();
|
|
423
499
|
}
|
|
424
500
|
function setupDefines(defines) {
|
|
425
501
|
for (const key in defines)
|
|
@@ -446,33 +522,39 @@ function setupConsoleLogSpy() {
|
|
|
446
522
|
}
|
|
447
523
|
function sendStdout(taskId) {
|
|
448
524
|
const buffer = stdoutBuffer.get(taskId);
|
|
449
|
-
if (buffer)
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
timer.stdoutTime
|
|
460
|
-
|
|
525
|
+
if (!buffer)
|
|
526
|
+
return;
|
|
527
|
+
const content = buffer.map((i) => String(i)).join("");
|
|
528
|
+
if (!content.trim())
|
|
529
|
+
return;
|
|
530
|
+
const timer = timers.get(taskId);
|
|
531
|
+
rpc().onUserConsoleLog({
|
|
532
|
+
type: "stdout",
|
|
533
|
+
content,
|
|
534
|
+
taskId,
|
|
535
|
+
time: timer.stdoutTime || RealDate.now(),
|
|
536
|
+
size: buffer.length
|
|
537
|
+
});
|
|
538
|
+
stdoutBuffer.set(taskId, []);
|
|
539
|
+
timer.stdoutTime = 0;
|
|
461
540
|
}
|
|
462
541
|
function sendStderr(taskId) {
|
|
463
542
|
const buffer = stderrBuffer.get(taskId);
|
|
464
|
-
if (buffer)
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
timer.stderrTime
|
|
475
|
-
|
|
543
|
+
if (!buffer)
|
|
544
|
+
return;
|
|
545
|
+
const content = buffer.map((i) => String(i)).join("");
|
|
546
|
+
if (!content.trim())
|
|
547
|
+
return;
|
|
548
|
+
const timer = timers.get(taskId);
|
|
549
|
+
rpc().onUserConsoleLog({
|
|
550
|
+
type: "stderr",
|
|
551
|
+
content,
|
|
552
|
+
taskId,
|
|
553
|
+
time: timer.stderrTime || RealDate.now(),
|
|
554
|
+
size: buffer.length
|
|
555
|
+
});
|
|
556
|
+
stderrBuffer.set(taskId, []);
|
|
557
|
+
timer.stderrTime = 0;
|
|
476
558
|
}
|
|
477
559
|
const stdout = new Writable({
|
|
478
560
|
write(data, encoding, callback) {
|
|
@@ -576,6 +658,9 @@ function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
|
|
|
576
658
|
return clone2;
|
|
577
659
|
}
|
|
578
660
|
}
|
|
661
|
+
function normalizeErrorMessage(message) {
|
|
662
|
+
return message.replace(/__vite_ssr_import_\d+__\./g, "");
|
|
663
|
+
}
|
|
579
664
|
function processError(err) {
|
|
580
665
|
if (!err)
|
|
581
666
|
return err;
|
|
@@ -592,6 +677,10 @@ function processError(err) {
|
|
|
592
677
|
err.expected = stringify(err.expected);
|
|
593
678
|
if (typeof err.actual !== "string")
|
|
594
679
|
err.actual = stringify(err.actual);
|
|
680
|
+
if (typeof err.message === "string")
|
|
681
|
+
err.message = normalizeErrorMessage(err.message);
|
|
682
|
+
if (typeof err.cause === "object" && err.cause.message === "string")
|
|
683
|
+
err.cause.message = normalizeErrorMessage(err.cause.message);
|
|
595
684
|
try {
|
|
596
685
|
return serializeError(err);
|
|
597
686
|
} catch (e) {
|
|
@@ -970,21 +1059,39 @@ function clearModuleMocks() {
|
|
|
970
1059
|
}
|
|
971
1060
|
|
|
972
1061
|
async function run(files, config) {
|
|
973
|
-
var _a;
|
|
974
1062
|
await setupGlobalEnv(config);
|
|
975
1063
|
const workerState = getWorkerState();
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
1064
|
+
const envs = ["node", "jsdom", "happy-dom"];
|
|
1065
|
+
const filesWithEnv = await Promise.all(files.map(async (file) => {
|
|
1066
|
+
var _a;
|
|
979
1067
|
const code = await promises.readFile(file, "utf-8");
|
|
980
1068
|
const env = ((_a = code.match(/@(?:vitest|jest)-environment\s+?([\w-]+)\b/)) == null ? void 0 : _a[1]) || config.environment || "node";
|
|
981
|
-
if (!
|
|
982
|
-
throw new Error(`Unsupported environment: ${env}`);
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1069
|
+
if (!envs.includes(env))
|
|
1070
|
+
throw new Error(`Unsupported environment: "${env}" in ${file}`);
|
|
1071
|
+
return {
|
|
1072
|
+
file,
|
|
1073
|
+
env
|
|
1074
|
+
};
|
|
1075
|
+
}));
|
|
1076
|
+
const filesByEnv = filesWithEnv.reduce((acc, { file, env }) => {
|
|
1077
|
+
acc[env] || (acc[env] = []);
|
|
1078
|
+
acc[env].push(file);
|
|
1079
|
+
return acc;
|
|
1080
|
+
}, {});
|
|
1081
|
+
for (const env of envs) {
|
|
1082
|
+
const environment = env;
|
|
1083
|
+
const files2 = filesByEnv[environment];
|
|
1084
|
+
if (!files2 || !files2.length)
|
|
1085
|
+
continue;
|
|
1086
|
+
await withEnv(environment, config.environmentOptions || {}, async () => {
|
|
1087
|
+
for (const file of files2) {
|
|
1088
|
+
workerState.mockMap.clear();
|
|
1089
|
+
resetModules();
|
|
1090
|
+
workerState.filepath = file;
|
|
1091
|
+
await startTests([file], config);
|
|
1092
|
+
workerState.filepath = void 0;
|
|
1093
|
+
}
|
|
986
1094
|
});
|
|
987
|
-
workerState.filepath = void 0;
|
|
988
1095
|
}
|
|
989
1096
|
}
|
|
990
1097
|
|
|
File without changes
|
package/dist/worker.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as createBirpc, M as ModuleCacheMap } from './chunk-vite-node-utils.
|
|
3
|
-
import { d as distDir } from './chunk-constants.
|
|
4
|
-
import { e as executeInViteNode } from './chunk-runtime-mocker.
|
|
5
|
-
import { r as rpc } from './chunk-runtime-rpc.
|
|
1
|
+
import { h as resolve, a as getWorkerState, A as stdout } from './chunk-utils-global.7092f9ed.js';
|
|
2
|
+
import { c as createBirpc, M as ModuleCacheMap } from './chunk-vite-node-utils.ebc9e052.js';
|
|
3
|
+
import { d as distDir } from './chunk-constants.07c1f709.js';
|
|
4
|
+
import { e as executeInViteNode } from './chunk-runtime-mocker.c6de56c0.js';
|
|
5
|
+
import { r as rpc } from './chunk-runtime-rpc.5148195e.js';
|
|
6
6
|
import 'tty';
|
|
7
7
|
import 'local-pkg';
|
|
8
8
|
import 'path';
|
|
@@ -32,7 +32,7 @@ async function startViteNode(ctx) {
|
|
|
32
32
|
rpc().onUnhandledRejection(err);
|
|
33
33
|
});
|
|
34
34
|
const { config } = ctx;
|
|
35
|
-
const { run: run2
|
|
35
|
+
const { run: run2 } = (await executeInViteNode({
|
|
36
36
|
files: [
|
|
37
37
|
resolve(distDir, "entry.js")
|
|
38
38
|
],
|
|
@@ -48,7 +48,7 @@ async function startViteNode(ctx) {
|
|
|
48
48
|
root: config.root,
|
|
49
49
|
base: config.base
|
|
50
50
|
}))[0];
|
|
51
|
-
_viteNode = { run: run2
|
|
51
|
+
_viteNode = { run: run2 };
|
|
52
52
|
return _viteNode;
|
|
53
53
|
}
|
|
54
54
|
function init(ctx) {
|
|
@@ -72,19 +72,18 @@ function init(ctx) {
|
|
|
72
72
|
}
|
|
73
73
|
})
|
|
74
74
|
};
|
|
75
|
-
if (ctx.invalidates)
|
|
76
|
-
ctx.invalidates.forEach((i) =>
|
|
75
|
+
if (ctx.invalidates) {
|
|
76
|
+
ctx.invalidates.forEach((i) => {
|
|
77
|
+
moduleCache.delete(i);
|
|
78
|
+
moduleCache.delete(`${i}__mock`);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
77
81
|
ctx.files.forEach((i) => moduleCache.delete(i));
|
|
78
82
|
}
|
|
79
|
-
async function collect(ctx) {
|
|
80
|
-
init(ctx);
|
|
81
|
-
const { collect: collect2 } = await startViteNode(ctx);
|
|
82
|
-
return collect2(ctx.files, ctx.config);
|
|
83
|
-
}
|
|
84
83
|
async function run(ctx) {
|
|
85
84
|
init(ctx);
|
|
86
85
|
const { run: run2 } = await startViteNode(ctx);
|
|
87
86
|
return run2(ctx.files, ctx.config);
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
export {
|
|
89
|
+
export { run };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.1",
|
|
5
5
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"vite",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"@types/node": "^17.0.31",
|
|
94
94
|
"@types/prompts": "^2.4.0",
|
|
95
95
|
"@types/sinonjs__fake-timers": "^8.1.2",
|
|
96
|
-
"@vitest/ui": "0.
|
|
96
|
+
"@vitest/ui": "0.12.1",
|
|
97
97
|
"birpc": "^0.2.2",
|
|
98
98
|
"c8": "^7.11.2",
|
|
99
99
|
"cac": "^6.7.12",
|
|
@@ -116,11 +116,11 @@
|
|
|
116
116
|
"pkg-types": "^0.3.2",
|
|
117
117
|
"pretty-format": "^27.5.1",
|
|
118
118
|
"prompts": "^2.4.2",
|
|
119
|
-
"rollup": "^2.
|
|
119
|
+
"rollup": "^2.72.1",
|
|
120
120
|
"source-map-js": "^1.0.2",
|
|
121
121
|
"strip-ansi": "^7.0.1",
|
|
122
122
|
"typescript": "^4.6.4",
|
|
123
|
-
"vite-node": "0.
|
|
123
|
+
"vite-node": "0.12.1",
|
|
124
124
|
"ws": "^8.6.0"
|
|
125
125
|
},
|
|
126
126
|
"engines": {
|