70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { beforeEach, test } from "vitest";
|
|
import { serveSinglePageApp } from "../src/index";
|
|
import { mockGlobalScope, mockRequestScope } from "./mocks";
|
|
|
|
beforeEach(() => {
|
|
mockGlobalScope();
|
|
mockRequestScope();
|
|
});
|
|
|
|
function testRequest(path: string) {
|
|
const url = new URL("https://example.com");
|
|
url.pathname = path;
|
|
const request = new Request(url.toString());
|
|
|
|
return request;
|
|
}
|
|
|
|
test("serveSinglePageApp returns root asset path when request path ends in .html", async ({
|
|
expect,
|
|
}) => {
|
|
const path = "/foo/thing.html";
|
|
const request = testRequest(path);
|
|
|
|
const expected_request = testRequest("/index.html");
|
|
const actual_request = serveSinglePageApp(request);
|
|
|
|
expect(expected_request.url).toEqual(actual_request.url);
|
|
});
|
|
|
|
test("serveSinglePageApp returns root asset path when request path does not have extension", async ({
|
|
expect,
|
|
}) => {
|
|
const path = "/foo/thing";
|
|
const request = testRequest(path);
|
|
|
|
const expected_request = testRequest("/index.html");
|
|
const actual_request = serveSinglePageApp(request);
|
|
|
|
expect(expected_request.url).toEqual(actual_request.url);
|
|
});
|
|
|
|
test("serveSinglePageApp returns requested asset when request path has non-html extension", async ({
|
|
expect,
|
|
}) => {
|
|
const path = "/foo/thing.js";
|
|
const request = testRequest(path);
|
|
|
|
const expected_request = request;
|
|
const actual_request = serveSinglePageApp(request);
|
|
|
|
expect(expected_request.url).toEqual(actual_request.url);
|
|
});
|