@promistream/from-node-stream 0.1.7 → 0.1.8

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.
Files changed (3) hide show
  1. package/package.json +10 -6
  2. package/src/index.js +6 -2
  3. package/test.js +47 -1
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@promistream/from-node-stream",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "main": "src/index.js",
5
- "repository": "https://codeberg.org/promistream/from-node-stream.git",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://codeberg.org/promistream/from-node-stream.git"
8
+ },
6
9
  "author": "Sven Slootweg <admin@cryto.net>",
7
10
  "license": "WTFPL OR CC0-1.0",
8
11
  "dependencies": {
@@ -15,7 +18,7 @@
15
18
  "@promistream/propagate-abort": "^0.1.7",
16
19
  "@promistream/propagate-peek": "^0.1.2",
17
20
  "@promistream/simple-sink": "^0.3.5",
18
- "@promistream/simple-source": "^0.1.10",
21
+ "@promistream/simple-source": "^0.1.11",
19
22
  "debug-instanced": "^1.0.0",
20
23
  "push-buffer": "^1.5.7",
21
24
  "single-concurrent": "^1.0.0",
@@ -23,15 +26,16 @@
23
26
  },
24
27
  "devDependencies": {
25
28
  "@promistream/buffered-map": "^0.1.1",
26
- "@promistream/collect": "^0.1.2",
29
+ "@promistream/collect": "^0.1.4",
27
30
  "@promistream/debug": "^0.1.2",
28
31
  "@promistream/from-iterable": "^0.1.1",
29
32
  "@promistream/map": "^0.1.10",
30
- "@promistream/parallelize": "^0.1.8",
33
+ "@promistream/parallelize": "^0.1.10",
31
34
  "@promistream/pipe": "^0.1.8",
32
35
  "@promistream/range-numbers": "^0.1.2",
36
+ "@promistream/test-abort": "^0.1.0",
33
37
  "bluebird": "^3.7.2",
34
38
  "p-defer": "^4.0.1",
35
39
  "through2": "^4.0.2"
36
40
  }
37
- }
41
+ }
package/src/index.js CHANGED
@@ -105,8 +105,12 @@ function convertFromReadable(stream) {
105
105
  onRequest: () => {
106
106
  return read();
107
107
  },
108
- onAbort: () => {
109
- return abort();
108
+ onAbort: (reason) => {
109
+ if (reason === true) {
110
+ return abort();
111
+ } else {
112
+ return abort(reason);
113
+ }
110
114
  }
111
115
  });
112
116
  }
package/test.js CHANGED
@@ -13,7 +13,9 @@ const fromIterable = require("@promistream/from-iterable");
13
13
  const fromNodeStream = require(".");
14
14
  const collect = require("@promistream/collect");
15
15
  const parallelize = require("@promistream/parallelize");
16
+ const testAbort = require("@promistream/test-abort");
16
17
  const debug = require("@promistream/debug");
18
+ const { once } = require("node:events");
17
19
 
18
20
  test("readable stream", async () => {
19
21
  let testFile = path.join(__dirname, "pnpm-lock.yaml"); // Big-ish file, so we're likely to read in multiple chunks
@@ -24,9 +26,41 @@ test("readable stream", async () => {
24
26
  collect()
25
27
  ]).read();
26
28
 
27
- assert.deepStrictEqual(result, [ expected ]);
29
+ assert.deepStrictEqual(result, [ expected ]);
28
30
  });
29
31
 
32
+ test("readable stream with error abort", { timeout: 500 }, async () => {
33
+ let testFile = path.join(__dirname, "pnpm-lock.yaml");
34
+ let nodeStream = fs.createReadStream(testFile);
35
+
36
+ let errorFromNodeStreamPromise = once(nodeStream, "error");
37
+
38
+ assert.rejects(async () => {
39
+ let result = await pipe([
40
+ fromNodeStream.fromReadable(nodeStream),
41
+ testAbort(0, new Error("sample error")),
42
+ collect()
43
+ ]).read();
44
+ }, { message: "sample error" });
45
+
46
+ let [ errorFromNodeStream ] = await errorFromNodeStreamPromise;
47
+ assert.strictEqual(errorFromNodeStream.message, "sample error");
48
+ });
49
+
50
+
51
+ test("readable stream with happy abort", { timeout: 500 }, async () => {
52
+ let testFile = path.join(__dirname, "pnpm-lock.yaml");
53
+
54
+ let result = await pipe([
55
+ fromNodeStream.fromReadable(fs.createReadStream(testFile)),
56
+ testAbort(0, true),
57
+ collect()
58
+ ]).read();
59
+
60
+ assert.deepStrictEqual(result, []);
61
+ });
62
+
63
+
30
64
  test("writable stream", async () => {
31
65
  let buffer = Buffer.alloc(400000);
32
66
 
@@ -116,6 +150,18 @@ test("transform stream, parallel", async () => {
116
150
  });
117
151
 
118
152
  /* FIXME: Do network socket test with both happy abort and error abort */
153
+ /* TODO: Flaky test behaviour was observed for the below test:
154
+
155
+ ✖ network socket (9.891608ms)
156
+ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
157
+ + actual - expected
158
+
159
+ + Buffer(0) [Uint8Array] []
160
+ - Buffer(2) [Uint8Array] [
161
+ - 99,
162
+ - 100
163
+ - ]
164
+ */
119
165
  test("network socket", async () => {
120
166
  let { resolve, promise } = pDefer();
121
167