Initial commit (by create-cloudflare CLI)
Details: C3 = create-cloudflare@2.64.2 project name = tangfamily package manager = npm@11.6.1 wrangler = wrangler@4.66.0 git = 2.47.1.windows.1
This commit is contained in:
3
test/env.d.ts
vendored
Normal file
3
test/env.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare module 'cloudflare:test' {
|
||||
interface ProvidedEnv extends Env {}
|
||||
}
|
||||
41
test/index.spec.ts
Normal file
41
test/index.spec.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { env, createExecutionContext, waitOnExecutionContext, SELF } from 'cloudflare:test';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import worker from '../src';
|
||||
|
||||
describe('Hello World user worker', () => {
|
||||
describe('request for /message', () => {
|
||||
it('/ responds with "Hello, World!" (unit style)', async () => {
|
||||
const request = new Request<unknown, IncomingRequestCfProperties>('http://example.com/message');
|
||||
// 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(`"Hello, World!"`);
|
||||
});
|
||||
|
||||
it('responds with "Hello, World!" (integration style)', async () => {
|
||||
const request = new Request('http://example.com/message');
|
||||
const response = await SELF.fetch(request);
|
||||
expect(await response.text()).toMatchInlineSnapshot(`"Hello, World!"`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('request for /random', () => {
|
||||
it('/ responds with a random UUID (unit style)', async () => {
|
||||
const request = new Request<unknown, IncomingRequestCfProperties>('http://example.com/random');
|
||||
// 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()).toMatch(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/);
|
||||
});
|
||||
|
||||
it('responds with a random UUID (integration style)', async () => {
|
||||
const request = new Request('http://example.com/random');
|
||||
const response = await SELF.fetch(request);
|
||||
expect(await response.text()).toMatch(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/);
|
||||
});
|
||||
});
|
||||
});
|
||||
8
test/tsconfig.json
Normal file
8
test/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"types": ["@cloudflare/vitest-pool-workers"]
|
||||
},
|
||||
"include": ["./**/*.ts", "../worker-configuration.d.ts"],
|
||||
"exclude": []
|
||||
}
|
||||
Reference in New Issue
Block a user