@jsenv/snapshot 2.16.1 → 2.16.2
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.2",
|
|
4
4
|
"description": "Snapshot testing",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@jsenv/assert": "4.5.5",
|
|
29
|
-
"@jsenv/ast": "6.7.
|
|
29
|
+
"@jsenv/ast": "6.7.18",
|
|
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.11",
|
|
32
|
+
"@jsenv/humanize": "1.7.3",
|
|
33
|
+
"@jsenv/terminal-recorder": "1.5.32",
|
|
34
34
|
"@jsenv/url-meta": "8.5.7",
|
|
35
|
-
"@jsenv/urls": "2.9.
|
|
35
|
+
"@jsenv/urls": "2.9.5",
|
|
36
36
|
"@jsenv/utils": "2.3.1",
|
|
37
37
|
"ansi-regex": "6.2.2",
|
|
38
38
|
"pixelmatch": "7.1.0",
|
|
@@ -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,7 @@ 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 jsonStringifyWithUndefined(replaced);
|
|
113
114
|
}
|
|
114
115
|
if (stringType === "html" || stringType === "xml") {
|
|
115
116
|
// do parse html
|
|
@@ -165,11 +166,19 @@ export const replaceFluctuatingValues = (
|
|
|
165
166
|
return regexpSource;
|
|
166
167
|
}
|
|
167
168
|
const jsValueReplaced = replaceInObject(value, { replace: replaceThings });
|
|
168
|
-
return
|
|
169
|
+
return jsonStringifyWithUndefined(jsValueReplaced);
|
|
169
170
|
}
|
|
170
171
|
return value;
|
|
171
172
|
};
|
|
172
173
|
|
|
174
|
+
// Use humanize for better JavaScript value representation
|
|
175
|
+
const jsonStringifyWithUndefined = (obj) => {
|
|
176
|
+
return humanize(obj, {
|
|
177
|
+
quote: "auto", // Let humanize decide the best quotes
|
|
178
|
+
indentSize: 2,
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
|
|
173
182
|
const replaceInObject = (object, { replace }) => {
|
|
174
183
|
const deepCopy = (
|
|
175
184
|
value,
|
|
@@ -53,6 +53,7 @@ export const snapshotTests = async (
|
|
|
53
53
|
logEffects,
|
|
54
54
|
filesystemEffects,
|
|
55
55
|
throwWhenDiff = process.env.CI,
|
|
56
|
+
sourceLocation = false,
|
|
56
57
|
} = options;
|
|
57
58
|
filesystemActions = {
|
|
58
59
|
"**": "compare",
|
|
@@ -184,10 +185,13 @@ export const snapshotTests = async (
|
|
|
184
185
|
});
|
|
185
186
|
sideEffectsMap.set(scenario, sideEffects);
|
|
186
187
|
const sideEffectsMarkdown = renderSideEffects(sideEffects, {
|
|
187
|
-
sourceFileUrl:
|
|
188
|
+
sourceFileUrl: sourceLocation
|
|
189
|
+
? `${callSite.url}#L${callSite.line}`
|
|
190
|
+
: callSite.url,
|
|
188
191
|
sideEffectMdFileUrl: scenarioMdFileUrl,
|
|
189
192
|
generateOutFileUrl: generateScenarioOutFileUrl,
|
|
190
193
|
title: scenario,
|
|
194
|
+
sourceLocation,
|
|
191
195
|
});
|
|
192
196
|
writeFileSync(scenarioMdFileUrl, sideEffectsMarkdown);
|
|
193
197
|
}
|