@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forwardimpact/libmock",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Shared mocks and test fixtures so every library and service tests the same way.",
5
5
  "keywords": [
6
6
  "test",
@@ -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 stub for a spawned child's writable stdin. Records every
13
- * `write(chunk)` on `chunks`; `end()`/`destroy()` are no-ops. Mirrors the
14
- * shape `createDefaultSubprocess().spawn` exposes (the child's `node:stream`
15
- * Writable) closely enough for a supervisor that pipes into it.
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 sink = {
19
- chunks: [],
20
- write(chunk) {
21
- sink.chunks.push(typeof chunk === "string" ? chunk : chunk.toString());
22
- return true;
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