Skip to content

Commit

Permalink
chore: test redirect()
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCommieAxolotl committed Aug 2, 2023
1 parent dcd7918 commit 487fcea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion test/byos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from "vitest";

import { createServer } from "http";

import { html, json, status } from "../src/aura";
import { html, json, status, redirect } from "../src/aura";
import { app, route } from "../src";

const myOwnServer = createServer();
Expand All @@ -15,6 +15,7 @@ const index = route("/", () => html`<h1>Hello World</h1>`);

server.attach(index);
server.attach(route("/json", () => json({ hello: "world" })));
server.attach(route("/redirect", () => redirect("/")));

test("byos", async (t) => {
server.attach(
Expand All @@ -31,6 +32,10 @@ test("byos", async (t) => {
// server is a Server instance
t.expect(server).toBeTruthy();

// redirects work
const redirect = await fetch("http://localhost:4000/redirect");
t.expect(redirect.redirected).toBe(true);

// response sends accurate status codes
const response = await fetch("http://localhost:4000/");
t.expect(response.status).toBe(200);
Expand Down
7 changes: 6 additions & 1 deletion test/standalone.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from "vitest";

import { html, json, status } from "../src/aura";
import { html, json, status, redirect } from "../src/aura";
import { app, route } from "../src";

const server = app(3000);
Expand All @@ -9,6 +9,7 @@ const index = route("/", () => html`<h1>Hello World</h1>`);

server.attach(index);
server.attach(route("/json", () => json({ hello: "world" })));
server.attach(route("/redirect", () => redirect("/")));

test("standalone", async (t) => {
server.attach(
Expand All @@ -25,6 +26,10 @@ test("standalone", async (t) => {
// server is a Server instance
t.expect(server).toBeTruthy();

// redirects work
const redirect = await fetch("http://localhost:3000/redirect");
t.expect(redirect.redirected).toBe(true);

// response sends accurate status codes
const response = await fetch("http://localhost:3000/");
t.expect(response.status).toBe(200);
Expand Down

0 comments on commit 487fcea

Please sign in to comment.