Skip to content

Commit

Permalink
Replace the test utility function streamToString with text from `…
Browse files Browse the repository at this point in the history
…node:stream/consumers`.
  • Loading branch information
jaydenseric committed Aug 27, 2023
1 parent 5c2270a commit f24d71b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 34 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Updated Node.js support to `^18.15.0 || >=20.4.0`.
- Updated dev dependencies, some of which require newer Node.js versions than previously supported.
- Refactored tests to use the standard `AbortController`, `fetch`, `File`, and `FormData` APIs available in modern Node.js and removed the dev dependencies [`node-abort-controller`](https://npm.im/node-abort-controller) and [`node-fetch`](https://npm.im/node-fetch).
- Replaced the test utility function `streamToString` with the function `text` from `node:stream/consumers` that’s available in modern Node.js.

### Patch

Expand Down
29 changes: 13 additions & 16 deletions processRequest.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {
throws,
} from "node:assert";
import { createServer } from "node:http";
import { text } from "node:stream/consumers";

import { ReadStream } from "fs-capacitor";

import processRequest from "./processRequest.mjs";
import abortingMultipartRequest from "./test/abortingMultipartRequest.mjs";
import Deferred from "./test/Deferred.mjs";
import listen from "./test/listen.mjs";
import streamToString from "./test/streamToString.mjs";
import Upload from "./Upload.mjs";

/**
Expand Down Expand Up @@ -86,7 +86,7 @@ export default (tests) => {
ok(stream instanceof ReadStream);
strictEqual(stream.readableEncoding, null);
strictEqual(stream.readableHighWaterMark, 16384);
strictEqual(await streamToString(stream), "a");
strictEqual(await text(stream), "a");
} catch (error) {
serverError = error;
} finally {
Expand Down Expand Up @@ -147,7 +147,7 @@ export default (tests) => {
ok(stream instanceof ReadStream);
strictEqual(stream.readableEncoding, null);
strictEqual(stream.readableHighWaterMark, 16384);
strictEqual(await streamToString(stream), "a");
strictEqual(await text(stream), "a");
} catch (error) {
serverError = error;
} finally {
Expand Down Expand Up @@ -208,10 +208,7 @@ export default (tests) => {
ok(stream instanceof ReadStream);
strictEqual(stream.readableEncoding, encoding);
strictEqual(stream.readableHighWaterMark, highWaterMark);
strictEqual(
await streamToString(stream),
Buffer.from("a").toString(encoding),
);
strictEqual(await text(stream), Buffer.from("a").toString(encoding));
} catch (error) {
serverError = error;
} finally {
Expand Down Expand Up @@ -266,7 +263,7 @@ export default (tests) => {
const streamA = uploadA.createReadStream();

ok(streamA instanceof ReadStream);
strictEqual(await streamToString(streamA), "a");
strictEqual(await text(streamA), "a");

ok(operations[1].variables.file instanceof Upload);

Expand All @@ -279,7 +276,7 @@ export default (tests) => {
const streamB = uploadB.createReadStream();

ok(streamB instanceof ReadStream);
strictEqual(await streamToString(streamB), "b");
strictEqual(await text(streamB), "b");
} catch (error) {
serverError = error;
} finally {
Expand Down Expand Up @@ -351,8 +348,8 @@ export default (tests) => {
ok(stream2 instanceof ReadStream);

const [content1, content2] = await Promise.all([
streamToString(stream1),
streamToString(stream2),
text(stream1),
text(stream2),
]);

strictEqual(content1, "a");
Expand Down Expand Up @@ -408,7 +405,7 @@ export default (tests) => {
const uploadB = await operation.variables.fileB.promise;
const streamB = uploadB.createReadStream();

await streamToString(streamB);
await text(streamB);
} catch (error) {
serverError = error;
} finally {
Expand Down Expand Up @@ -468,7 +465,7 @@ export default (tests) => {
const stream = upload.createReadStream();

ok(stream instanceof ReadStream);
strictEqual(await streamToString(stream), "a");
strictEqual(await text(stream), "a");
} catch (error) {
serverError = error;
} finally {
Expand Down Expand Up @@ -622,7 +619,7 @@ export default (tests) => {
const streamA = uploadA.createReadStream();

ok(streamA instanceof ReadStream);
strictEqual(await streamToString(streamA), "a");
strictEqual(await text(streamA), "a");
ok(operation.variables.files[1] instanceof Upload);
await rejects(operation.variables.files[1].promise, {
name: "PayloadTooLargeError",
Expand Down Expand Up @@ -717,7 +714,7 @@ export default (tests) => {
const streamB = uploadB.createReadStream();

ok(streamB instanceof ReadStream);
strictEqual(await streamToString(streamB), "b");
strictEqual(await text(streamB), "b");
} catch (error) {
serverError = error;
} finally {
Expand Down Expand Up @@ -832,7 +829,7 @@ export default (tests) => {
const stream = upload.createReadStream();

ok(stream instanceof ReadStream);
strictEqual(await streamToString(stream), "a");
strictEqual(await text(stream), "a");
};

const testUploadB = async () => {
Expand Down
18 changes: 0 additions & 18 deletions test/streamToString.mjs

This file was deleted.

0 comments on commit f24d71b

Please sign in to comment.