@jsenv/snapshot 2.3.0 → 2.3.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.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "Snapshot testing",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -3,15 +3,13 @@ import { replaceFluctuatingValues } from "../replace_fluctuating_values.js";
3
3
 
4
4
  const RETURN_PROMISE = {};
5
5
 
6
- let executing = false;
6
+ let functionExecutingCount = 0;
7
+
7
8
  export const collectFunctionSideEffects = (
8
9
  fn,
9
10
  sideEffectDetectors,
10
11
  { rootDirectoryUrl },
11
12
  ) => {
12
- if (executing) {
13
- throw new Error("collectFunctionSideEffects already running");
14
- }
15
13
  const sideEffects = [];
16
14
  const addSideEffect = (sideEffect) => {
17
15
  sideEffects.push(sideEffect);
@@ -23,6 +21,13 @@ export const collectFunctionSideEffects = (
23
21
  uninstall();
24
22
  });
25
23
  }
24
+ if (functionExecutingCount) {
25
+ console.warn(
26
+ `collectFunctionSideEffects called while other function(s) side effects are collected`,
27
+ );
28
+ }
29
+ functionExecutingCount++;
30
+
26
31
  const onCatch = (valueThrow) => {
27
32
  sideEffects.push({
28
33
  type: "throw",
@@ -73,7 +78,7 @@ export const collectFunctionSideEffects = (
73
78
  });
74
79
  };
75
80
  const onFinally = () => {
76
- executing = false;
81
+ functionExecutingCount--;
77
82
  for (const finallyCallback of finallyCallbackSet) {
78
83
  finallyCallback();
79
84
  }
@@ -11,8 +11,6 @@ import { renderSideEffects } from "./function_side_effects_renderer.js";
11
11
  import { spyConsoleCalls } from "./spy_console_calls.js";
12
12
  import { spyFilesystemCalls } from "./spy_filesystem_calls.js";
13
13
 
14
- let filesystemSideEffectInstalled;
15
-
16
14
  export const snapshotFunctionSideEffects = (
17
15
  fn,
18
16
  fnFileUrl,
@@ -79,12 +77,6 @@ export const snapshotFunctionSideEffects = (
79
77
  {
80
78
  name: "filesystem",
81
79
  install: (addSideEffect) => {
82
- if (filesystemSideEffectInstalled) {
83
- throw new Error(
84
- "cannot collect filesystem side effects concurrently (already collecting side effect for an other function)",
85
- );
86
- }
87
- filesystemSideEffectInstalled = true;
88
80
  const fsSideEffectDirectoryUrl = ensurePathnameTrailingSlash(
89
81
  new URL(filesystemEffectsDirectory, sideEffectDirectoryUrl),
90
82
  );
@@ -112,7 +104,9 @@ export const snapshotFunctionSideEffects = (
112
104
  type: "fs:write_file",
113
105
  value: { relativeUrl, content },
114
106
  label: `write file "${relativeUrl}"`,
115
- text: content,
107
+ text: `--- content ---
108
+ ${content}
109
+ ---------------`,
116
110
  });
117
111
  }
118
112
  },
@@ -132,7 +126,6 @@ export const snapshotFunctionSideEffects = (
132
126
  );
133
127
  return () => {
134
128
  filesystemSpy.restore();
135
- filesystemSideEffectInstalled = false;
136
129
  };
137
130
  },
138
131
  },