@forwardimpact/libmock 0.1.3 → 0.1.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/mock/subprocess.js +14 -18
package/package.json
CHANGED
package/src/mock/subprocess.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Writable } from "node:stream";
|
|
2
|
+
|
|
1
3
|
import { spy } from "./spy.js";
|
|
2
4
|
|
|
3
5
|
function asyncIterableOf(str) {
|
|
@@ -9,27 +11,21 @@ function asyncIterableOf(str) {
|
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
* A captured-chunks
|
|
13
|
-
* `
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* A captured-chunks sink for a spawned child's writable stdin. A real
|
|
15
|
+
* `node:stream` Writable (so it is a valid `pipe()` destination, the way a
|
|
16
|
+
* supervisor pipes a service's output into its logger) that records every
|
|
17
|
+
* written chunk on `chunks` instead of forwarding it anywhere. Mirrors the
|
|
18
|
+
* `stdin` the production `createDefaultSubprocess().spawn` exposes.
|
|
16
19
|
*/
|
|
17
20
|
function createMockStdinSink() {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
write(chunk) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
end() {},
|
|
25
|
-
destroy() {},
|
|
26
|
-
on() {
|
|
27
|
-
return sink;
|
|
28
|
-
},
|
|
29
|
-
once() {
|
|
30
|
-
return sink;
|
|
21
|
+
const chunks = [];
|
|
22
|
+
const sink = new Writable({
|
|
23
|
+
write(chunk, _encoding, callback) {
|
|
24
|
+
chunks.push(typeof chunk === "string" ? chunk : chunk.toString());
|
|
25
|
+
callback();
|
|
31
26
|
},
|
|
32
|
-
};
|
|
27
|
+
});
|
|
28
|
+
sink.chunks = chunks;
|
|
33
29
|
return sink;
|
|
34
30
|
}
|
|
35
31
|
|