Skip to content

Commit

Permalink
test(index): keep the server alive during the entire test session
Browse files Browse the repository at this point in the history
Also, remove use of deprecated code.
  • Loading branch information
arunanshub committed Jun 5, 2023
1 parent c74a6e4 commit 0f4249d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,38 @@ import {
} from "h3";
import { Blob } from "fetch-blob";
import { FormData } from "formdata-polyfill/esm.min.js";
import { describe, beforeEach, afterEach, it, expect } from "vitest";
import { describe, beforeAll, afterAll, it, expect } from "vitest";
import { Headers, $fetch } from "../src/node";

describe("ofetch", () => {
let listener;
const getURL = (url) => joinURL(listener.url, url);

beforeEach(async () => {
beforeAll(async () => {
const app = createApp()
.use(
"/ok",
eventHandler(() => "ok")
)
.use(
"/params",
eventHandler((event) => getQuery(event.req.url || ""))
eventHandler((event) => getQuery(event.node.req.url || ""))
)
.use(
"/url",
eventHandler((event) => event.req.url)
eventHandler((event) => event.node.req.url)
)
.use(
"/post",
eventHandler(async (event) => ({
body: await readBody(event),
headers: event.req.headers,
headers: event.node.req.headers,
}))
)
.use(
"/binary",
eventHandler((event) => {
event.res.setHeader("Content-Type", "application/octet-stream");
event.node.res.setHeader("Content-Type", "application/octet-stream");
return new Blob(["binary"]);
})
)
Expand All @@ -51,7 +51,7 @@ describe("ofetch", () => {
listener = await listen(toNodeListener(app));
});

afterEach(async () => {
afterAll(async () => {
await listener.close();
});

Expand Down

0 comments on commit 0f4249d

Please sign in to comment.