@jsenv/snapshot 2.8.6 → 2.8.8
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.8.
|
|
3
|
+
"version": "2.8.8",
|
|
4
4
|
"description": "Snapshot testing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@jsenv/assert": "4.1.15",
|
|
37
37
|
"@jsenv/ast": "6.2.15",
|
|
38
38
|
"@jsenv/exception": "1.0.2",
|
|
39
|
-
"@jsenv/filesystem": "4.
|
|
39
|
+
"@jsenv/filesystem": "4.10.0",
|
|
40
40
|
"@jsenv/terminal-recorder": "1.4.4",
|
|
41
41
|
"@jsenv/urls": "2.5.2",
|
|
42
42
|
"@jsenv/utils": "2.1.2",
|
|
@@ -58,7 +58,6 @@ export const createWellKnown = (name, replacement = name) => {
|
|
|
58
58
|
|
|
59
59
|
export const createReplaceFilesystemWellKnownValues = ({
|
|
60
60
|
rootDirectoryUrl,
|
|
61
|
-
localhostUrl,
|
|
62
61
|
// for unit tests
|
|
63
62
|
isWindows = process.platform === "win32",
|
|
64
63
|
ancestorPackagesDisabled,
|
|
@@ -127,32 +126,9 @@ export const createReplaceFilesystemWellKnownValues = ({
|
|
|
127
126
|
}
|
|
128
127
|
};
|
|
129
128
|
};
|
|
130
|
-
const addWellKnownUrl = (url, replacement) => {
|
|
131
|
-
const wellKnownUrl = {
|
|
132
|
-
url,
|
|
133
|
-
replace: (string) => {
|
|
134
|
-
return string.replaceAll(url, replacement);
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
wellKownUrlArray.push(wellKnownUrl);
|
|
138
|
-
return () => {
|
|
139
|
-
const urlIndex = wellKownUrlArray.indexOf(wellKnownUrl);
|
|
140
|
-
if (urlIndex > -1) {
|
|
141
|
-
wellKownUrlArray.splice(urlIndex, 1);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
129
|
if (rootDirectoryUrl) {
|
|
146
130
|
addWellKnownFileUrl(rootDirectoryUrl, WELL_KNOWN_ROOT);
|
|
147
131
|
}
|
|
148
|
-
if (localhostUrl) {
|
|
149
|
-
addWellKnownUrl(
|
|
150
|
-
localhostUrl,
|
|
151
|
-
localhostUrl.startsWith("https")
|
|
152
|
-
? "https://localhost"
|
|
153
|
-
: "http://localhost",
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
132
|
/*
|
|
157
133
|
* When running code inside a node project ancestor packages
|
|
158
134
|
* should make things super predictible because
|
|
@@ -21,13 +21,11 @@ export const replaceFluctuatingValues = (
|
|
|
21
21
|
{
|
|
22
22
|
stringType,
|
|
23
23
|
rootDirectoryUrl,
|
|
24
|
-
localhostUrl,
|
|
25
24
|
fileUrl,
|
|
26
25
|
preserveAnsi,
|
|
27
26
|
// for unit test
|
|
28
27
|
replaceFilesystemWellKnownValues = createReplaceFilesystemWellKnownValues({
|
|
29
28
|
rootDirectoryUrl,
|
|
30
|
-
localhostUrl,
|
|
31
29
|
}),
|
|
32
30
|
} = {},
|
|
33
31
|
) => {
|
|
@@ -191,6 +189,12 @@ const replaceInObject = (object, { replace }) => {
|
|
|
191
189
|
};
|
|
192
190
|
|
|
193
191
|
const replaceHttpUrls = (source) => {
|
|
192
|
+
source = source.replace(/(https?):\/\/localhost:\d+/g, (match, protocol) => {
|
|
193
|
+
return `${protocol}://localhost`;
|
|
194
|
+
});
|
|
195
|
+
source = source.replace(/(https?):\/\/\[::1\]:\d+/g, (match, protocol) => {
|
|
196
|
+
return `${protocol}://[::1]`;
|
|
197
|
+
});
|
|
194
198
|
return source;
|
|
195
199
|
// return source.replace(/(?:https?|ftp):\/\/\S+[\w/]/g, (match) => {
|
|
196
200
|
// const lastChar = match[match.length - 1];
|
|
@@ -5,6 +5,7 @@ import { groupLogSideEffects } from "./group_log_side_effects.js";
|
|
|
5
5
|
const logSideEffectsOptionsDefault = {
|
|
6
6
|
prevent: true,
|
|
7
7
|
group: true,
|
|
8
|
+
ignore: false,
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
export const logSideEffects = (logSideEffectsOptions) => {
|
|
@@ -15,7 +16,7 @@ export const logSideEffects = (logSideEffectsOptions) => {
|
|
|
15
16
|
return {
|
|
16
17
|
name: "console",
|
|
17
18
|
install: (addSideEffect, { addFinallyCallback }) => {
|
|
18
|
-
const { prevent, group } = logSideEffectsOptions;
|
|
19
|
+
const { prevent, group, ignore } = logSideEffectsOptions;
|
|
19
20
|
if (group) {
|
|
20
21
|
addFinallyCallback((sideEffects) => {
|
|
21
22
|
groupLogSideEffects(sideEffects, {
|
|
@@ -60,6 +61,9 @@ export const logSideEffects = (logSideEffectsOptions) => {
|
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
const addLogSideEffect = (type, message) => {
|
|
64
|
+
if (ignore) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
63
67
|
addSideEffect({
|
|
64
68
|
code: type,
|
|
65
69
|
type,
|
|
@@ -64,10 +64,6 @@ export const snapshotTests = async (
|
|
|
64
64
|
return outFileUrl;
|
|
65
65
|
};
|
|
66
66
|
const outDirectoryUrl = generateOutFileUrl("");
|
|
67
|
-
const outDirectorySnapshot = takeDirectorySnapshot(
|
|
68
|
-
outDirectoryUrl,
|
|
69
|
-
filesystemActions,
|
|
70
|
-
);
|
|
71
67
|
const sideEffectMdFileUrl = generateOutFileUrl(`${sourceFilename}.md`);
|
|
72
68
|
|
|
73
69
|
const dirUrlMap = new Map();
|
|
@@ -86,9 +82,28 @@ export const snapshotTests = async (
|
|
|
86
82
|
}
|
|
87
83
|
onlyTestMap.set(scenario, { fn, options, callSite: getCallerLocation(2) });
|
|
88
84
|
};
|
|
89
|
-
fnRegisteringTest({ test });
|
|
85
|
+
const fnReturnValue = await fnRegisteringTest({ test });
|
|
90
86
|
|
|
91
|
-
|
|
87
|
+
let activeTestMap;
|
|
88
|
+
const toIgnoreActions = {};
|
|
89
|
+
if (onlyTestMap.size) {
|
|
90
|
+
activeTestMap = onlyTestMap;
|
|
91
|
+
for (const [scenario] of testMap) {
|
|
92
|
+
const testScenario = asValidFilename(scenario);
|
|
93
|
+
const generateScenarioOutFileUrl = (outfilename) => {
|
|
94
|
+
return generateOutFileUrl(`${testScenario}/${outfilename}`);
|
|
95
|
+
};
|
|
96
|
+
const scenarioOutDirectoryUrl = generateScenarioOutFileUrl("");
|
|
97
|
+
toIgnoreActions[scenarioOutDirectoryUrl] = "ignore";
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
activeTestMap = testMap;
|
|
101
|
+
}
|
|
102
|
+
// ignore tout ceux aui sont désactivé
|
|
103
|
+
const outDirectorySnapshot = takeDirectorySnapshot(outDirectoryUrl, {
|
|
104
|
+
...filesystemActions,
|
|
105
|
+
...toIgnoreActions,
|
|
106
|
+
});
|
|
92
107
|
const captureSideEffects = createCaptureSideEffects({
|
|
93
108
|
sourceFileUrl,
|
|
94
109
|
rootDirectoryUrl,
|
|
@@ -115,7 +130,6 @@ export const snapshotTests = async (
|
|
|
115
130
|
markdown += "\n\n";
|
|
116
131
|
markdown += generatedByLink;
|
|
117
132
|
}
|
|
118
|
-
|
|
119
133
|
const scenarioDirs = [];
|
|
120
134
|
for (const [scenario, { fn, callSite }] of activeTestMap) {
|
|
121
135
|
markdown += "\n\n";
|
|
@@ -143,6 +157,9 @@ export const snapshotTests = async (
|
|
|
143
157
|
});
|
|
144
158
|
markdown += sideEffectsMarkdown;
|
|
145
159
|
}
|
|
160
|
+
if (typeof fnReturnValue === "function") {
|
|
161
|
+
await fnReturnValue();
|
|
162
|
+
}
|
|
146
163
|
// if (sideEffectFilePattern === "./side_effects/[filename]/[filename].md") {
|
|
147
164
|
// const scenarioParentDirUrl = new URL("./", sideEffectFileUrl);
|
|
148
165
|
// const dirContent = readDirectorySync(scenarioParentDirUrl);
|