@jsenv/snapshot 2.16.1 → 2.16.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/snapshot",
|
|
3
|
-
"version": "2.16.
|
|
3
|
+
"version": "2.16.3",
|
|
4
4
|
"description": "Snapshot testing",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@jsenv/assert": "4.5.5",
|
|
29
|
-
"@jsenv/ast": "6.7.
|
|
29
|
+
"@jsenv/ast": "6.7.19",
|
|
30
30
|
"@jsenv/exception": "1.2.1",
|
|
31
|
-
"@jsenv/filesystem": "4.15.
|
|
32
|
-
"@jsenv/humanize": "1.7.
|
|
33
|
-
"@jsenv/terminal-recorder": "1.5.
|
|
31
|
+
"@jsenv/filesystem": "4.15.12",
|
|
32
|
+
"@jsenv/humanize": "1.7.4",
|
|
33
|
+
"@jsenv/terminal-recorder": "1.5.33",
|
|
34
34
|
"@jsenv/url-meta": "8.5.7",
|
|
35
|
-
"@jsenv/urls": "2.9.
|
|
35
|
+
"@jsenv/urls": "2.9.6",
|
|
36
36
|
"@jsenv/utils": "2.3.1",
|
|
37
37
|
"ansi-regex": "6.2.2",
|
|
38
38
|
"pixelmatch": "7.1.0",
|
|
39
39
|
"pngjs": "7.0.0",
|
|
40
|
-
"prettier": "3.
|
|
40
|
+
"prettier": "3.8.1",
|
|
41
41
|
"strip-ansi": "7.1.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
stringifyHtmlAst,
|
|
12
12
|
visitHtmlNodes,
|
|
13
13
|
} from "@jsenv/ast";
|
|
14
|
+
import { humanize } from "@jsenv/humanize";
|
|
14
15
|
import { urlToExtension } from "@jsenv/urls";
|
|
15
16
|
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js";
|
|
16
17
|
import stripAnsi from "strip-ansi";
|
|
@@ -109,7 +110,10 @@ export const replaceFluctuatingValues = (
|
|
|
109
110
|
if (stringType === "json") {
|
|
110
111
|
const jsValue = JSON.parse(value);
|
|
111
112
|
const replaced = replaceInObject(jsValue, { replace: replaceThings });
|
|
112
|
-
return
|
|
113
|
+
return humanize(replaced, {
|
|
114
|
+
quote: `"`, // prefer double for json
|
|
115
|
+
indentSize: 2,
|
|
116
|
+
});
|
|
113
117
|
}
|
|
114
118
|
if (stringType === "html" || stringType === "xml") {
|
|
115
119
|
// do parse html
|
|
@@ -165,7 +169,10 @@ export const replaceFluctuatingValues = (
|
|
|
165
169
|
return regexpSource;
|
|
166
170
|
}
|
|
167
171
|
const jsValueReplaced = replaceInObject(value, { replace: replaceThings });
|
|
168
|
-
return
|
|
172
|
+
return humanize(jsValueReplaced, {
|
|
173
|
+
quote: "auto", // Let humanize decide the best quotes
|
|
174
|
+
indentSize: 2,
|
|
175
|
+
});
|
|
169
176
|
}
|
|
170
177
|
return value;
|
|
171
178
|
};
|
|
@@ -20,6 +20,8 @@ import { renderSideEffects, renderSmallLink } from "./render_side_effects.js";
|
|
|
20
20
|
* Any error thrown by test function is detected and added to side effects
|
|
21
21
|
* @param {boolean} [snapshotTestsOptions.executionEffects.return=true]
|
|
22
22
|
* Test function return value is added to side effects
|
|
23
|
+
* @param {Object} [snapshotTestsOptions.logEffects]
|
|
24
|
+
* Control how console outputs are captured and included in side effects
|
|
23
25
|
* @param {Object} [snapshotTestsOptions.filesystemActions]
|
|
24
26
|
* Control what to do when there is a file side effect
|
|
25
27
|
* "compare", "compare_presence_only", "undo", "ignore"
|
|
@@ -53,6 +55,7 @@ export const snapshotTests = async (
|
|
|
53
55
|
logEffects,
|
|
54
56
|
filesystemEffects,
|
|
55
57
|
throwWhenDiff = process.env.CI,
|
|
58
|
+
sourceLocation = false,
|
|
56
59
|
} = options;
|
|
57
60
|
filesystemActions = {
|
|
58
61
|
"**": "compare",
|
|
@@ -184,10 +187,13 @@ export const snapshotTests = async (
|
|
|
184
187
|
});
|
|
185
188
|
sideEffectsMap.set(scenario, sideEffects);
|
|
186
189
|
const sideEffectsMarkdown = renderSideEffects(sideEffects, {
|
|
187
|
-
sourceFileUrl:
|
|
190
|
+
sourceFileUrl: sourceLocation
|
|
191
|
+
? `${callSite.url}#L${callSite.line}`
|
|
192
|
+
: callSite.url,
|
|
188
193
|
sideEffectMdFileUrl: scenarioMdFileUrl,
|
|
189
194
|
generateOutFileUrl: generateScenarioOutFileUrl,
|
|
190
195
|
title: scenario,
|
|
196
|
+
sourceLocation,
|
|
191
197
|
});
|
|
192
198
|
writeFileSync(scenarioMdFileUrl, sideEffectsMarkdown);
|
|
193
199
|
}
|