@jsenv/snapshot 2.13.9 → 2.14.1
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 +8 -8
- package/src/main.js +1 -0
- package/src/side_effects/capture_logs_into_file.js +14 -0
- package/src/side_effects/filesystem/spy_filesystem_calls.js +2 -7
- package/src/side_effects/log/log_side_effects.js +1 -1
- package/src/side_effects/render_logs_gif.js +2 -2
- package/src/side_effects/render_logs_svg.js +27 -0
- package/src/side_effects/snapshot_tests.js +21 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/snapshot",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.1",
|
|
4
4
|
"description": "Snapshot testing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
],
|
|
32
32
|
"sideEffects": false,
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@jsenv/assert": "4.4.
|
|
35
|
-
"@jsenv/ast": "6.6.
|
|
34
|
+
"@jsenv/assert": "4.4.5",
|
|
35
|
+
"@jsenv/ast": "6.6.7",
|
|
36
36
|
"@jsenv/exception": "1.1.7",
|
|
37
|
-
"@jsenv/humanize": "1.
|
|
38
|
-
"@jsenv/filesystem": "4.14.
|
|
39
|
-
"@jsenv/terminal-recorder": "1.5.
|
|
40
|
-
"@jsenv/urls": "2.7.
|
|
41
|
-
"@jsenv/utils": "2.
|
|
37
|
+
"@jsenv/humanize": "1.4.0",
|
|
38
|
+
"@jsenv/filesystem": "4.14.6",
|
|
39
|
+
"@jsenv/terminal-recorder": "1.5.10",
|
|
40
|
+
"@jsenv/urls": "2.7.1",
|
|
41
|
+
"@jsenv/utils": "2.3.0",
|
|
42
42
|
"ansi-regex": "6.1.0",
|
|
43
43
|
"pixelmatch": "7.1.0",
|
|
44
44
|
"prettier": "3.5.3",
|
package/src/main.js
CHANGED
|
@@ -5,6 +5,7 @@ export {
|
|
|
5
5
|
export { createReplaceFilesystemWellKnownValues } from "./filesystem_well_known_values.js";
|
|
6
6
|
export { getCallerLocation } from "./get_caller_location.js";
|
|
7
7
|
export { replaceFluctuatingValues } from "./replace_fluctuating_values.js";
|
|
8
|
+
export { captureLogsIntoFile } from "./side_effects/capture_logs_into_file.js";
|
|
8
9
|
export { renderLogsGif } from "./side_effects/render_logs_gif.js";
|
|
9
10
|
export { snapshotSideEffects } from "./side_effects/snapshot_side_effects.js";
|
|
10
11
|
export { snapshotTests } from "./side_effects/snapshot_tests.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCaptureSideEffects } from "./create_capture_side_effects.js";
|
|
2
|
+
import { renderLogsSvg } from "./render_logs_svg.js";
|
|
3
|
+
|
|
4
|
+
export const captureLogsIntoFile = async (fn, { svgFileUrl }) => {
|
|
5
|
+
const capture = createCaptureSideEffects({
|
|
6
|
+
executionEffects: false,
|
|
7
|
+
filesystemEffects: false,
|
|
8
|
+
logEffects: {
|
|
9
|
+
group: false,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
const sideEffects = await capture(fn);
|
|
13
|
+
renderLogsSvg(sideEffects, svgFileUrl);
|
|
14
|
+
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// https://github.com/tschaub/mock-fs/issues/348
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
|
|
7
|
+
compareFileUrls,
|
|
8
8
|
removeDirectorySync,
|
|
9
9
|
removeFileSync,
|
|
10
10
|
writeFileSync,
|
|
@@ -335,12 +335,7 @@ export const spyFilesystemCalls = (
|
|
|
335
335
|
}
|
|
336
336
|
fileRestoreMap.clear();
|
|
337
337
|
const dirUrls = Array.from(dirRestoreMap.keys());
|
|
338
|
-
dirUrls.sort(
|
|
339
|
-
return comparePathnames(
|
|
340
|
-
new URL(left).pathname,
|
|
341
|
-
new URL(right).pathname,
|
|
342
|
-
);
|
|
343
|
-
});
|
|
338
|
+
dirUrls.sort(compareFileUrls);
|
|
344
339
|
for (const dirUrl of dirUrls) {
|
|
345
340
|
const restore = dirRestoreMap.get(dirUrl);
|
|
346
341
|
restore();
|
|
@@ -71,7 +71,7 @@ export const logSideEffects = (logSideEffectsOptions) => {
|
|
|
71
71
|
const logGroupSideEffect = {
|
|
72
72
|
code: "log_group",
|
|
73
73
|
type: `log_group`,
|
|
74
|
-
value: {},
|
|
74
|
+
value: {}, // TODO: the concatenation of the logs
|
|
75
75
|
render: {
|
|
76
76
|
md: (options) => {
|
|
77
77
|
const renderLogGroup = () => {
|
|
@@ -2,7 +2,7 @@ import { writeFileSync } from "@jsenv/filesystem";
|
|
|
2
2
|
import { startTerminalRecording } from "@jsenv/terminal-recorder";
|
|
3
3
|
import { isLogSideEffect } from "./log/log_side_effects.js";
|
|
4
4
|
|
|
5
|
-
export const renderLogsGif = async (sideEffects,
|
|
5
|
+
export const renderLogsGif = async (sideEffects, gifFileUrl) => {
|
|
6
6
|
const terminalRecorder = await startTerminalRecording({
|
|
7
7
|
gif: true,
|
|
8
8
|
});
|
|
@@ -15,5 +15,5 @@ export const renderLogsGif = async (sideEffects, gitFileUrl) => {
|
|
|
15
15
|
}
|
|
16
16
|
const result = await terminalRecorder.stop();
|
|
17
17
|
const gif = await result.gif();
|
|
18
|
-
writeFileSync(new URL(
|
|
18
|
+
writeFileSync(new URL(gifFileUrl), gif);
|
|
19
19
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { writeFileSync } from "@jsenv/filesystem";
|
|
2
|
+
import { startTerminalRecording } from "@jsenv/terminal-recorder";
|
|
3
|
+
import { isLogSideEffect } from "./log/log_side_effects.js";
|
|
4
|
+
|
|
5
|
+
export const renderLogsSvg = async (
|
|
6
|
+
sideEffects,
|
|
7
|
+
svgFileUrl,
|
|
8
|
+
svgOptions = {},
|
|
9
|
+
) => {
|
|
10
|
+
const terminalRecorder = await startTerminalRecording({
|
|
11
|
+
svg: {
|
|
12
|
+
title: "Terminal",
|
|
13
|
+
width: "auto",
|
|
14
|
+
...svgOptions,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
for (const sideEffect of sideEffects) {
|
|
18
|
+
if (isLogSideEffect(sideEffect)) {
|
|
19
|
+
await terminalRecorder.write(`${sideEffect.value}\n`, {
|
|
20
|
+
delay: sideEffect.delay,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const result = await terminalRecorder.stop();
|
|
25
|
+
const svg = await result.svg();
|
|
26
|
+
writeFileSync(new URL(svgFileUrl), svg);
|
|
27
|
+
};
|
|
@@ -31,10 +31,17 @@ import { renderSideEffects, renderSmallLink } from "./render_side_effects.js";
|
|
|
31
31
|
* Urls of filesystem side effects will be relative to this base directory
|
|
32
32
|
* Default to the directory containing @sourceFileUrl
|
|
33
33
|
*/
|
|
34
|
+
let preconfiguredOptions = null;
|
|
34
35
|
export const snapshotTests = async (
|
|
35
36
|
sourceFileUrl,
|
|
36
37
|
fnRegisteringTest,
|
|
37
|
-
{
|
|
38
|
+
options = {},
|
|
39
|
+
) => {
|
|
40
|
+
if (preconfiguredOptions) {
|
|
41
|
+
Object.assign(options, preconfiguredOptions);
|
|
42
|
+
preconfiguredOptions = null;
|
|
43
|
+
}
|
|
44
|
+
let {
|
|
38
45
|
outFilePattern = "./_[source_filename]/[filename]",
|
|
39
46
|
filesystemActions,
|
|
40
47
|
rootDirectoryUrl,
|
|
@@ -43,11 +50,10 @@ export const snapshotTests = async (
|
|
|
43
50
|
logEffects,
|
|
44
51
|
filesystemEffects,
|
|
45
52
|
throwWhenDiff = process.env.CI,
|
|
46
|
-
} =
|
|
47
|
-
) => {
|
|
53
|
+
} = options;
|
|
48
54
|
filesystemActions = {
|
|
49
55
|
"**": "compare",
|
|
50
|
-
...filesystemActions,
|
|
56
|
+
...options.filesystemActions,
|
|
51
57
|
"**/*.svg": "compare_presence_only",
|
|
52
58
|
};
|
|
53
59
|
|
|
@@ -222,6 +228,17 @@ export const snapshotTests = async (
|
|
|
222
228
|
|
|
223
229
|
return { dirUrlMap, sideEffectsMap };
|
|
224
230
|
};
|
|
231
|
+
// preConfigure is just so that when we update the snapshot test options
|
|
232
|
+
// it does not influence too much the formatting
|
|
233
|
+
// snapshotTests(import.meta.url, ({ test }) => { }, options)
|
|
234
|
+
// becomes
|
|
235
|
+
// snapshotTests.prefConfigure(options)
|
|
236
|
+
// snapshotTests(import.meta.url, ({ test }) => { })
|
|
237
|
+
// which are equivalent
|
|
238
|
+
|
|
239
|
+
snapshotTests.prefConfigure = (options) => {
|
|
240
|
+
preconfiguredOptions = options;
|
|
241
|
+
};
|
|
225
242
|
|
|
226
243
|
// see https://github.com/parshap/node-sanitize-filename/blob/master/index.js
|
|
227
244
|
const asValidFilename = (string) => {
|