@jsenv/snapshot 2.2.6 → 2.2.7
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 +1 -1
- package/src/function_snapshot.js +14 -6
package/package.json
CHANGED
package/src/function_snapshot.js
CHANGED
|
@@ -8,6 +8,8 @@ import { urlToFilename, urlToRelativeUrl } from "@jsenv/urls";
|
|
|
8
8
|
import { takeDirectorySnapshot } from "./filesystem_snapshot.js";
|
|
9
9
|
import { replaceFluctuatingValues } from "./replace_fluctuating_values.js";
|
|
10
10
|
|
|
11
|
+
const consoleSpySymbol = Symbol.for("console_spy_for_jsenv_snapshot");
|
|
12
|
+
|
|
11
13
|
export const snapshotFunctionSideEffects = (
|
|
12
14
|
fn,
|
|
13
15
|
fnFileUrl,
|
|
@@ -59,12 +61,17 @@ export const snapshotFunctionSideEffects = (
|
|
|
59
61
|
if (captureConsole) {
|
|
60
62
|
const installConsoleSpy = (methodName) => {
|
|
61
63
|
const methodSpied = console[methodName];
|
|
62
|
-
|
|
64
|
+
if (consoleSpySymbol in methodSpied) {
|
|
65
|
+
throw new Error("snapshotFunctionSideEffects already running");
|
|
66
|
+
}
|
|
67
|
+
const methodSpy = (message) => {
|
|
63
68
|
sideEffects.push({
|
|
64
69
|
type: `console.${methodName}`,
|
|
65
70
|
value: message,
|
|
66
71
|
});
|
|
67
72
|
};
|
|
73
|
+
methodSpy[consoleSpySymbol] = true;
|
|
74
|
+
console[methodName] = methodSpy;
|
|
68
75
|
finallyCallbackSet.add(() => {
|
|
69
76
|
console[methodName] = methodSpied;
|
|
70
77
|
});
|
|
@@ -139,8 +146,7 @@ export const snapshotFunctionSideEffects = (
|
|
|
139
146
|
try {
|
|
140
147
|
const returnValue = fn();
|
|
141
148
|
if (returnValue && returnValue.then) {
|
|
142
|
-
returnedPromise =
|
|
143
|
-
returnValue.then(
|
|
149
|
+
returnedPromise = returnValue.then(
|
|
144
150
|
(value) => {
|
|
145
151
|
onResult(value);
|
|
146
152
|
onFinally();
|
|
@@ -150,14 +156,16 @@ export const snapshotFunctionSideEffects = (
|
|
|
150
156
|
onFinally();
|
|
151
157
|
},
|
|
152
158
|
);
|
|
153
|
-
|
|
154
|
-
onResult(returnValue);
|
|
159
|
+
return returnedPromise;
|
|
155
160
|
}
|
|
161
|
+
onResult(returnValue);
|
|
162
|
+
return null;
|
|
156
163
|
} catch (e) {
|
|
157
164
|
onError(e);
|
|
165
|
+
return null;
|
|
158
166
|
} finally {
|
|
159
167
|
if (returnedPromise) {
|
|
160
|
-
return;
|
|
168
|
+
return returnedPromise;
|
|
161
169
|
}
|
|
162
170
|
onFinally();
|
|
163
171
|
}
|