@jsenv/snapshot 2.3.1 → 2.3.2
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,5 +1,6 @@
|
|
|
1
1
|
import { createException } from "@jsenv/exception";
|
|
2
2
|
import { replaceFluctuatingValues } from "../replace_fluctuating_values.js";
|
|
3
|
+
import { wrapIntoMarkdownBlock } from "./function_side_effects_renderer.js";
|
|
3
4
|
|
|
4
5
|
const RETURN_PROMISE = {};
|
|
5
6
|
|
|
@@ -22,6 +23,15 @@ export const collectFunctionSideEffects = (
|
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
25
|
if (functionExecutingCount) {
|
|
26
|
+
// The reason for this warning:
|
|
27
|
+
// 1. fs side effect detectors is not yet fully compatible with that because
|
|
28
|
+
// callback.oncomplete redefinition might be wrong for open, mkdir etc
|
|
29
|
+
// (at least this is to be tested)
|
|
30
|
+
// 2. It's usually a sign code forgets to put await in front of
|
|
31
|
+
// collectFunctionSideEffects or snapshotFunctionSideEffects
|
|
32
|
+
// 3. collectFunctionSideEffects is meant to collect a function side effect
|
|
33
|
+
// during unit test. So in unit test the function being tested should be analyized
|
|
34
|
+
// and should not in turn analyze an other one
|
|
25
35
|
console.warn(
|
|
26
36
|
`collectFunctionSideEffects called while other function(s) side effects are collected`,
|
|
27
37
|
);
|
|
@@ -33,9 +43,11 @@ export const collectFunctionSideEffects = (
|
|
|
33
43
|
type: "throw",
|
|
34
44
|
value: valueThrow,
|
|
35
45
|
label: "throw",
|
|
36
|
-
text:
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
text: wrapIntoMarkdownBlock(
|
|
47
|
+
renderValueThrownOrRejected(
|
|
48
|
+
createException(valueThrow, { rootDirectoryUrl }),
|
|
49
|
+
{ rootDirectoryUrl },
|
|
50
|
+
),
|
|
39
51
|
),
|
|
40
52
|
});
|
|
41
53
|
};
|
|
@@ -52,9 +64,12 @@ export const collectFunctionSideEffects = (
|
|
|
52
64
|
type: "return",
|
|
53
65
|
value: valueReturned,
|
|
54
66
|
label: "return",
|
|
55
|
-
text:
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
text: wrapIntoMarkdownBlock(
|
|
68
|
+
renderReturnValueOrResolveValue(valueReturned, {
|
|
69
|
+
rootDirectoryUrl,
|
|
70
|
+
}),
|
|
71
|
+
"js",
|
|
72
|
+
),
|
|
58
73
|
});
|
|
59
74
|
}
|
|
60
75
|
};
|
|
@@ -63,7 +78,10 @@ export const collectFunctionSideEffects = (
|
|
|
63
78
|
type: "resolve",
|
|
64
79
|
value,
|
|
65
80
|
label: "resolve",
|
|
66
|
-
text:
|
|
81
|
+
text: wrapIntoMarkdownBlock(
|
|
82
|
+
renderReturnValueOrResolveValue(value, { rootDirectoryUrl }),
|
|
83
|
+
"js",
|
|
84
|
+
),
|
|
67
85
|
});
|
|
68
86
|
};
|
|
69
87
|
const onReject = (reason) => {
|
|
@@ -71,9 +89,11 @@ export const collectFunctionSideEffects = (
|
|
|
71
89
|
type: "reject",
|
|
72
90
|
value: reason,
|
|
73
91
|
label: "reject",
|
|
74
|
-
text:
|
|
75
|
-
|
|
76
|
-
|
|
92
|
+
text: wrapIntoMarkdownBlock(
|
|
93
|
+
renderValueThrownOrRejected(
|
|
94
|
+
createException(reason, { rootDirectoryUrl }),
|
|
95
|
+
{ rootDirectoryUrl },
|
|
96
|
+
),
|
|
77
97
|
),
|
|
78
98
|
});
|
|
79
99
|
};
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { writeFileSync } from "@jsenv/filesystem";
|
|
2
2
|
import {
|
|
3
3
|
ensurePathnameTrailingSlash,
|
|
4
|
+
urlToExtension,
|
|
4
5
|
urlToFilename,
|
|
5
6
|
urlToRelativeUrl,
|
|
6
7
|
} from "@jsenv/urls";
|
|
7
8
|
import { takeDirectorySnapshot } from "../filesystem_snapshot.js";
|
|
8
9
|
import { replaceFluctuatingValues } from "../replace_fluctuating_values.js";
|
|
9
10
|
import { collectFunctionSideEffects } from "./function_side_effects_collector.js";
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
renderSideEffects,
|
|
13
|
+
wrapIntoMarkdownBlock,
|
|
14
|
+
} from "./function_side_effects_renderer.js";
|
|
11
15
|
import { spyConsoleCalls } from "./spy_console_calls.js";
|
|
12
16
|
import { spyFilesystemCalls } from "./spy_filesystem_calls.js";
|
|
13
17
|
|
|
@@ -32,7 +36,7 @@ export const snapshotFunctionSideEffects = (
|
|
|
32
36
|
const sideEffectDirectorySnapshot = takeDirectorySnapshot(
|
|
33
37
|
sideEffectDirectoryUrl,
|
|
34
38
|
);
|
|
35
|
-
const sideEffectFilename = `${urlToFilename(sideEffectDirectoryUrl)}_side_effects.
|
|
39
|
+
const sideEffectFilename = `${urlToFilename(sideEffectDirectoryUrl)}_side_effects.md`;
|
|
36
40
|
const sideEffectFileUrl = new URL(sideEffectFilename, sideEffectDirectoryUrl);
|
|
37
41
|
const callbackSet = new Set();
|
|
38
42
|
const sideEffectDetectors = [
|
|
@@ -44,10 +48,13 @@ export const snapshotFunctionSideEffects = (
|
|
|
44
48
|
type: `console:${methodName}`,
|
|
45
49
|
value: message,
|
|
46
50
|
label: `console.${methodName}`,
|
|
47
|
-
text:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
text: wrapIntoMarkdownBlock(
|
|
52
|
+
replaceFluctuatingValues(message, {
|
|
53
|
+
stringType: "console",
|
|
54
|
+
rootDirectoryUrl,
|
|
55
|
+
}),
|
|
56
|
+
"console",
|
|
57
|
+
),
|
|
51
58
|
});
|
|
52
59
|
};
|
|
53
60
|
const consoleSpy = spyConsoleCalls(
|
|
@@ -104,9 +111,10 @@ export const snapshotFunctionSideEffects = (
|
|
|
104
111
|
type: "fs:write_file",
|
|
105
112
|
value: { relativeUrl, content },
|
|
106
113
|
label: `write file "${relativeUrl}"`,
|
|
107
|
-
text:
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
text: wrapIntoMarkdownBlock(
|
|
115
|
+
content,
|
|
116
|
+
urlToExtension(url).slice(1),
|
|
117
|
+
),
|
|
110
118
|
});
|
|
111
119
|
}
|
|
112
120
|
},
|