Skip to content

Commit a09fd14

Browse files
committed
test: update test
1 parent b759670 commit a09fd14

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

test/app.test.ts

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { Readable } from "node:stream";
1+
import {
2+
Readable as NodeStreamReadable,
3+
Transform as NodeStreamTransoform,
4+
} from "node:stream";
25
import { HTTPError, fromNodeHandler } from "../src/index.ts";
36
import { describeMatrix } from "./_setup.ts";
47

@@ -101,7 +104,7 @@ describeMatrix("app", (t, { it, expect }) => {
101104

102105
it.runIf(t.target === "node")("Node.js Readable Stream", async () => {
103106
t.app.use(() => {
104-
return new Readable({
107+
return new NodeStreamReadable({
105108
read() {
106109
this.push(Buffer.from("<h1>Hello world!</h1>", "utf8"));
107110
this.push(null);
@@ -115,33 +118,32 @@ describeMatrix("app", (t, { it, expect }) => {
115118
});
116119

117120
// TODO: investigate issues with stream errors on srvx
118-
// it.runIf(t.target === "node")(
119-
// "Node.js Readable Stream with Error",
120-
// async () => {
121-
// t.app.use(() => {
122-
// return new Readable({
123-
// read() {
124-
// this.push(Buffer.from("123", "utf8"));
125-
// this.push(null);
126-
// },
127-
// }).pipe(
128-
// new Transform({
129-
// transform(_chunk, _encoding, callback) {
130-
// const err = createError({
131-
// statusCode: 500,
132-
// statusText: "test",
133-
// });
134-
// setTimeout(() => callback(err), 0);
135-
// },
136-
// }),
137-
// );
138-
// });
139-
// // const res = await t.fetch("/");
140-
// expect(async () => await t.fetch("/")).toThrowError();
141-
// // expect(res.status).toBe(500);
142-
// // expect(JSON.parse(await res.text()).statusMessage).toBe("test");
143-
// },
144-
// );
121+
it.runIf(/* t.target === "node" */ false)(
122+
"Node.js Readable Stream with Error",
123+
async () => {
124+
t.app.use(() => {
125+
return new NodeStreamReadable({
126+
read() {
127+
this.push(Buffer.from("123", "utf8"));
128+
this.push(null);
129+
},
130+
}).pipe(
131+
new NodeStreamTransoform({
132+
transform(_chunk, _encoding, callback) {
133+
const err = new HTTPError({
134+
statusCode: 500,
135+
statusText: "test",
136+
});
137+
setTimeout(() => callback(err), 0);
138+
},
139+
}),
140+
);
141+
});
142+
const res = await t.fetch("/");
143+
expect(res.status).toBe(500);
144+
expect(JSON.parse(await res.text()).statusMessage).toBe("test");
145+
},
146+
);
145147

146148
it("Web Stream", async () => {
147149
t.app.use(() => {
@@ -156,7 +158,10 @@ describeMatrix("app", (t, { it, expect }) => {
156158
const res = await t.fetch("/");
157159

158160
expect(await res.text()).toBe("<h1>Hello world!</h1>");
159-
// expect(res.headers.get("transfer-encoding")).toBe("chunked"); // TODO: h3 should add this header
161+
if (t.target === "node") {
162+
// In Web API, we cannot determine protocol and connection type
163+
expect(res.headers.get("transfer-encoding")).toBe("chunked");
164+
}
160165
});
161166

162167
it("Web Stream with Error", async () => {

0 commit comments

Comments
 (0)