From 5224f035cff0a0e31a672e330a90aaefcbbae1e1 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 10 Jul 2023 14:03:50 +0200 Subject: [PATCH] refactor test --- test/app.test.ts | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/test/app.test.ts b/test/app.test.ts index 2c858cf6..df56deb8 100644 --- a/test/app.test.ts +++ b/test/app.test.ts @@ -10,6 +10,9 @@ import { createError, } from "../src"; +const readableStreamSupported = + typeof ReadableStream !== "undefined"; /* Node.js 16 */ + describe("app", () => { let app: App; let request: SuperTest; @@ -102,7 +105,7 @@ describe("app", () => { expect(JSON.parse(res.text).statusMessage).toBe("test"); }); - it.skipIf(typeof ReadableStream === undefined)("Web Stream", async () => { + it.runIf(readableStreamSupported)("Web Stream", async () => { app.use( eventHandler(() => { return new ReadableStream({ @@ -120,27 +123,24 @@ describe("app", () => { expect(res.header["transfer-encoding"]).toBe("chunked"); }); - it.skipIf(typeof ReadableStream === undefined)( - "Web Stream with Error", - async () => { - app.use( - eventHandler(() => { - return new ReadableStream({ - start() { - throw createError({ - statusCode: 500, - statusText: "test", - }); - }, - }); - }) - ); - const res = await request.get("/"); + it.runIf(readableStreamSupported)("Web Stream with Error", async () => { + app.use( + eventHandler(() => { + return new ReadableStream({ + start() { + throw createError({ + statusCode: 500, + statusText: "test", + }); + }, + }); + }) + ); + const res = await request.get("/"); - expect(res.statusCode).toBe(500); - expect(JSON.parse(res.text).statusMessage).toBe("test"); - } - ); + expect(res.statusCode).toBe(500); + expect(JSON.parse(res.text).statusMessage).toBe("test"); + }); it("can return HTML directly", async () => { app.use(eventHandler(() => "

Hello world!

"));