@vitest/snapshot 3.0.8 → 3.0.9

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.
@@ -0,0 +1,22 @@
1
+ interface ParsedStack {
2
+ method: string;
3
+ file: string;
4
+ line: number;
5
+ column: number;
6
+ }
7
+
8
+ interface SnapshotEnvironment {
9
+ getVersion: () => string;
10
+ getHeader: () => string;
11
+ resolvePath: (filepath: string) => Promise<string>;
12
+ resolveRawPath: (testPath: string, rawPath: string) => Promise<string>;
13
+ saveSnapshotFile: (filepath: string, snapshot: string) => Promise<void>;
14
+ readSnapshotFile: (filepath: string) => Promise<string | null>;
15
+ removeSnapshotFile: (filepath: string) => Promise<void>;
16
+ processStackTrace?: (stack: ParsedStack) => ParsedStack;
17
+ }
18
+ interface SnapshotEnvironmentOptions {
19
+ snapshotsDirName?: string;
20
+ }
21
+
22
+ export type { ParsedStack as P, SnapshotEnvironment as S, SnapshotEnvironmentOptions as a };
@@ -1,16 +1,16 @@
1
- import { S as SnapshotEnvironment, a as SnapshotEnvironmentOptions } from './environment-Ddx0EDtY.js';
1
+ import { S as SnapshotEnvironment, a as SnapshotEnvironmentOptions } from './environment.d-DHdQ1Csl.js';
2
2
 
3
3
  declare class NodeSnapshotEnvironment implements SnapshotEnvironment {
4
- private options;
5
- constructor(options?: SnapshotEnvironmentOptions);
6
- getVersion(): string;
7
- getHeader(): string;
8
- resolveRawPath(testPath: string, rawPath: string): Promise<string>;
9
- resolvePath(filepath: string): Promise<string>;
10
- prepareDirectory(dirPath: string): Promise<void>;
11
- saveSnapshotFile(filepath: string, snapshot: string): Promise<void>;
12
- readSnapshotFile(filepath: string): Promise<string | null>;
13
- removeSnapshotFile(filepath: string): Promise<void>;
4
+ private options;
5
+ constructor(options?: SnapshotEnvironmentOptions);
6
+ getVersion(): string;
7
+ getHeader(): string;
8
+ resolveRawPath(testPath: string, rawPath: string): Promise<string>;
9
+ resolvePath(filepath: string): Promise<string>;
10
+ prepareDirectory(dirPath: string): Promise<void>;
11
+ saveSnapshotFile(filepath: string, snapshot: string): Promise<void>;
12
+ readSnapshotFile(filepath: string): Promise<string | null>;
13
+ removeSnapshotFile(filepath: string): Promise<void>;
14
14
  }
15
15
 
16
16
  export { NodeSnapshotEnvironment, SnapshotEnvironment };
package/dist/index.d.ts CHANGED
@@ -1,139 +1,128 @@
1
- import { S as SnapshotStateOptions, a as SnapshotMatchOptions, b as SnapshotResult, R as RawSnapshotInfo } from './rawSnapshot-DOKg5unn.js';
2
- export { c as SnapshotData, d as SnapshotSerializer, e as SnapshotSummary, f as SnapshotUpdateState, U as UncheckedSnapshot } from './rawSnapshot-DOKg5unn.js';
3
- import { S as SnapshotEnvironment } from './environment-Ddx0EDtY.js';
1
+ import { S as SnapshotStateOptions, a as SnapshotMatchOptions, b as SnapshotResult, R as RawSnapshotInfo } from './rawSnapshot.d-lFsMJFUd.js';
2
+ export { c as SnapshotData, d as SnapshotSerializer, e as SnapshotSummary, f as SnapshotUpdateState, U as UncheckedSnapshot } from './rawSnapshot.d-lFsMJFUd.js';
3
+ import { S as SnapshotEnvironment, P as ParsedStack } from './environment.d-DHdQ1Csl.js';
4
4
  import { Plugin, Plugins } from '@vitest/pretty-format';
5
5
 
6
- interface ParsedStack {
7
- method: string;
8
- file: string;
9
- line: number;
10
- column: number;
11
- }
12
-
13
6
  /**
14
- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
15
- *
16
- * This source code is licensed under the MIT license found in the
17
- * LICENSE file in the root directory of this source tree.
18
- */
7
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
8
+ *
9
+ * This source code is licensed under the MIT license found in the
10
+ * LICENSE file in the root directory of this source tree.
11
+ */
19
12
 
20
- declare class DefaultMap<K, V> extends Map<K, V> {
21
- private defaultFn;
22
- constructor(defaultFn: (key: K) => V, entries?: Iterable<readonly [K, V]>);
23
- get(key: K): V;
13
+ declare class DefaultMap<
14
+ K,
15
+ V
16
+ > extends Map<K, V> {
17
+ private defaultFn;
18
+ constructor(defaultFn: (key: K) => V, entries?: Iterable<readonly [K, V]>);
19
+ get(key: K): V;
24
20
  }
25
21
  declare class CounterMap<K> extends DefaultMap<K, number> {
26
- constructor();
27
- _total: number | undefined;
28
- valueOf(): number;
29
- increment(key: K): void;
30
- total(): number;
22
+ constructor();
23
+ _total: number | undefined;
24
+ valueOf(): number;
25
+ increment(key: K): void;
26
+ total(): number;
31
27
  }
32
28
 
33
- /**
34
- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
35
- *
36
- * This source code is licensed under the MIT license found in the
37
- * LICENSE file in the root directory of this source tree.
38
- */
39
-
40
29
  interface SnapshotReturnOptions {
41
- actual: string;
42
- count: number;
43
- expected?: string;
44
- key: string;
45
- pass: boolean;
30
+ actual: string;
31
+ count: number;
32
+ expected?: string;
33
+ key: string;
34
+ pass: boolean;
46
35
  }
47
36
  interface SaveStatus {
48
- deleted: boolean;
49
- saved: boolean;
37
+ deleted: boolean;
38
+ saved: boolean;
50
39
  }
51
40
  declare class SnapshotState {
52
- testFilePath: string;
53
- snapshotPath: string;
54
- private _counters;
55
- private _dirty;
56
- private _updateSnapshot;
57
- private _snapshotData;
58
- private _initialData;
59
- private _inlineSnapshots;
60
- private _inlineSnapshotStacks;
61
- private _testIdToKeys;
62
- private _rawSnapshots;
63
- private _uncheckedKeys;
64
- private _snapshotFormat;
65
- private _environment;
66
- private _fileExists;
67
- expand: boolean;
68
- private _added;
69
- private _matched;
70
- private _unmatched;
71
- private _updated;
72
- get added(): CounterMap<string>;
73
- set added(value: number);
74
- get matched(): CounterMap<string>;
75
- set matched(value: number);
76
- get unmatched(): CounterMap<string>;
77
- set unmatched(value: number);
78
- get updated(): CounterMap<string>;
79
- set updated(value: number);
80
- private constructor();
81
- static create(testFilePath: string, options: SnapshotStateOptions): Promise<SnapshotState>;
82
- get environment(): SnapshotEnvironment;
83
- markSnapshotsAsCheckedForTest(testName: string): void;
84
- clearTest(testId: string): void;
85
- protected _inferInlineSnapshotStack(stacks: ParsedStack[]): ParsedStack | null;
86
- private _addSnapshot;
87
- save(): Promise<SaveStatus>;
88
- getUncheckedCount(): number;
89
- getUncheckedKeys(): Array<string>;
90
- removeUncheckedKeys(): void;
91
- match({ testId, testName, received, key, inlineSnapshot, isInline, error, rawSnapshot, }: SnapshotMatchOptions): SnapshotReturnOptions;
92
- pack(): Promise<SnapshotResult>;
41
+ testFilePath: string;
42
+ snapshotPath: string;
43
+ private _counters;
44
+ private _dirty;
45
+ private _updateSnapshot;
46
+ private _snapshotData;
47
+ private _initialData;
48
+ private _inlineSnapshots;
49
+ private _inlineSnapshotStacks;
50
+ private _testIdToKeys;
51
+ private _rawSnapshots;
52
+ private _uncheckedKeys;
53
+ private _snapshotFormat;
54
+ private _environment;
55
+ private _fileExists;
56
+ expand: boolean;
57
+ private _added;
58
+ private _matched;
59
+ private _unmatched;
60
+ private _updated;
61
+ get added(): CounterMap<string>;
62
+ set added(value: number);
63
+ get matched(): CounterMap<string>;
64
+ set matched(value: number);
65
+ get unmatched(): CounterMap<string>;
66
+ set unmatched(value: number);
67
+ get updated(): CounterMap<string>;
68
+ set updated(value: number);
69
+ private constructor();
70
+ static create(testFilePath: string, options: SnapshotStateOptions): Promise<SnapshotState>;
71
+ get environment(): SnapshotEnvironment;
72
+ markSnapshotsAsCheckedForTest(testName: string): void;
73
+ clearTest(testId: string): void;
74
+ protected _inferInlineSnapshotStack(stacks: ParsedStack[]): ParsedStack | null;
75
+ private _addSnapshot;
76
+ save(): Promise<SaveStatus>;
77
+ getUncheckedCount(): number;
78
+ getUncheckedKeys(): Array<string>;
79
+ removeUncheckedKeys(): void;
80
+ match({ testId, testName, received, key, inlineSnapshot, isInline, error, rawSnapshot }: SnapshotMatchOptions): SnapshotReturnOptions;
81
+ pack(): Promise<SnapshotResult>;
93
82
  }
94
83
 
95
84
  interface AssertOptions {
96
- received: unknown;
97
- filepath: string;
98
- name: string;
99
- /**
100
- * Not required but needed for `SnapshotClient.clearTest` to implement test-retry behavior.
101
- * @default name
102
- */
103
- testId?: string;
104
- message?: string;
105
- isInline?: boolean;
106
- properties?: object;
107
- inlineSnapshot?: string;
108
- error?: Error;
109
- errorMessage?: string;
110
- rawSnapshot?: RawSnapshotInfo;
85
+ received: unknown;
86
+ filepath: string;
87
+ name: string;
88
+ /**
89
+ * Not required but needed for `SnapshotClient.clearTest` to implement test-retry behavior.
90
+ * @default name
91
+ */
92
+ testId?: string;
93
+ message?: string;
94
+ isInline?: boolean;
95
+ properties?: object;
96
+ inlineSnapshot?: string;
97
+ error?: Error;
98
+ errorMessage?: string;
99
+ rawSnapshot?: RawSnapshotInfo;
111
100
  }
112
101
  interface SnapshotClientOptions {
113
- isEqual?: (received: unknown, expected: unknown) => boolean;
102
+ isEqual?: (received: unknown, expected: unknown) => boolean;
114
103
  }
115
104
  declare class SnapshotClient {
116
- private options;
117
- snapshotStateMap: Map<string, SnapshotState>;
118
- constructor(options?: SnapshotClientOptions);
119
- setup(filepath: string, options: SnapshotStateOptions): Promise<void>;
120
- finish(filepath: string): Promise<SnapshotResult>;
121
- skipTest(filepath: string, testName: string): void;
122
- clearTest(filepath: string, testId: string): void;
123
- getSnapshotState(filepath: string): SnapshotState;
124
- assert(options: AssertOptions): void;
125
- assertRaw(options: AssertOptions): Promise<void>;
126
- clear(): void;
105
+ private options;
106
+ snapshotStateMap: Map<string, SnapshotState>;
107
+ constructor(options?: SnapshotClientOptions);
108
+ setup(filepath: string, options: SnapshotStateOptions): Promise<void>;
109
+ finish(filepath: string): Promise<SnapshotResult>;
110
+ skipTest(filepath: string, testName: string): void;
111
+ clearTest(filepath: string, testId: string): void;
112
+ getSnapshotState(filepath: string): SnapshotState;
113
+ assert(options: AssertOptions): void;
114
+ assertRaw(options: AssertOptions): Promise<void>;
115
+ clear(): void;
127
116
  }
128
117
 
129
118
  declare function stripSnapshotIndentation(inlineSnapshot: string): string;
130
119
 
131
120
  /**
132
- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
133
- *
134
- * This source code is licensed under the MIT license found in the
135
- * LICENSE file in the root directory of this source tree.
136
- */
121
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
122
+ *
123
+ * This source code is licensed under the MIT license found in the
124
+ * LICENSE file in the root directory of this source tree.
125
+ */
137
126
 
138
127
  declare function addSerializer(plugin: Plugin): void;
139
128
  declare function getSerializers(): Plugins;
package/dist/manager.d.ts CHANGED
@@ -1,18 +1,18 @@
1
- import { S as SnapshotStateOptions, e as SnapshotSummary, b as SnapshotResult } from './rawSnapshot-DOKg5unn.js';
1
+ import { S as SnapshotStateOptions, e as SnapshotSummary, b as SnapshotResult } from './rawSnapshot.d-lFsMJFUd.js';
2
2
  import '@vitest/pretty-format';
3
- import './environment-Ddx0EDtY.js';
3
+ import './environment.d-DHdQ1Csl.js';
4
4
 
5
5
  declare class SnapshotManager {
6
- options: Omit<SnapshotStateOptions, 'snapshotEnvironment'>;
7
- summary: SnapshotSummary;
8
- extension: string;
9
- constructor(options: Omit<SnapshotStateOptions, 'snapshotEnvironment'>);
10
- clear(): void;
11
- add(result: SnapshotResult): void;
12
- resolvePath<T = any>(testPath: string, context?: T): string;
13
- resolveRawPath(testPath: string, rawPath: string): string;
6
+ options: Omit<SnapshotStateOptions, "snapshotEnvironment">;
7
+ summary: SnapshotSummary;
8
+ extension: string;
9
+ constructor(options: Omit<SnapshotStateOptions, "snapshotEnvironment">);
10
+ clear(): void;
11
+ add(result: SnapshotResult): void;
12
+ resolvePath<T = any>(testPath: string, context?: T): string;
13
+ resolveRawPath(testPath: string, rawPath: string): string;
14
14
  }
15
- declare function emptySummary(options: Omit<SnapshotStateOptions, 'snapshotEnvironment'>): SnapshotSummary;
15
+ declare function emptySummary(options: Omit<SnapshotStateOptions, "snapshotEnvironment">): SnapshotSummary;
16
16
  declare function addSnapshotResult(summary: SnapshotSummary, result: SnapshotResult): void;
17
17
 
18
18
  export { SnapshotManager, addSnapshotResult, emptySummary };
@@ -0,0 +1,61 @@
1
+ import { OptionsReceived, Plugin } from '@vitest/pretty-format';
2
+ import { S as SnapshotEnvironment } from './environment.d-DHdQ1Csl.js';
3
+
4
+ type SnapshotData = Record<string, string>;
5
+ type SnapshotUpdateState = "all" | "new" | "none";
6
+ type SnapshotSerializer = Plugin;
7
+ interface SnapshotStateOptions {
8
+ updateSnapshot: SnapshotUpdateState;
9
+ snapshotEnvironment: SnapshotEnvironment;
10
+ expand?: boolean;
11
+ snapshotFormat?: OptionsReceived;
12
+ resolveSnapshotPath?: (path: string, extension: string, context?: any) => string;
13
+ }
14
+ interface SnapshotMatchOptions {
15
+ testId: string;
16
+ testName: string;
17
+ received: unknown;
18
+ key?: string;
19
+ inlineSnapshot?: string;
20
+ isInline: boolean;
21
+ error?: Error;
22
+ rawSnapshot?: RawSnapshotInfo;
23
+ }
24
+ interface SnapshotResult {
25
+ filepath: string;
26
+ added: number;
27
+ fileDeleted: boolean;
28
+ matched: number;
29
+ unchecked: number;
30
+ uncheckedKeys: Array<string>;
31
+ unmatched: number;
32
+ updated: number;
33
+ }
34
+ interface UncheckedSnapshot {
35
+ filePath: string;
36
+ keys: Array<string>;
37
+ }
38
+ interface SnapshotSummary {
39
+ added: number;
40
+ didUpdate: boolean;
41
+ failure: boolean;
42
+ filesAdded: number;
43
+ filesRemoved: number;
44
+ filesRemovedList: Array<string>;
45
+ filesUnmatched: number;
46
+ filesUpdated: number;
47
+ matched: number;
48
+ total: number;
49
+ unchecked: number;
50
+ uncheckedKeysByFile: Array<UncheckedSnapshot>;
51
+ unmatched: number;
52
+ updated: number;
53
+ }
54
+
55
+ interface RawSnapshotInfo {
56
+ file: string;
57
+ readonly?: boolean;
58
+ content?: string;
59
+ }
60
+
61
+ export type { RawSnapshotInfo as R, SnapshotStateOptions as S, UncheckedSnapshot as U, SnapshotMatchOptions as a, SnapshotResult as b, SnapshotData as c, SnapshotSerializer as d, SnapshotSummary as e, SnapshotUpdateState as f };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/snapshot",
3
3
  "type": "module",
4
- "version": "3.0.8",
4
+ "version": "3.0.9",
5
5
  "description": "Vitest snapshot manager",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -40,12 +40,12 @@
40
40
  "dependencies": {
41
41
  "magic-string": "^0.30.17",
42
42
  "pathe": "^2.0.3",
43
- "@vitest/pretty-format": "3.0.8"
43
+ "@vitest/pretty-format": "3.0.9"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/natural-compare": "^1.4.3",
47
47
  "natural-compare": "^1.4.0",
48
- "@vitest/utils": "3.0.8"
48
+ "@vitest/utils": "3.0.9"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "rimraf dist && rollup -c",
@@ -1,22 +0,0 @@
1
- interface ParsedStack {
2
- method: string;
3
- file: string;
4
- line: number;
5
- column: number;
6
- }
7
-
8
- interface SnapshotEnvironment {
9
- getVersion: () => string;
10
- getHeader: () => string;
11
- resolvePath: (filepath: string) => Promise<string>;
12
- resolveRawPath: (testPath: string, rawPath: string) => Promise<string>;
13
- saveSnapshotFile: (filepath: string, snapshot: string) => Promise<void>;
14
- readSnapshotFile: (filepath: string) => Promise<string | null>;
15
- removeSnapshotFile: (filepath: string) => Promise<void>;
16
- processStackTrace?: (stack: ParsedStack) => ParsedStack;
17
- }
18
- interface SnapshotEnvironmentOptions {
19
- snapshotsDirName?: string;
20
- }
21
-
22
- export type { SnapshotEnvironment as S, SnapshotEnvironmentOptions as a };
@@ -1,61 +0,0 @@
1
- import { OptionsReceived, Plugin } from '@vitest/pretty-format';
2
- import { S as SnapshotEnvironment } from './environment-Ddx0EDtY.js';
3
-
4
- type SnapshotData = Record<string, string>;
5
- type SnapshotUpdateState = 'all' | 'new' | 'none';
6
- type SnapshotSerializer = Plugin;
7
- interface SnapshotStateOptions {
8
- updateSnapshot: SnapshotUpdateState;
9
- snapshotEnvironment: SnapshotEnvironment;
10
- expand?: boolean;
11
- snapshotFormat?: OptionsReceived;
12
- resolveSnapshotPath?: (path: string, extension: string, context?: any) => string;
13
- }
14
- interface SnapshotMatchOptions {
15
- testId: string;
16
- testName: string;
17
- received: unknown;
18
- key?: string;
19
- inlineSnapshot?: string;
20
- isInline: boolean;
21
- error?: Error;
22
- rawSnapshot?: RawSnapshotInfo;
23
- }
24
- interface SnapshotResult {
25
- filepath: string;
26
- added: number;
27
- fileDeleted: boolean;
28
- matched: number;
29
- unchecked: number;
30
- uncheckedKeys: Array<string>;
31
- unmatched: number;
32
- updated: number;
33
- }
34
- interface UncheckedSnapshot {
35
- filePath: string;
36
- keys: Array<string>;
37
- }
38
- interface SnapshotSummary {
39
- added: number;
40
- didUpdate: boolean;
41
- failure: boolean;
42
- filesAdded: number;
43
- filesRemoved: number;
44
- filesRemovedList: Array<string>;
45
- filesUnmatched: number;
46
- filesUpdated: number;
47
- matched: number;
48
- total: number;
49
- unchecked: number;
50
- uncheckedKeysByFile: Array<UncheckedSnapshot>;
51
- unmatched: number;
52
- updated: number;
53
- }
54
-
55
- interface RawSnapshotInfo {
56
- file: string;
57
- readonly?: boolean;
58
- content?: string;
59
- }
60
-
61
- export type { RawSnapshotInfo as R, SnapshotStateOptions as S, UncheckedSnapshot as U, SnapshotMatchOptions as a, SnapshotResult as b, SnapshotData as c, SnapshotSerializer as d, SnapshotSummary as e, SnapshotUpdateState as f };