@jsenv/snapshot 2.14.2 → 2.15.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/snapshot",
3
- "version": "2.14.2",
3
+ "version": "2.15.1",
4
4
  "description": "Snapshot testing",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -31,13 +31,13 @@
31
31
  ],
32
32
  "sideEffects": false,
33
33
  "dependencies": {
34
- "@jsenv/assert": "4.4.5",
35
- "@jsenv/ast": "6.6.7",
34
+ "@jsenv/assert": "4.5.0",
35
+ "@jsenv/ast": "6.6.9",
36
36
  "@jsenv/exception": "1.1.7",
37
- "@jsenv/humanize": "1.4.0",
38
- "@jsenv/filesystem": "4.14.6",
39
- "@jsenv/terminal-recorder": "1.5.11",
40
- "@jsenv/urls": "2.7.1",
37
+ "@jsenv/humanize": "1.5.0",
38
+ "@jsenv/filesystem": "4.15.0",
39
+ "@jsenv/terminal-recorder": "1.5.14",
40
+ "@jsenv/urls": "2.7.2",
41
41
  "@jsenv/utils": "2.3.0",
42
42
  "ansi-regex": "6.1.0",
43
43
  "pixelmatch": "7.1.0",
@@ -9,6 +9,8 @@ const executionEffectsDefault = {
9
9
  return: true,
10
10
  };
11
11
 
12
+ let currentCapture = false;
13
+
12
14
  export const createCaptureSideEffects = ({
13
15
  sourceFileUrl,
14
16
  logEffects = true,
@@ -50,6 +52,7 @@ export const createCaptureSideEffects = ({
50
52
  replaceFilesystemWellKnownValues,
51
53
  };
52
54
  let functionExecutingCount = 0;
55
+ let ignored = false;
53
56
  const capture = (fn, { callSite, baseDirectory } = {}) => {
54
57
  const unicodeSupported = UNICODE.supported;
55
58
  const ansiSupported = ANSI.supported;
@@ -74,6 +77,7 @@ export const createCaptureSideEffects = ({
74
77
  };
75
78
  const onSideEffectRemoved = () => {};
76
79
  const addSideEffect = (sideEffect) => {
80
+ if (ignored) return null;
77
81
  sideEffects.push(sideEffect);
78
82
  onSideEffectAdded(sideEffect);
79
83
  return sideEffect;
@@ -286,6 +290,7 @@ export const createCaptureSideEffects = ({
286
290
  });
287
291
  };
288
292
  const onFinally = () => {
293
+ currentCapture = null;
289
294
  delete process.env.CAPTURING_SIDE_EFFECTS;
290
295
  UNICODE.supported = unicodeSupported;
291
296
  ANSI.supported = ansiSupported;
@@ -326,6 +331,13 @@ export const createCaptureSideEffects = ({
326
331
  process.env.CAPTURING_SIDE_EFFECTS = "1";
327
332
  functionExecutingCount++;
328
333
  let returnedPromise = false;
334
+ currentCapture = {
335
+ ignoreWhile: (fn) => {
336
+ ignored = true;
337
+ fn();
338
+ ignored = false;
339
+ },
340
+ };
329
341
  try {
330
342
  const valueReturned = fn();
331
343
  if (valueReturned && typeof valueReturned.then === "function") {
@@ -355,7 +367,17 @@ export const createCaptureSideEffects = ({
355
367
  }
356
368
  }
357
369
  };
370
+ capture.ignoreSideEffects = ignoreSideEffects;
371
+
358
372
  return capture;
359
373
  };
360
374
 
375
+ export const ignoreSideEffects = (fn) => {
376
+ if (!currentCapture) {
377
+ console.warn(`ignoreSideEffects called outside of captureSideEffects`);
378
+ return;
379
+ }
380
+ currentCapture.ignoreWhile(fn);
381
+ };
382
+
361
383
  const RETURN_PROMISE = {};
@@ -2,7 +2,10 @@ import { writeFileSync } from "@jsenv/filesystem";
2
2
  import { urlToBasename, urlToFilename, urlToRelativeUrl } from "@jsenv/urls";
3
3
  import { takeDirectorySnapshot } from "../filesystem_snapshot.js";
4
4
  import { getCallerLocation } from "../get_caller_location.js";
5
- import { createCaptureSideEffects } from "./create_capture_side_effects.js";
5
+ import {
6
+ createCaptureSideEffects,
7
+ ignoreSideEffects,
8
+ } from "./create_capture_side_effects.js";
6
9
  import { renderSideEffects, renderSmallLink } from "./render_side_effects.js";
7
10
 
8
11
  /**
@@ -235,11 +238,12 @@ export const snapshotTests = async (
235
238
  // snapshotTests.prefConfigure(options)
236
239
  // snapshotTests(import.meta.url, ({ test }) => { })
237
240
  // which are equivalent
238
-
239
241
  snapshotTests.prefConfigure = (options) => {
240
242
  preconfiguredOptions = options;
241
243
  };
242
244
 
245
+ snapshotTests.ignoreSideEffects = ignoreSideEffects;
246
+
243
247
  // see https://github.com/parshap/node-sanitize-filename/blob/master/index.js
244
248
  const asValidFilename = (string) => {
245
249
  return string