@jsenv/snapshot 2.6.8 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/snapshot",
3
- "version": "2.6.8",
3
+ "version": "2.6.9",
4
4
  "description": "Snapshot testing",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -170,27 +170,35 @@ export const takeDirectorySnapshot = (
170
170
  directoryUrl = new URL(directoryUrl);
171
171
  const associations = URL_META.resolveAssociations(
172
172
  {
173
- included: pattern,
173
+ action: pattern,
174
174
  },
175
175
  directoryUrl,
176
176
  );
177
- const predicate = ({ included }) => included;
178
- const shouldVisitDirectory = (url) =>
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
- const shouldIncludeFile = (url) =>
185
- predicate(
186
- URL_META.applyAssociations({
187
- url,
188
- associations,
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:
@@ -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,