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
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { env, exports, withEnv } from "cloudflare:workers";
|
|
import { describe, it } from "vitest";
|
|
import worker from "../src";
|
|
|
|
describe("Hello World user worker", () => {
|
|
it('responds with "Hello, World!" (integration style)', async ({
|
|
expect,
|
|
}) => {
|
|
const response = await exports.default.fetch("http://example.com/message");
|
|
expect(await response.text()).toMatchInlineSnapshot(`"Hello, World!"`);
|
|
});
|
|
|
|
it("returns 404 for unknown routes (assets are not routed through exports.default)", async ({
|
|
expect,
|
|
}) => {
|
|
const response = await exports.default.fetch("http://example.com/");
|
|
expect(response.status).toBe(404);
|
|
});
|
|
|
|
it("can mock the ASSETS binding using withEnv", async ({ expect }) => {
|
|
const mockAssets = {
|
|
fetch: async () => new Response("mocked asset response"),
|
|
};
|
|
|
|
await withEnv({ ...env, ASSETS: mockAssets }, async () => {
|
|
const response = await worker.fetch(
|
|
new Request("http://example.com/binding"),
|
|
env,
|
|
{} as ExecutionContext
|
|
);
|
|
expect(await response.text()).toBe("mocked asset response");
|
|
});
|
|
});
|
|
});
|