Skip to content

Commit

Permalink
test: add polyfills to run all tests against node.js 16 (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Jul 24, 2023
1 parent a9b8de8 commit 591836e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
1 change: 1 addition & 0 deletions test/_setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "node-fetch-native/polyfill";
13 changes: 4 additions & 9 deletions test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import {
createError,
} from "../src";

// Node.js 16 limitations
const readableStreamSupported = typeof ReadableStream !== "undefined";
const blobSupported = typeof Blob !== "undefined";
const responseSupported = typeof Response !== "undefined";

describe("app", () => {
let app: App;
let request: SuperTest<Test>;
Expand All @@ -34,7 +29,7 @@ describe("app", () => {
expect(res.body).toEqual({ url: "/" });
});

it.runIf(responseSupported)("can return Response directly", async () => {
it("can return Response directly", async () => {
app.use(
"/",
eventHandler(
Expand Down Expand Up @@ -74,7 +69,7 @@ describe("app", () => {
}
});

it.runIf(blobSupported)("can return Blob directly", async () => {
it("can return Blob directly", async () => {
app.use(
eventHandler(
() =>
Expand Down Expand Up @@ -139,7 +134,7 @@ describe("app", () => {
expect(JSON.parse(res.text).statusMessage).toBe("test");
});

it.runIf(readableStreamSupported)("Web Stream", async () => {
it("Web Stream", async () => {
app.use(
eventHandler(() => {
return new ReadableStream({
Expand All @@ -157,7 +152,7 @@ describe("app", () => {
expect(res.header["transfer-encoding"]).toBe("chunked");
});

it.runIf(readableStreamSupported)("Web Stream with Error", async () => {
it("Web Stream with Error", async () => {
app.use(
eventHandler(() => {
return new ReadableStream({
Expand Down
4 changes: 1 addition & 3 deletions test/event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
getMethod,
} from "../src";

const supportsHeaders = typeof Headers !== "undefined";

describe("Event", () => {
let app: App;
let request: SuperTest<Test>;
Expand All @@ -32,7 +30,7 @@ describe("Event", () => {
expect(result.text).toBe("200");
});

it.runIf(supportsHeaders)("can read the headers", async () => {
it("can read the headers", async () => {
app.use(
"/",
eventHandler((event) => {
Expand Down
7 changes: 4 additions & 3 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
setupFiles: ["./test/_setup"],
coverage: {
reporter: ["text", "clover", "json"]
}
}
reporter: ["text", "clover", "json"],
},
},
});

0 comments on commit 591836e

Please sign in to comment.