@jsenv/snapshot 2.2.3 → 2.2.4
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 +26 -6
package/package.json
CHANGED
package/src/function_snapshot.js
CHANGED
|
@@ -16,6 +16,7 @@ export const snapshotFunctionSideEffects = (
|
|
|
16
16
|
rootDirectoryUrl = new URL("./", fnFileUrl),
|
|
17
17
|
captureConsole = true,
|
|
18
18
|
filesystemEffects,
|
|
19
|
+
filesystemEffectsInline,
|
|
19
20
|
restoreFilesystem,
|
|
20
21
|
} = {},
|
|
21
22
|
) => {
|
|
@@ -50,7 +51,10 @@ export const snapshotFunctionSideEffects = (
|
|
|
50
51
|
}
|
|
51
52
|
writeFileSync(
|
|
52
53
|
sideEffectFileUrl,
|
|
53
|
-
stringifySideEffects(sideEffects, {
|
|
54
|
+
stringifySideEffects(sideEffects, {
|
|
55
|
+
rootDirectoryUrl,
|
|
56
|
+
filesystemEffectsInline,
|
|
57
|
+
}),
|
|
54
58
|
);
|
|
55
59
|
sideEffectDirectorySnapshot.compare();
|
|
56
60
|
};
|
|
@@ -89,6 +93,7 @@ export const snapshotFunctionSideEffects = (
|
|
|
89
93
|
if (atStartState.found && !nowState.found) {
|
|
90
94
|
onFileSystemSideEffect({
|
|
91
95
|
type: `remove file "${relativeUrl}"`,
|
|
96
|
+
value: atStartState.content,
|
|
92
97
|
});
|
|
93
98
|
if (restoreFilesystem) {
|
|
94
99
|
writeFileSync(from, atStartState.content);
|
|
@@ -104,10 +109,18 @@ export const snapshotFunctionSideEffects = (
|
|
|
104
109
|
atStartState.content !== nowState.content ||
|
|
105
110
|
atStartState.mtimeMs !== nowState.mtimeMs
|
|
106
111
|
) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
if (filesystemEffectsInline) {
|
|
113
|
+
onFileSystemSideEffect({
|
|
114
|
+
type: `write file "${relativeUrl}"`,
|
|
115
|
+
value: nowState.content,
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
writeFileSync(toUrl, nowState.content);
|
|
119
|
+
onFileSystemSideEffect({
|
|
120
|
+
type: `write file "${relativeUrl}" (see ./fs/${relativeUrl})`,
|
|
121
|
+
value: nowState.content,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
111
124
|
if (restoreFilesystem) {
|
|
112
125
|
if (atStartState.found) {
|
|
113
126
|
if (atStartState.content !== nowState.content) {
|
|
@@ -152,7 +165,10 @@ export const snapshotFunctionSideEffects = (
|
|
|
152
165
|
}
|
|
153
166
|
};
|
|
154
167
|
|
|
155
|
-
const stringifySideEffects = (
|
|
168
|
+
const stringifySideEffects = (
|
|
169
|
+
sideEffects,
|
|
170
|
+
{ rootDirectoryUrl, filesystemEffectsInline },
|
|
171
|
+
) => {
|
|
156
172
|
let string = "";
|
|
157
173
|
let index = 0;
|
|
158
174
|
for (const sideEffect of sideEffects) {
|
|
@@ -172,6 +188,10 @@ const stringifySideEffects = (sideEffects, { rootDirectoryUrl }) => {
|
|
|
172
188
|
sideEffect.type.startsWith("remove file") ||
|
|
173
189
|
sideEffect.type.startsWith("write file")
|
|
174
190
|
) {
|
|
191
|
+
if (filesystemEffectsInline) {
|
|
192
|
+
string += "\n";
|
|
193
|
+
string += value;
|
|
194
|
+
}
|
|
175
195
|
} else if (sideEffect.type === "throw") {
|
|
176
196
|
value = replaceFluctuatingValues(value.stack, {
|
|
177
197
|
stringType: "error",
|