vitest 0.0.70 → 0.0.74

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
@@ -1,3 +1,4 @@
1
+ import { Formatter } from 'picocolors/types';
1
2
  import { TransformResult, ViteDevServer } from 'vite';
2
3
  import { OptionsReceived } from 'pretty-format';
3
4
  import { MessagePort } from 'worker_threads';
@@ -5,6 +6,110 @@ export { assert, default as chai, expect, should } from 'chai';
5
6
  import sinon from 'sinon';
6
7
  export { default as sinon } from 'sinon';
7
8
 
9
+ declare const EXPECTED_COLOR: Formatter;
10
+ declare const RECEIVED_COLOR: Formatter;
11
+ declare const INVERTED_COLOR: Formatter;
12
+ declare const BOLD_WEIGHT: Formatter;
13
+ declare const DIM_COLOR: Formatter;
14
+ declare type MatcherHintOptions = {
15
+ comment?: string;
16
+ expectedColor?: Formatter;
17
+ isDirectExpectCall?: boolean;
18
+ isNot?: boolean;
19
+ promise?: string;
20
+ receivedColor?: Formatter;
21
+ secondArgument?: string;
22
+ secondArgumentColor?: Formatter;
23
+ };
24
+ declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
25
+ declare const stringify: (object: unknown, maxDepth?: number) => string;
26
+ declare const printReceived: (object: unknown) => string;
27
+ declare const printExpected: (value: unknown) => string;
28
+ declare type DiffOptions = {
29
+ aAnnotation?: string;
30
+ aColor?: Formatter;
31
+ aIndicator?: string;
32
+ bAnnotation?: string;
33
+ bColor?: Formatter;
34
+ bIndicator?: string;
35
+ changeColor?: Formatter;
36
+ changeLineTrailingSpaceColor?: Formatter;
37
+ commonColor?: Formatter;
38
+ commonIndicator?: string;
39
+ commonLineTrailingSpaceColor?: Formatter;
40
+ contextLines?: number;
41
+ emptyFirstOrLastLinePlaceholder?: string;
42
+ expand?: boolean;
43
+ includeChangeCounts?: boolean;
44
+ omitAnnotationLines?: boolean;
45
+ patchColor?: Formatter;
46
+ compareKeys?: any;
47
+ };
48
+ declare function diff(a: any, b: any, options?: DiffOptions): string;
49
+
50
+ declare const jestMatcherUtils_EXPECTED_COLOR: typeof EXPECTED_COLOR;
51
+ declare const jestMatcherUtils_RECEIVED_COLOR: typeof RECEIVED_COLOR;
52
+ declare const jestMatcherUtils_INVERTED_COLOR: typeof INVERTED_COLOR;
53
+ declare const jestMatcherUtils_BOLD_WEIGHT: typeof BOLD_WEIGHT;
54
+ declare const jestMatcherUtils_DIM_COLOR: typeof DIM_COLOR;
55
+ type jestMatcherUtils_MatcherHintOptions = MatcherHintOptions;
56
+ declare const jestMatcherUtils_matcherHint: typeof matcherHint;
57
+ declare const jestMatcherUtils_stringify: typeof stringify;
58
+ declare const jestMatcherUtils_printReceived: typeof printReceived;
59
+ declare const jestMatcherUtils_printExpected: typeof printExpected;
60
+ type jestMatcherUtils_DiffOptions = DiffOptions;
61
+ declare const jestMatcherUtils_diff: typeof diff;
62
+ declare namespace jestMatcherUtils {
63
+ export {
64
+ jestMatcherUtils_EXPECTED_COLOR as EXPECTED_COLOR,
65
+ jestMatcherUtils_RECEIVED_COLOR as RECEIVED_COLOR,
66
+ jestMatcherUtils_INVERTED_COLOR as INVERTED_COLOR,
67
+ jestMatcherUtils_BOLD_WEIGHT as BOLD_WEIGHT,
68
+ jestMatcherUtils_DIM_COLOR as DIM_COLOR,
69
+ jestMatcherUtils_MatcherHintOptions as MatcherHintOptions,
70
+ jestMatcherUtils_matcherHint as matcherHint,
71
+ jestMatcherUtils_stringify as stringify,
72
+ jestMatcherUtils_printReceived as printReceived,
73
+ jestMatcherUtils_printExpected as printExpected,
74
+ jestMatcherUtils_DiffOptions as DiffOptions,
75
+ jestMatcherUtils_diff as diff,
76
+ };
77
+ }
78
+
79
+ declare type Tester = (a: any, b: any) => boolean | undefined;
80
+ declare type MatcherState = {
81
+ assertionCalls: number;
82
+ currentTestName?: string;
83
+ dontThrow?: () => void;
84
+ error?: Error;
85
+ equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
86
+ expand?: boolean;
87
+ expectedAssertionsNumber?: number | null;
88
+ expectedAssertionsNumberError?: Error;
89
+ isExpectingAssertions?: boolean;
90
+ isExpectingAssertionsError?: Error;
91
+ isNot: boolean;
92
+ promise: string;
93
+ suppressedErrors: Array<Error>;
94
+ testPath?: string;
95
+ utils: typeof jestMatcherUtils & {
96
+ iterableEquality: Tester;
97
+ subsetEquality: Tester;
98
+ };
99
+ };
100
+ declare type SyncExpectationResult = {
101
+ pass: boolean;
102
+ message: () => string;
103
+ };
104
+ declare type AsyncExpectationResult = Promise<SyncExpectationResult>;
105
+ declare type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
106
+ declare type RawMatcherFn<T extends MatcherState = MatcherState> = {
107
+ (this: T, received: any, expected: any, options?: any): ExpectationResult;
108
+ };
109
+ declare type MatchersObject<T extends MatcherState = MatcherState> = {
110
+ [id: string]: RawMatcherFn<T>;
111
+ };
112
+
8
113
  declare class StateManager {
9
114
  filesMap: Record<string, File>;
10
115
  idMap: Record<string, Task>;
@@ -45,6 +150,11 @@ interface VitestContext {
45
150
  snapshot: SnapshotManager;
46
151
  reporter: Reporter;
47
152
  }
153
+ interface UserConsoleLog {
154
+ content: string;
155
+ type: 'stdout' | 'stderr';
156
+ taskId?: string;
157
+ }
48
158
 
49
159
  declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
50
160
  declare type TaskState = RunMode | 'pass' | 'fail';
@@ -134,6 +244,7 @@ interface Reporter {
134
244
  onTaskUpdate?: (pack: TaskResultPack) => Awaitable<void>;
135
245
  onWatcherStart?: () => Awaitable<void>;
136
246
  onWatcherRerun?: (files: string[], trigger: string) => Awaitable<void>;
247
+ onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
137
248
  }
138
249
 
139
250
  declare type SnapshotData = Record<string, string>;
@@ -302,8 +413,8 @@ interface WorkerContext {
302
413
  invalidates?: string[];
303
414
  }
304
415
  interface RpcMap {
305
- workerReady: [[], void];
306
416
  fetch: [[id: string], TransformResult | null | undefined];
417
+ log: [[UserConsoleLog], void];
307
418
  onCollected: [[files: File[]], void];
308
419
  onFinished: [[], void];
309
420
  onTaskUpdate: [[pack: TaskResultPack], void];
@@ -422,6 +533,7 @@ declare global {
422
533
  config: ResolvedConfig;
423
534
  rpc: RpcCall;
424
535
  send: RpcSend;
536
+ current?: Test;
425
537
  };
426
538
  }
427
539
  }
@@ -441,6 +553,9 @@ declare module 'vite' {
441
553
  }
442
554
  declare global {
443
555
  namespace Chai {
556
+ interface ExpectStatic {
557
+ extend(expects: MatchersObject): void;
558
+ }
444
559
  interface Assertion {
445
560
  toMatchSnapshot(message?: string): Assertion;
446
561
  matchSnapshot(message?: string): Assertion;
@@ -464,6 +579,7 @@ declare global {
464
579
  toBeInstanceOf(c: any): void;
465
580
  toBeCalledTimes(n: number): void;
466
581
  toHaveLength(l: number): void;
582
+ toHaveProperty(p: string, value?: any): void;
467
583
  toBeCloseTo(number: number, numDigits?: number): void;
468
584
  toHaveBeenCalledTimes(n: number): void;
469
585
  toHaveBeenCalledOnce(): void;
@@ -491,4 +607,4 @@ declare global {
491
607
  }
492
608
  }
493
609
 
494
- export { Arrayable, Awaitable, CliOptions, ComputeMode, Environment, EnvironmentReturn, File, GlobalContext, HookListener, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserOptions, VitestContext, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, clearContext, createSuiteHooks, defaultSuite, describe, it, mock, spy, stub, suite, test };
610
+ export { Arrayable, Awaitable, CliOptions, ComputeMode, Environment, EnvironmentReturn, File, GlobalContext, HookListener, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConsoleLog, UserOptions, VitestContext, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, clearContext, createSuiteHooks, defaultSuite, describe, it, mock, spy, stub, suite, test };
package/dist/worker.js CHANGED
@@ -53,6 +53,18 @@ async function interpretedImport(path, interpretDefault) {
53
53
  }
54
54
  return mod;
55
55
  }
56
+ let SOURCEMAPPING_URL = "sourceMa";
57
+ SOURCEMAPPING_URL += "ppingURL";
58
+ async function withInlineSourcemap(result) {
59
+ const { code, map } = result;
60
+ if (code.includes(`${SOURCEMAPPING_URL}=`))
61
+ return result;
62
+ if (map)
63
+ result.code = `${code}
64
+
65
+ //# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}`;
66
+ return result;
67
+ }
56
68
  async function executeInViteNode(options) {
57
69
  const { moduleCache, root, files, fetch } = options;
58
70
  const externaled = new Set(builtinModules);
@@ -79,6 +91,8 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
79
91
  const result2 = await fetch(id);
80
92
  if (!result2)
81
93
  throw new Error(`failed to load ${id}`);
94
+ if (process.env.NODE_V8_COVERAGE)
95
+ withInlineSourcemap(result2);
82
96
  const url = pathToFileURL(fsPath).href;
83
97
  const exports = {};
84
98
  setCache(fsPath, { transformResult: result2, exports });
package/global.d.ts CHANGED
@@ -3,7 +3,6 @@ declare global {
3
3
  const test: typeof import('vitest')['test']
4
4
  const describe: typeof import('vitest')['describe']
5
5
  const it: typeof import('vitest')['it']
6
- const chai: typeof import('vitest')['chai']
7
6
  const expect: typeof import('vitest')['expect']
8
7
  const assert: typeof import('vitest')['assert']
9
8
  const sinon: typeof import('vitest')['sinon']
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.70",
3
+ "version": "0.0.74",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -46,13 +46,13 @@
46
46
  "docs:build": "npm -C docs run build",
47
47
  "docs:serve": "npm -C docs run serve",
48
48
  "lint": "eslint \"{src,test}/**/*.ts\"",
49
- "prepare": "esmo scripts/generate-types.ts",
50
49
  "prepublishOnly": "nr build",
51
50
  "release": "bumpp --commit --push --tag && esmo scripts/publish.ts",
52
51
  "test": "node bin/vitest.mjs -r test/core",
53
52
  "test:all": "cross-env CI=true pnpm -r --stream --filter !vitest run test --",
54
53
  "test:ci": "cross-env CI=true pnpm -r --stream --filter !vitest --filter !@vitest/test-fails run test --",
55
- "typecheck": "tsc --noEmit && nr lint"
54
+ "typecheck": "tsc --noEmit && nr lint",
55
+ "ci": "ni && nr typecheck && nr lint && nr build && nr test:all"
56
56
  },
57
57
  "dependencies": {
58
58
  "@types/chai": "^4.3.0",