Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add polyfills to run all tests against node.js 16 #456

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"],
},
},
});