@vitest/snapshot 0.30.0
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/LICENSE +22 -0
- package/README.md +75 -0
- package/dist/environment-8fbbf71b.d.ts +12 -0
- package/dist/environment.d.ts +14 -0
- package/dist/environment.js +40 -0
- package/dist/index-2c775746.d.ts +59 -0
- package/dist/index.d.ts +112 -0
- package/dist/index.js +940 -0
- package/dist/manager.d.ts +18 -0
- package/dist/manager.js +74 -0
- package/package.json +49 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { S as SnapshotStateOptions, e as SnapshotSummary, b as SnapshotResult } from './index-2c775746.js';
|
|
2
|
+
import 'pretty-format';
|
|
3
|
+
import './environment-8fbbf71b.js';
|
|
4
|
+
|
|
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(testPath: string): string;
|
|
13
|
+
resolveRawPath(testPath: string, rawPath: string): string;
|
|
14
|
+
}
|
|
15
|
+
declare function emptySummary(options: Omit<SnapshotStateOptions, 'snapshotEnvironment'>): SnapshotSummary;
|
|
16
|
+
declare function addSnapshotResult(summary: SnapshotSummary, result: SnapshotResult): void;
|
|
17
|
+
|
|
18
|
+
export { SnapshotManager, addSnapshotResult, emptySummary };
|
package/dist/manager.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { join, dirname, basename, isAbsolute, resolve } from 'pathe';
|
|
2
|
+
|
|
3
|
+
class SnapshotManager {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
this.options = options;
|
|
6
|
+
this.summary = void 0;
|
|
7
|
+
this.extension = ".snap";
|
|
8
|
+
this.clear();
|
|
9
|
+
}
|
|
10
|
+
clear() {
|
|
11
|
+
this.summary = emptySummary(this.options);
|
|
12
|
+
}
|
|
13
|
+
add(result) {
|
|
14
|
+
addSnapshotResult(this.summary, result);
|
|
15
|
+
}
|
|
16
|
+
resolvePath(testPath) {
|
|
17
|
+
const resolver = this.options.resolveSnapshotPath || (() => {
|
|
18
|
+
return join(
|
|
19
|
+
join(
|
|
20
|
+
dirname(testPath),
|
|
21
|
+
"__snapshots__"
|
|
22
|
+
),
|
|
23
|
+
`${basename(testPath)}${this.extension}`
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
return resolver(testPath, this.extension);
|
|
27
|
+
}
|
|
28
|
+
resolveRawPath(testPath, rawPath) {
|
|
29
|
+
return isAbsolute(rawPath) ? rawPath : resolve(dirname(testPath), rawPath);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function emptySummary(options) {
|
|
33
|
+
const summary = {
|
|
34
|
+
added: 0,
|
|
35
|
+
failure: false,
|
|
36
|
+
filesAdded: 0,
|
|
37
|
+
filesRemoved: 0,
|
|
38
|
+
filesRemovedList: [],
|
|
39
|
+
filesUnmatched: 0,
|
|
40
|
+
filesUpdated: 0,
|
|
41
|
+
matched: 0,
|
|
42
|
+
total: 0,
|
|
43
|
+
unchecked: 0,
|
|
44
|
+
uncheckedKeysByFile: [],
|
|
45
|
+
unmatched: 0,
|
|
46
|
+
updated: 0,
|
|
47
|
+
didUpdate: options.updateSnapshot === "all"
|
|
48
|
+
};
|
|
49
|
+
return summary;
|
|
50
|
+
}
|
|
51
|
+
function addSnapshotResult(summary, result) {
|
|
52
|
+
if (result.added)
|
|
53
|
+
summary.filesAdded++;
|
|
54
|
+
if (result.fileDeleted)
|
|
55
|
+
summary.filesRemoved++;
|
|
56
|
+
if (result.unmatched)
|
|
57
|
+
summary.filesUnmatched++;
|
|
58
|
+
if (result.updated)
|
|
59
|
+
summary.filesUpdated++;
|
|
60
|
+
summary.added += result.added;
|
|
61
|
+
summary.matched += result.matched;
|
|
62
|
+
summary.unchecked += result.unchecked;
|
|
63
|
+
if (result.uncheckedKeys && result.uncheckedKeys.length > 0) {
|
|
64
|
+
summary.uncheckedKeysByFile.push({
|
|
65
|
+
filePath: result.filepath,
|
|
66
|
+
keys: result.uncheckedKeys
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
summary.unmatched += result.unmatched;
|
|
70
|
+
summary.updated += result.updated;
|
|
71
|
+
summary.total += result.added + result.matched + result.unmatched + result.updated;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { SnapshotManager, addSnapshotResult, emptySummary };
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vitest/snapshot",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.30.0",
|
|
5
|
+
"description": "Vitest Snapshot Resolver",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/vitest-dev/vitest.git",
|
|
10
|
+
"directory": "packages/snapshot"
|
|
11
|
+
},
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./environment": {
|
|
19
|
+
"types": "./dist/environment.d.ts",
|
|
20
|
+
"import": "./dist/environment.js"
|
|
21
|
+
},
|
|
22
|
+
"./manager": {
|
|
23
|
+
"types": "./dist/manager.d.ts",
|
|
24
|
+
"import": "./dist/manager.js"
|
|
25
|
+
},
|
|
26
|
+
"./*": "./*"
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"*.d.ts"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"magic-string": "^0.30.0",
|
|
37
|
+
"pathe": "^1.1.0",
|
|
38
|
+
"pretty-format": "^27.5.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/natural-compare": "^1.4.1",
|
|
42
|
+
"natural-compare": "^1.4.0",
|
|
43
|
+
"@vitest/utils": "0.30.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "rimraf dist && rollup -c",
|
|
47
|
+
"dev": "rollup -c --watch"
|
|
48
|
+
}
|
|
49
|
+
}
|