mirror of
https://github.com/fmhy/edit.git
synced 2025-11-28 00:41:20 +11:00
30 lines
2.1 KiB
TypeScript
30 lines
2.1 KiB
TypeScript
import { env, createExecutionContext, waitOnExecutionContext, SELF } from 'cloudflare:test';
|
|
import { describe, it, expect } from 'vitest';
|
|
import worker from '../src/index';
|
|
|
|
// For now, you'll need to do something like this to get a correctly-typed
|
|
// `Request` to pass to `worker.fetch()`.
|
|
const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;
|
|
|
|
describe('Hello World worker', () => {
|
|
it('responds with Hello World! (unit style)', async () => {
|
|
const request = new IncomingRequest('http://example.com');
|
|
// Create an empty context to pass to `worker.fetch()`.
|
|
const ctx = createExecutionContext();
|
|
const response = await worker.fetch(request, env, ctx);
|
|
// Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
|
|
await waitOnExecutionContext(ctx);
|
|
expect(await response.text()).toMatchInlineSnapshot(`
|
|
"<!doctype html><html lang="en"><head><title>Example Domain</title><meta name="viewport" content="width=device-width, initial-scale=1"><style>body{background:#eee;width:60vw;margin:15vh auto;font-family:system-ui,sans-serif}h1{font-size:1.5em}div{opacity:0.8}a:link,a:visited{color:#348}</style><body><div><h1>Example Domain</h1><p>This domain is for use in documentation examples without needing permission. Avoid use in operations.<p><a href="https://iana.org/domains/example">Learn more</a></div></body></html>
|
|
"
|
|
`);
|
|
});
|
|
|
|
it('responds with Hello World! (integration style)', async () => {
|
|
const response = await SELF.fetch('https://example.com');
|
|
expect(await response.text()).toMatchInlineSnapshot(`
|
|
"<!doctype html><html lang="en"><head><title>Example Domain</title><meta name="viewport" content="width=device-width, initial-scale=1"><style>body{background:#eee;width:60vw;margin:15vh auto;font-family:system-ui,sans-serif}h1{font-size:1.5em}div{opacity:0.8}a:link,a:visited{color:#348}</style><body><div><h1>Example Domain</h1><p>This domain is for use in documentation examples without needing permission. Avoid use in operations.<p><a href="https://iana.org/domains/example">Learn more</a></div></body></html>
|
|
"
|
|
`);
|
|
});
|
|
});
|