@jsenv/snapshot 2.6.7 → 2.6.9
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
|
@@ -170,27 +170,35 @@ export const takeDirectorySnapshot = (
|
|
|
170
170
|
directoryUrl = new URL(directoryUrl);
|
|
171
171
|
const associations = URL_META.resolveAssociations(
|
|
172
172
|
{
|
|
173
|
-
|
|
173
|
+
action: pattern,
|
|
174
174
|
},
|
|
175
175
|
directoryUrl,
|
|
176
176
|
);
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
URL_META.urlChildMayMatch({
|
|
177
|
+
const shouldVisitDirectory = (url) => {
|
|
178
|
+
return URL_META.urlChildMayMatch({
|
|
180
179
|
url,
|
|
181
180
|
associations,
|
|
182
|
-
predicate,
|
|
181
|
+
predicate: (meta) => Boolean(meta.action),
|
|
183
182
|
});
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
183
|
+
};
|
|
184
|
+
const shouldIncludeFile = (url) => {
|
|
185
|
+
const meta = URL_META.applyAssociations({
|
|
186
|
+
url,
|
|
187
|
+
associations,
|
|
188
|
+
});
|
|
189
|
+
return meta.action === true || meta.action === "presence_only";
|
|
190
|
+
};
|
|
191
|
+
const shouldCompareFile = (url) => {
|
|
192
|
+
const meta = URL_META.applyAssociations({
|
|
193
|
+
url,
|
|
194
|
+
associations,
|
|
195
|
+
});
|
|
196
|
+
return meta.action === true || meta.action === "compare";
|
|
197
|
+
};
|
|
191
198
|
const directorySnapshot = createDirectorySnapshot(directoryUrl, {
|
|
192
199
|
shouldVisitDirectory,
|
|
193
200
|
shouldIncludeFile,
|
|
201
|
+
shouldCompareFile,
|
|
194
202
|
clean: true,
|
|
195
203
|
});
|
|
196
204
|
return {
|
|
@@ -199,6 +207,7 @@ export const takeDirectorySnapshot = (
|
|
|
199
207
|
const nextDirectorySnapshot = createDirectorySnapshot(directoryUrl, {
|
|
200
208
|
shouldVisitDirectory,
|
|
201
209
|
shouldIncludeFile,
|
|
210
|
+
shouldCompareFile,
|
|
202
211
|
});
|
|
203
212
|
directorySnapshot.compare(nextDirectorySnapshot, { throwWhenDiff });
|
|
204
213
|
},
|
|
@@ -226,7 +235,7 @@ export const takeDirectorySnapshot = (
|
|
|
226
235
|
};
|
|
227
236
|
const createDirectorySnapshot = (
|
|
228
237
|
directoryUrl,
|
|
229
|
-
{ shouldVisitDirectory, shouldIncludeFile, clean },
|
|
238
|
+
{ shouldVisitDirectory, shouldIncludeFile, shouldCompareFile, clean },
|
|
230
239
|
) => {
|
|
231
240
|
const directorySnapshot = {
|
|
232
241
|
type: "directory",
|
|
@@ -311,6 +320,9 @@ ${extraUrls.join("\n")}`);
|
|
|
311
320
|
// content
|
|
312
321
|
{
|
|
313
322
|
for (const relativeUrl of relativeUrls) {
|
|
323
|
+
if (!shouldCompareFile(new URL(relativeUrl, directoryUrl))) {
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
314
326
|
const snapshot = directoryContentSnapshot[relativeUrl];
|
|
315
327
|
const nextSnapshot = nextDirectoryContentSnapshot[relativeUrl];
|
|
316
328
|
if (nextSnapshot) {
|
|
@@ -370,6 +382,7 @@ ${extraUrls.join("\n")}`);
|
|
|
370
382
|
{
|
|
371
383
|
shouldVisitDirectory,
|
|
372
384
|
shouldIncludeFile,
|
|
385
|
+
shouldCompareFile,
|
|
373
386
|
clean,
|
|
374
387
|
},
|
|
375
388
|
);
|
|
@@ -9,6 +9,9 @@ export const getCallerLocation = (callIndex = 1) => {
|
|
|
9
9
|
const { stack } = new Error();
|
|
10
10
|
Error.prepareStackTrace = prepareStackTrace;
|
|
11
11
|
const callerCallsite = stack[callIndex];
|
|
12
|
+
if (!callerCallsite) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
12
15
|
const fileName = callerCallsite.getFileName();
|
|
13
16
|
const testCallSite = {
|
|
14
17
|
url:
|
|
@@ -97,6 +97,27 @@ export const filesystemSideEffects = (
|
|
|
97
97
|
}
|
|
98
98
|
return null;
|
|
99
99
|
});
|
|
100
|
+
addSkippableHandler((sideEffect) => {
|
|
101
|
+
// on llinux writing to a file with the same content
|
|
102
|
+
// is ignored somehow
|
|
103
|
+
// let's make this consistent on other platforms
|
|
104
|
+
if (sideEffect.code === "write_file") {
|
|
105
|
+
return (nextSideEffect, { skip, stop }) => {
|
|
106
|
+
if (
|
|
107
|
+
nextSideEffect.code === "write_file" &&
|
|
108
|
+
nextSideEffect.value.url === sideEffect.value.url &&
|
|
109
|
+
!Buffer.compare(
|
|
110
|
+
nextSideEffect.value.buffer,
|
|
111
|
+
sideEffect.value.buffer,
|
|
112
|
+
)
|
|
113
|
+
) {
|
|
114
|
+
skip();
|
|
115
|
+
}
|
|
116
|
+
stop();
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
});
|
|
100
121
|
|
|
101
122
|
addFinallyCallback((sideEffects) => {
|
|
102
123
|
// gather all file side effect next to each other
|
|
@@ -78,7 +78,12 @@ export const snapshotTests = async (
|
|
|
78
78
|
`./${asValidFilename(scenario)}/`,
|
|
79
79
|
snapshotFileUrl,
|
|
80
80
|
);
|
|
81
|
-
const outDirectorySnapshot = takeDirectorySnapshot(outDirectoryUrl
|
|
81
|
+
const outDirectorySnapshot = takeDirectorySnapshot(outDirectoryUrl, {
|
|
82
|
+
pattern: {
|
|
83
|
+
"**/*": true,
|
|
84
|
+
"**/*.svg": "presence_only",
|
|
85
|
+
},
|
|
86
|
+
});
|
|
82
87
|
const sideEffectsMarkdown = renderSideEffects(sideEffects, {
|
|
83
88
|
sideEffectFileUrl: snapshotFileUrl,
|
|
84
89
|
outDirectoryUrl,
|