vitest 0.10.0 → 0.10.3

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/node.d.ts CHANGED
@@ -220,7 +220,7 @@ declare abstract class BaseReporter implements Reporter {
220
220
  constructor();
221
221
  onInit(ctx: Vitest): void;
222
222
  relative(path: string): string;
223
- onFinished(files?: File[]): Promise<void>;
223
+ onFinished(files?: File[], errors?: unknown[]): Promise<void>;
224
224
  onTaskUpdate(packs: TaskResultPack[]): void;
225
225
  onWatcherStart(): Promise<void>;
226
226
  onWatcherRerun(files: string[], trigger?: string): Promise<void>;
@@ -234,6 +234,7 @@ declare abstract class BaseReporter implements Reporter {
234
234
  interface ListRendererOptions {
235
235
  renderSucceed?: boolean;
236
236
  outputStream: NodeJS.WritableStream;
237
+ showHeap: boolean;
237
238
  }
238
239
  declare const createListRenderer: (_tasks: Task[], options: ListRendererOptions) => {
239
240
  start(): any;
@@ -247,7 +248,7 @@ declare class DefaultReporter extends BaseReporter {
247
248
  rendererOptions: ListRendererOptions;
248
249
  onTestRemoved(trigger?: string): Promise<void>;
249
250
  onCollected(): void;
250
- onFinished(files?: File[]): Promise<void>;
251
+ onFinished(files?: File[], errors?: unknown[]): Promise<void>;
251
252
  onWatcherStart(): Promise<void>;
252
253
  stopListRender(): Promise<void>;
253
254
  onWatcherRerun(files: string[], trigger?: string): Promise<void>;
@@ -257,7 +258,7 @@ declare class DefaultReporter extends BaseReporter {
257
258
  declare class DotReporter extends BaseReporter {
258
259
  renderer?: ReturnType<typeof createListRenderer>;
259
260
  onCollected(): void;
260
- onFinished(files?: File[]): Promise<void>;
261
+ onFinished(files?: File[], errors?: unknown[]): Promise<void>;
261
262
  onWatcherStart(): Promise<void>;
262
263
  stopListRender(): Promise<void>;
263
264
  onWatcherRerun(files: string[], trigger?: string): Promise<void>;
@@ -354,6 +355,7 @@ interface ErrorWithDiff extends Error {
354
355
  actual?: any;
355
356
  expected?: any;
356
357
  operator?: string;
358
+ type?: string;
357
359
  }
358
360
 
359
361
  declare type CoverageReporter = 'clover' | 'cobertura' | 'html-spa' | 'html' | 'json-summary' | 'json' | 'lcov' | 'lcovonly' | 'none' | 'teamcity' | 'text-lcov' | 'text-summary' | 'text';
@@ -509,6 +511,7 @@ interface TaskResult {
509
511
  state: TaskState;
510
512
  duration?: number;
511
513
  startTime?: number;
514
+ heap?: number;
512
515
  error?: ErrorWithDiff;
513
516
  htmlError?: string;
514
517
  hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
@@ -555,7 +558,7 @@ interface TestContext {
555
558
  interface Reporter {
556
559
  onInit?(ctx: Vitest): void;
557
560
  onCollected?: (files?: File[]) => Awaitable<void>;
558
- onFinished?: (files?: File[]) => Awaitable<void>;
561
+ onFinished?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
559
562
  onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
560
563
  onTestRemoved?: (trigger?: string) => Awaitable<void>;
561
564
  onWatcherStart?: () => Awaitable<void>;
@@ -709,7 +712,7 @@ interface InlineConfig {
709
712
  * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
710
713
  * and/or paths to custom reporters
711
714
  */
712
- reporters?: Arrayable<BuiltinReporters | Reporter | string>;
715
+ reporters?: Arrayable<BuiltinReporters | Reporter | Omit<string, BuiltinReporters>>;
713
716
  /**
714
717
  * diff output length
715
718
  */
@@ -851,6 +854,10 @@ interface InlineConfig {
851
854
  * Resolve custom snapshot path
852
855
  */
853
856
  resolveSnapshotPath?: (path: string, extension: string) => string;
857
+ /**
858
+ * Show heap usage after each test. Usefull for debugging memory leaks.
859
+ */
860
+ logHeapUsage?: boolean;
854
861
  }
855
862
  interface UserConfig extends InlineConfig {
856
863
  /**
@@ -927,6 +934,10 @@ declare class StateManager {
927
934
  filesMap: Map<string, File>;
928
935
  idMap: Map<string, Task>;
929
936
  taskFileMap: WeakMap<Task, File>;
937
+ errorsSet: Set<unknown>;
938
+ catchError(err: unknown, type: string): void;
939
+ clearErrors(): void;
940
+ getUnhandledErrors(): unknown[];
930
941
  getFiles(keys?: string[]): File[];
931
942
  getFilepaths(): string[];
932
943
  getFailedFilepaths(): string[];
@@ -988,7 +999,7 @@ declare class Vitest {
988
999
  globTestFiles(filters?: string[]): Promise<string[]>;
989
1000
  isTargetFile(id: string, source?: string): Promise<boolean>;
990
1001
  isInSourceTestFile(code: string): boolean;
991
- printError(err: unknown): Promise<void>;
1002
+ printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
992
1003
  onServerRestarted(fn: () => void): void;
993
1004
  }
994
1005
 
package/dist/node.js CHANGED
@@ -1,5 +1,5 @@
1
- export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.5c678054.js';
2
- export { V as VitestRunner } from './chunk-runtime-mocker.111ac858.js';
1
+ export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.f88b9527.js';
2
+ export { V as VitestRunner } from './chunk-runtime-mocker.89015cf8.js';
3
3
  import 'buffer';
4
4
  import 'path';
5
5
  import 'child_process';
@@ -13,19 +13,19 @@ import 'stream';
13
13
  import 'util';
14
14
  import 'url';
15
15
  import 'os';
16
- import './chunk-utils-global.37a7c822.js';
16
+ import './chunk-utils-global.eb31f3da.js';
17
17
  import 'tty';
18
18
  import 'local-pkg';
19
19
  import 'vite';
20
- import './chunk-constants.d540b1d1.js';
20
+ import './chunk-constants.54c46a47.js';
21
21
  import 'readline';
22
- import './chunk-vite-node-utils.33447cc0.js';
22
+ import './chunk-vite-node-utils.3cb38009.js';
23
23
  import 'module';
24
24
  import 'vm';
25
- import './chunk-defaults.04d5d90b.js';
25
+ import './chunk-defaults.c143550b.js';
26
26
  import 'worker_threads';
27
27
  import 'tinypool';
28
28
  import 'perf_hooks';
29
- import './chunk-utils-timers.12bc05d1.js';
29
+ import './chunk-utils-timers.8a5e7cd5.js';
30
30
  import './chunk-magic-string.d5e0e473.js';
31
31
  import './vendor-index.405e58ef.js';
@@ -1,13 +1,13 @@
1
1
  import { promises } from 'fs';
2
- import { b as getWorkerState, t as toArray, m as relative, D as partitionSuiteChildren, E as hasTests, u as hasFailed, q as getFullName, r as resetModules } from './chunk-utils-global.37a7c822.js';
2
+ import { b as getWorkerState, t as toArray, H as clone, F as getType, m as relative, B as stdout, I as partitionSuiteChildren, J as hasTests, u as hasFailed, q as getFullName, r as resetModules } from './chunk-utils-global.eb31f3da.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.f863f182.js';
7
- import chai, { assert, should } from 'chai';
8
- import { r as rpc } from './chunk-runtime-rpc.8f648236.js';
9
- import { d as clearTimeout, c as setTimeout, s as stringify } from './chunk-utils-timers.12bc05d1.js';
10
- import { t as takeCoverage } from './chunk-defaults.04d5d90b.js';
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.0ac0691b.js';
7
+ import chai, { assert, should, util } from 'chai';
8
+ import { r as rpc } from './chunk-runtime-rpc.710f6f7f.js';
9
+ import { d as clearTimeout, c as setTimeout, s as stringify } from './chunk-utils-timers.8a5e7cd5.js';
10
+ import { t as takeCoverage } from './chunk-defaults.c143550b.js';
11
11
  import { createHash } from 'crypto';
12
12
  import { format } from 'util';
13
13
 
@@ -419,7 +419,7 @@ async function setupGlobalEnv(config) {
419
419
  globalSetup = true;
420
420
  setupConsoleLogSpy();
421
421
  if (config.globals)
422
- (await import('./chunk-integrations-globals.d2c09cd2.js')).registerApiGlobally();
422
+ (await import('./chunk-integrations-globals.12eb8517.js')).registerApiGlobally();
423
423
  }
424
424
  function setupDefines(defines) {
425
425
  for (const key in defines)
@@ -556,24 +556,24 @@ function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
556
556
  if (seen.has(val))
557
557
  return seen.get(val);
558
558
  if (Array.isArray(val)) {
559
- const clone = new Array(val.length);
560
- seen.set(val, clone);
559
+ const clone2 = new Array(val.length);
560
+ seen.set(val, clone2);
561
561
  val.forEach((e, i) => {
562
- clone[i] = serializeError(e, seen);
562
+ clone2[i] = serializeError(e, seen);
563
563
  });
564
- return clone;
564
+ return clone2;
565
565
  } else {
566
- const clone = /* @__PURE__ */ Object.create(null);
567
- seen.set(val, clone);
566
+ const clone2 = /* @__PURE__ */ Object.create(null);
567
+ seen.set(val, clone2);
568
568
  let obj = val;
569
569
  while (obj && obj !== OBJECT_PROTO) {
570
570
  Object.getOwnPropertyNames(obj).forEach((key) => {
571
- if (!(key in clone))
572
- clone[key] = serializeError(obj[key], seen);
571
+ if (!(key in clone2))
572
+ clone2[key] = serializeError(obj[key], seen);
573
573
  });
574
574
  obj = Object.getPrototypeOf(obj);
575
575
  }
576
- return clone;
576
+ return clone2;
577
577
  }
578
578
  }
579
579
  function processError(err) {
@@ -583,6 +583,11 @@ function processError(err) {
583
583
  err.stackStr = String(err.stack);
584
584
  if (err.name)
585
585
  err.nameStr = String(err.name);
586
+ const clonedActual = clone(err.actual);
587
+ const clonedExpected = clone(err.expected);
588
+ const { replacedActual, replacedExpected } = replaceAsymmetricMatcher(clonedActual, clonedExpected);
589
+ err.actual = replacedActual;
590
+ err.expected = replacedExpected;
586
591
  if (typeof err.expected !== "string")
587
592
  err.expected = stringify(err.expected);
588
593
  if (typeof err.actual !== "string")
@@ -594,6 +599,38 @@ function processError(err) {
594
599
  Inner error message: ${err == null ? void 0 : err.message}`));
595
600
  }
596
601
  }
602
+ function isAsymmetricMatcher(data) {
603
+ const type = getType(data);
604
+ return type === "Object" && typeof data.asymmetricMatch === "function";
605
+ }
606
+ function isReplaceable(obj1, obj2) {
607
+ const obj1Type = getType(obj1);
608
+ const obj2Type = getType(obj2);
609
+ return obj1Type === obj2Type && obj1Type === "Object";
610
+ }
611
+ function replaceAsymmetricMatcher(actual, expected) {
612
+ if (!isReplaceable(actual, expected))
613
+ return { replacedActual: actual, replacedExpected: expected };
614
+ util.getOwnEnumerableProperties(expected).forEach((key) => {
615
+ const expectedValue = expected[key];
616
+ const actualValue = actual[key];
617
+ if (isAsymmetricMatcher(expectedValue)) {
618
+ if (expectedValue.asymmetricMatch(actualValue))
619
+ actual[key] = expectedValue;
620
+ } else if (isAsymmetricMatcher(actualValue)) {
621
+ if (actualValue.asymmetricMatch(expectedValue))
622
+ expected[key] = actualValue;
623
+ } else if (isReplaceable(actualValue, expectedValue)) {
624
+ const replaced = replaceAsymmetricMatcher(actualValue, expectedValue);
625
+ actual[key] = replaced.replacedActual;
626
+ expected[key] = replaced.replacedExpected;
627
+ }
628
+ });
629
+ return {
630
+ replacedActual: actual,
631
+ replacedExpected: expected
632
+ };
633
+ }
597
634
 
598
635
  const now$1 = Date.now;
599
636
  function hash(str, length = 10) {
@@ -635,7 +672,7 @@ async function collectTests(paths, config) {
635
672
  state: "fail",
636
673
  error: processError(e)
637
674
  };
638
- process.stdout.write("\0");
675
+ stdout().write("\0");
639
676
  }
640
677
  calculateHash(file);
641
678
  const hasOnlyTasks = someTasksAreOnly(file);
@@ -830,6 +867,8 @@ async function runTest(test) {
830
867
  }
831
868
  getSnapshotClient().clearTest();
832
869
  test.result.duration = now() - start;
870
+ if (workerState.config.logHeapUsage)
871
+ test.result.heap = process.memoryUsage().heapUsed;
833
872
  workerState.current = void 0;
834
873
  updateTask(test);
835
874
  }
@@ -878,6 +917,9 @@ async function runSuite(suite) {
878
917
  }
879
918
  }
880
919
  suite.result.duration = now() - start;
920
+ const workerState = getWorkerState();
921
+ if (workerState.config.logHeapUsage)
922
+ suite.result.heap = process.memoryUsage().heapUsed;
881
923
  if (suite.mode === "run") {
882
924
  if (!hasTests(suite)) {
883
925
  suite.result.state = "fail";
package/dist/worker.js CHANGED
@@ -1,8 +1,8 @@
1
- import { k as resolve, b as getWorkerState } from './chunk-utils-global.37a7c822.js';
2
- import { c as createBirpc, M as ModuleCacheMap } from './chunk-vite-node-utils.33447cc0.js';
3
- import { d as distDir } from './chunk-constants.d540b1d1.js';
4
- import { e as executeInViteNode } from './chunk-runtime-mocker.111ac858.js';
5
- import { r as rpc } from './chunk-runtime-rpc.8f648236.js';
1
+ import { k as resolve, b as getWorkerState, B as stdout } from './chunk-utils-global.eb31f3da.js';
2
+ import { c as createBirpc, M as ModuleCacheMap } from './chunk-vite-node-utils.3cb38009.js';
3
+ import { d as distDir } from './chunk-constants.54c46a47.js';
4
+ import { e as executeInViteNode } from './chunk-runtime-mocker.89015cf8.js';
5
+ import { r as rpc } from './chunk-runtime-rpc.710f6f7f.js';
6
6
  import 'tty';
7
7
  import 'local-pkg';
8
8
  import 'path';
@@ -28,6 +28,9 @@ async function startViteNode(ctx) {
28
28
  rpc().onWorkerExit(code);
29
29
  return processExit(code);
30
30
  };
31
+ process.on("unhandledRejection", (err) => {
32
+ rpc().onUnhandledRejection(err);
33
+ });
31
34
  const { config } = ctx;
32
35
  const { run: run2, collect: collect2 } = (await executeInViteNode({
33
36
  files: [
@@ -51,7 +54,7 @@ async function startViteNode(ctx) {
51
54
  function init(ctx) {
52
55
  if (typeof __vitest_worker__ !== "undefined" && ctx.config.threads && ctx.config.isolate)
53
56
  throw new Error(`worker for ${ctx.files.join(",")} already initialized by ${getWorkerState().ctx.files.join(",")}. This is probably an internal bug of Vitest.`);
54
- process.stdout.write("\0");
57
+ stdout().write("\0");
55
58
  const { config, port, id } = ctx;
56
59
  process.env.VITEST_WORKER_ID = String(id);
57
60
  globalThis.__vitest_worker__ = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "0.10.0",
4
+ "version": "0.10.3",
5
5
  "description": "A blazing fast unit test framework powered by Vite",
6
6
  "keywords": [
7
7
  "vite",
@@ -79,9 +79,9 @@
79
79
  "@types/chai-subset": "^1.3.3",
80
80
  "chai": "^4.3.6",
81
81
  "local-pkg": "^0.4.1",
82
- "tinypool": "^0.1.2",
82
+ "tinypool": "^0.1.3",
83
83
  "tinyspy": "^0.3.2",
84
- "vite": "^2.9.5"
84
+ "vite": "^2.9.7"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@antfu/install-pkg": "^0.1.0",
@@ -90,10 +90,10 @@
90
90
  "@types/jsdom": "^16.2.14",
91
91
  "@types/micromatch": "^4.0.2",
92
92
  "@types/natural-compare": "^1.4.1",
93
- "@types/node": "^17.0.26",
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.10.0",
96
+ "@vitest/ui": "0.10.3",
97
97
  "birpc": "^0.2.2",
98
98
  "c8": "^7.11.2",
99
99
  "cac": "^6.7.12",
@@ -116,12 +116,12 @@
116
116
  "pkg-types": "^0.3.2",
117
117
  "pretty-format": "^27.5.1",
118
118
  "prompts": "^2.4.2",
119
- "rollup": "^2.70.2",
119
+ "rollup": "^2.71.1",
120
120
  "source-map-js": "^1.0.2",
121
121
  "strip-ansi": "^7.0.1",
122
- "typescript": "^4.6.3",
123
- "vite-node": "0.10.0",
124
- "ws": "^8.5.0"
122
+ "typescript": "^4.6.4",
123
+ "vite-node": "0.10.3",
124
+ "ws": "^8.6.0"
125
125
  },
126
126
  "engines": {
127
127
  "node": ">=v14.16.0"
@@ -129,6 +129,5 @@
129
129
  "scripts": {
130
130
  "build": "rimraf dist && rollup -c",
131
131
  "dev": "rollup -c --watch -m inline"
132
- },
133
- "readme": "# vitest\n\n[![NPM version](https://img.shields.io/npm/v/vitest?color=a1b858&label=)](https://www.npmjs.com/package/vitest)\n\nA blazing fast unit test framework powered by Vite.\n\n[GitHub](https://github.com/vitest-dev/vitest) | [Documentation](https://vitest.dev/)\n"
132
+ }
134
133
  }
package/vitest.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import('./dist/cli.js')
2
+ import './dist/cli.js'