vitest 0.0.91 → 0.0.95

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/index.d.ts CHANGED
@@ -2,7 +2,6 @@ import { Formatter } from 'picocolors/types';
2
2
  import { OptionsReceived } from 'pretty-format';
3
3
  import { MessagePort } from 'worker_threads';
4
4
  export { assert, default as chai, expect, should } from 'chai';
5
- export { spy, spyOn } from 'tinyspy';
6
5
 
7
6
  declare const EXPECTED_COLOR: Formatter;
8
7
  declare const RECEIVED_COLOR: Formatter;
@@ -129,6 +128,28 @@ declare class Anything extends AsymmetricMatcher<void> {
129
128
  toString(): string;
130
129
  toAsymmetricMatcher(): string;
131
130
  }
131
+ declare class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
132
+ constructor(sample: Record<string, unknown>, inverse?: boolean);
133
+ getPrototype(obj: object): any;
134
+ hasProperty(obj: object | null, property: string): boolean;
135
+ asymmetricMatch(other: any): boolean;
136
+ toString(): string;
137
+ getExpectedType(): string;
138
+ }
139
+ declare class ArrayContaining extends AsymmetricMatcher<Array<unknown>> {
140
+ constructor(sample: Array<unknown>, inverse?: boolean);
141
+ asymmetricMatch(other: Array<unknown>): boolean;
142
+ toString(): string;
143
+ getExpectedType(): string;
144
+ }
145
+ declare class Any extends AsymmetricMatcher<any> {
146
+ constructor(sample: unknown);
147
+ fnNameFor(func: Function): string;
148
+ asymmetricMatch(other: unknown): boolean;
149
+ toString(): string;
150
+ getExpectedType(): string;
151
+ toAsymmetricMatcher(): string;
152
+ }
132
153
 
133
154
  declare type Awaitable<T> = T | PromiseLike<T>;
134
155
  declare type Nullable<T> = T | null | undefined;
@@ -291,6 +312,7 @@ interface SnapshotSummary {
291
312
  updated: number;
292
313
  }
293
314
 
315
+ declare type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom';
294
316
  interface InlineConfig {
295
317
  /**
296
318
  * Include globs for test files
@@ -336,7 +358,7 @@ interface InlineConfig {
336
358
  *
337
359
  * @default 'node'
338
360
  */
339
- environment?: 'node' | 'jsdom' | 'happy-dom';
361
+ environment?: BuiltinEnvironment;
340
362
  /**
341
363
  * Update snapshot files
342
364
  *
@@ -608,21 +630,25 @@ declare function fn<TArgs extends any[] = any[], R = any>(): JestMockCompatFn<TA
608
630
  declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): JestMockCompatFn<TArgs, R>;
609
631
 
610
632
  declare class VitestUtils {
611
- spyOn: typeof spyOn;
612
- fn: typeof fn;
613
- mock: (path: string) => string;
614
633
  private _timers;
615
634
  constructor();
616
635
  useFakeTimers(): void;
617
636
  useRealTimers(): void;
618
- runOnlyPendingTimers(): void;
619
- runAllTimers(): void;
620
- advanceTimersByTime(ms: number): void;
621
- advanceTimersToNextTimer(): void;
622
- runAllTicks(): void;
637
+ runOnlyPendingTimers(): void | Promise<void>;
638
+ runAllTimers(): void | Promise<void>;
639
+ advanceTimersByTime(ms: number): void | Promise<void>;
640
+ advanceTimersToNextTimer(): void | Promise<void>;
641
+ runAllTicks(): void | Promise<void>;
623
642
  setSystemTime(time?: number | Date): void;
624
643
  getRealSystemTime(): number;
625
644
  getTimerCount(): number;
645
+ spyOn: typeof spyOn;
646
+ fn: typeof fn;
647
+ mock: (path: string) => string;
648
+ isMockFunction(fn: any): any;
649
+ clearAllMocks(): void;
650
+ resetAllMocks(): void;
651
+ restoreAllMocks(): void;
626
652
  }
627
653
  declare const vitest: VitestUtils;
628
654
  declare const vi: VitestUtils;
@@ -641,6 +667,9 @@ declare global {
641
667
  extend(expects: MatchersObject): void;
642
668
  stringContaining(expected: string): void;
643
669
  anything(): Anything;
670
+ objectContaining(expected: any): ObjectContaining;
671
+ any(constructor: unknown): Any;
672
+ arrayContaining(expected: any): ArrayContaining;
644
673
  }
645
674
  interface Assertion {
646
675
  chaiEqual(expected: any): void;
@@ -695,4 +724,4 @@ declare global {
695
724
  }
696
725
  }
697
726
 
698
- export { ArgumentsType, Arrayable, Awaitable, ComputeMode, DoneCallback, Environment, EnvironmentReturn, File, HookListener, InlineConfig, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, it, suite, test, vi, vitest };
727
+ export { ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ComputeMode, DoneCallback, Environment, EnvironmentReturn, File, HookListener, InlineConfig, JestMockCompat, JestMockCompatContext, JestMockCompatFn, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, fn, it, spyOn, suite, test, vi, vitest };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { d as describe, i as it, s as suite, t as test } from './suite-b8c6cb53.js';
2
- export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, e as vi, v as vitest } from './index-708135df.js';
2
+ export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, f as fn, s as spyOn, e as vi, v as vitest } from './index-368448f4.js';
3
3
  export { assert, default as chai, expect, should } from 'chai';
4
- export { spy, spyOn } from 'tinyspy';
5
4
  import './index-9e71c815.js';
5
+ import 'tinyspy';
@@ -0,0 +1,78 @@
1
+ import { A as API_PATH } from './constants-9cfa4d7b.js';
2
+ import 'path';
3
+ import 'url';
4
+
5
+ /*! (c) 2020 Andrea Giammarchi */
6
+
7
+ const {parse: $parse, stringify: $stringify} = JSON;
8
+
9
+ const Primitive = String; // it could be Number
10
+ const primitive = 'string'; // it could be 'number'
11
+ const object = 'object';
12
+
13
+ const noop = (_, value) => value;
14
+
15
+ const set = (known, input, value) => {
16
+ const index = Primitive(input.push(value) - 1);
17
+ known.set(value, index);
18
+ return index;
19
+ };
20
+
21
+ const stringify = (value, replacer, space) => {
22
+ const $ = replacer && typeof replacer === object ?
23
+ (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
24
+ (replacer || noop);
25
+ const known = new Map;
26
+ const input = [];
27
+ const output = [];
28
+ let i = +set(known, input, $.call({'': value}, '', value));
29
+ let firstRun = !i;
30
+ while (i < input.length) {
31
+ firstRun = true;
32
+ output[i] = $stringify(input[i++], replace, space);
33
+ }
34
+ return '[' + output.join(',') + ']';
35
+ function replace(key, value) {
36
+ if (firstRun) {
37
+ firstRun = !firstRun;
38
+ return value;
39
+ }
40
+ const after = $.call(this, key, value);
41
+ switch (typeof after) {
42
+ case object:
43
+ if (after === null) return after;
44
+ case primitive:
45
+ return known.get(after) || set(known, input, after);
46
+ }
47
+ return after;
48
+ }
49
+ };
50
+
51
+ function sendFlatted(res, data) {
52
+ res.setHeader("Content-Type", "application/json");
53
+ res.write(stringify(data));
54
+ res.statusCode = 200;
55
+ res.end();
56
+ }
57
+ function middlewareAPI(ctx) {
58
+ return (req, res, next) => {
59
+ var _a;
60
+ if (!((_a = req.url) == null ? void 0 : _a.startsWith(API_PATH)))
61
+ return next();
62
+ const url = req.url.slice(API_PATH.length);
63
+ if (url === "/") {
64
+ return sendFlatted(res, {
65
+ files: ctx.state.filesMap
66
+ });
67
+ }
68
+ if (url === "/files") {
69
+ return sendFlatted(res, {
70
+ files: Object.keys(ctx.state.filesMap)
71
+ });
72
+ }
73
+ res.statusCode = 404;
74
+ res.end();
75
+ };
76
+ }
77
+
78
+ export { middlewareAPI as default, sendFlatted };
package/dist/node.js CHANGED
@@ -1,19 +1,20 @@
1
- export { c as createVitest } from './index-25bef3dd.js';
1
+ export { c as createVitest } from './index-ece64e3c.js';
2
2
  import 'path';
3
3
  import 'vite';
4
4
  import 'process';
5
5
  import 'fs';
6
+ import 'fast-glob';
7
+ import 'util';
6
8
  import './constants-9cfa4d7b.js';
7
9
  import 'url';
8
- import './utils-5d0cec8a.js';
9
- import 'module';
10
+ import './utils-576876dc.js';
10
11
  import 'tty';
12
+ import 'local-pkg';
11
13
  import 'perf_hooks';
12
- import './error-abd1f726.js';
14
+ import './error-81292c96.js';
13
15
  import 'source-map';
16
+ import './index-5cc247ff.js';
14
17
  import 'assert';
15
18
  import 'events';
16
19
  import 'worker_threads';
17
- import 'piscina';
18
- import 'fast-glob';
19
- import 'micromatch';
20
+ import 'tinypool';
@@ -1,5 +1,5 @@
1
- import { createRequire } from 'module';
2
1
  import require$$0 from 'tty';
2
+ import { isPackageExists } from 'local-pkg';
3
3
 
4
4
  var picocolors = {exports: {}};
5
5
 
@@ -76,6 +76,8 @@ function notNullish(v) {
76
76
  function slash(str) {
77
77
  return str.replace(/\\/g, "/");
78
78
  }
79
+ const noop = () => {
80
+ };
79
81
  function partitionSuiteChildren(suite) {
80
82
  let tasksGroup = [];
81
83
  const tasksGroups = [];
@@ -137,15 +139,24 @@ function getNames(task) {
137
139
  }
138
140
  return names;
139
141
  }
140
- function checkPeerDependency(dependency) {
141
- const require = createRequire(import.meta.url);
142
- try {
143
- require.resolve(dependency);
144
- } catch {
145
- console.log(c.red(`${c.inverse(c.red(" MISSING DEP "))} Cound not find '${dependency}' peer dependency, please try installing it
142
+ async function ensurePackageInstalled(dependency, promptInstall = !process.env.CI) {
143
+ if (isPackageExists(dependency))
144
+ return true;
145
+ console.log(c.red(`${c.inverse(c.red(" MISSING DEP "))} Can not find dependency '${dependency}'
146
146
  `));
147
- process.exit(1);
147
+ if (!promptInstall)
148
+ return false;
149
+ const prompts = await import('./index-fa899e66.js').then(function (n) { return n.i; });
150
+ const { install } = await prompts.prompt({
151
+ type: "confirm",
152
+ name: "install",
153
+ message: c.reset(`Do you want to install ${c.green(dependency)}?`)
154
+ });
155
+ if (install) {
156
+ await (await import('./index-e7a421bb.js')).installPackage(dependency);
157
+ return true;
148
158
  }
159
+ return false;
149
160
  }
150
161
 
151
- export { getTests as a, getSuites as b, c, hasTests as d, getTasks as e, checkPeerDependency as f, getNames as g, hasFailed as h, interpretOnlyMode as i, notNullish as n, partitionSuiteChildren as p, slash as s, toArray as t };
162
+ export { getTests as a, getSuites as b, c, notNullish as d, ensurePackageInstalled as e, hasTests as f, getNames as g, hasFailed as h, interpretOnlyMode as i, getTasks as j, noop as n, partitionSuiteChildren as p, slash as s, toArray as t };
package/dist/utils.js CHANGED
@@ -1,3 +1,3 @@
1
- import 'module';
2
- export { f as checkPeerDependency, g as getNames, b as getSuites, e as getTasks, a as getTests, h as hasFailed, d as hasTests, i as interpretOnlyMode, n as notNullish, p as partitionSuiteChildren, s as slash, t as toArray } from './utils-5d0cec8a.js';
1
+ export { e as ensurePackageInstalled, g as getNames, b as getSuites, j as getTasks, a as getTests, h as hasFailed, f as hasTests, i as interpretOnlyMode, n as noop, d as notNullish, p as partitionSuiteChildren, s as slash, t as toArray } from './utils-576876dc.js';
2
+ import 'local-pkg';
3
3
  import 'tty';