@jsenv/snapshot 2.7.1 → 2.7.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/package.json +2 -3
- package/src/side_effects/snapshot_tests.js +13 -0
- package/src/cli.mjs +0 -54
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/snapshot",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.3",
|
|
4
4
|
"description": "Snapshot testing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"url": "https://github.com/jsenv/core",
|
|
13
13
|
"directory": "packages/independent/snapshot"
|
|
14
14
|
},
|
|
15
|
-
"bin": "./src/cli.mjs",
|
|
16
15
|
"engines": {
|
|
17
16
|
"node": ">=20.0.0"
|
|
18
17
|
},
|
|
@@ -37,7 +36,7 @@
|
|
|
37
36
|
"@jsenv/assert": "4.1.13",
|
|
38
37
|
"@jsenv/ast": "6.2.12",
|
|
39
38
|
"@jsenv/exception": "1.0.1",
|
|
40
|
-
"@jsenv/filesystem": "4.9.
|
|
39
|
+
"@jsenv/filesystem": "4.9.8",
|
|
41
40
|
"@jsenv/terminal-recorder": "1.4.2",
|
|
42
41
|
"@jsenv/urls": "2.5.1",
|
|
43
42
|
"@jsenv/utils": "2.1.2",
|
|
@@ -45,12 +45,20 @@ export const snapshotTests = async (
|
|
|
45
45
|
sideEffectFileUrl = new URL(sideEffectFileUrl, testFileUrl);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
const dirUrlMap = new Map();
|
|
49
|
+
const sideEffectsMap = new Map();
|
|
48
50
|
const testMap = new Map();
|
|
49
51
|
const onlyTestMap = new Map();
|
|
50
52
|
const test = (scenario, fn, options) => {
|
|
53
|
+
if (testMap.has(scenario) || onlyTestMap.has(scenario)) {
|
|
54
|
+
console.warn(`test override "${scenario}"`);
|
|
55
|
+
}
|
|
51
56
|
testMap.set(scenario, { fn, options, callSite: getCallerLocation(2) });
|
|
52
57
|
};
|
|
53
58
|
test.ONLY = (scenario, fn, options) => {
|
|
59
|
+
if (testMap.has(scenario) || onlyTestMap.has(scenario)) {
|
|
60
|
+
console.warn(`test override "${scenario}"`);
|
|
61
|
+
}
|
|
54
62
|
onlyTestMap.set(scenario, { fn, options, callSite: getCallerLocation(2) });
|
|
55
63
|
};
|
|
56
64
|
fnRegisteringTest({ test });
|
|
@@ -89,6 +97,7 @@ export const snapshotTests = async (
|
|
|
89
97
|
callSite: linkToEachSource ? callSite : undefined,
|
|
90
98
|
baseDirectory: String(new URL("./", callSite.url)),
|
|
91
99
|
});
|
|
100
|
+
sideEffectsMap.set(scenario, sideEffects);
|
|
92
101
|
const testScenario = asValidFilename(scenario);
|
|
93
102
|
let outDirectoryRelativeUrl = outDirectoryPattern
|
|
94
103
|
.replaceAll("[test_name]", testName)
|
|
@@ -109,6 +118,8 @@ export const snapshotTests = async (
|
|
|
109
118
|
const outFileUrl = new URL(outFileRelativeUrl, testFileUrl).href;
|
|
110
119
|
return outFileUrl;
|
|
111
120
|
};
|
|
121
|
+
const outFileDirectoryUrl = generateOutFileUrl("");
|
|
122
|
+
dirUrlMap.set(scenario, outFileDirectoryUrl);
|
|
112
123
|
const sideEffectsMarkdown = renderSideEffects(sideEffects, {
|
|
113
124
|
sideEffectFileUrl,
|
|
114
125
|
outDirectoryUrl,
|
|
@@ -125,6 +136,8 @@ export const snapshotTests = async (
|
|
|
125
136
|
mockFluctuatingValues: false,
|
|
126
137
|
throwWhenDiff,
|
|
127
138
|
});
|
|
139
|
+
|
|
140
|
+
return { dirUrlMap, sideEffectsMap };
|
|
128
141
|
};
|
|
129
142
|
|
|
130
143
|
const generateExecutingLink = (sourceFileUrl, sideEffectFileUrl) => {
|
package/src/cli.mjs
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { clearDirectorySync } from "@jsenv/filesystem";
|
|
4
|
-
import { pathToFileURL } from "node:url";
|
|
5
|
-
import { parseArgs } from "node:util";
|
|
6
|
-
|
|
7
|
-
const options = {
|
|
8
|
-
help: {
|
|
9
|
-
type: "boolean",
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
const { values, positionals } = parseArgs({
|
|
13
|
-
options,
|
|
14
|
-
allowPositionals: true,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
if (values.help || positionals.length === 0) {
|
|
18
|
-
console.log(`snapshot: Manage snapshot files generated during tests.
|
|
19
|
-
|
|
20
|
-
Usage: npx @jsenv/snapshot clear [pattern]
|
|
21
|
-
|
|
22
|
-
https://github.com/jsenv/core/tree/main/packages/independent/snapshot
|
|
23
|
-
|
|
24
|
-
pattern: files matching this pattern will be removed; can use "*" and "**"
|
|
25
|
-
`);
|
|
26
|
-
process.exit(0);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const commandHandlers = {
|
|
30
|
-
clear: (pattern) => {
|
|
31
|
-
const currentDirectoryPath = process.cwd();
|
|
32
|
-
const currentDirectoryUrl = pathToFileURL(`${currentDirectoryPath}/`);
|
|
33
|
-
console.log(`clear files matching ${pattern} in ${currentDirectoryPath}`);
|
|
34
|
-
clearDirectorySync(currentDirectoryUrl, pattern);
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const [command] = positionals;
|
|
39
|
-
const commandHandler = commandHandlers[command];
|
|
40
|
-
|
|
41
|
-
if (!commandHandler) {
|
|
42
|
-
console.error(`Error: unknown command ${command}.`);
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (commandHandler.length) {
|
|
47
|
-
const args = positionals.slice(1);
|
|
48
|
-
if (args.length === 0) {
|
|
49
|
-
console.error(`Error: "${command}" command expect arguments.`);
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
await commandHandler(...positionals.slice(1));
|