experiment-worker-api/test/index.spec.js
HoshinoKoji 85d462a53d Initial commit (by create-cloudflare CLI)
Details:
  C3 = create-cloudflare@2.28.0
  project name = r2-worker
  package manager = npm@10.7.0
  wrangler = wrangler@3.78.8
  git = 2.42.0.windows.2
2024-09-24 20:52:14 +08:00

21 lines
899 B
JavaScript

import { env, createExecutionContext, waitOnExecutionContext, SELF } from 'cloudflare:test';
import { describe, it, expect } from 'vitest';
import worker from '../src';
describe('Hello World worker', () => {
it('responds with Hello World! (unit style)', async () => {
const request = new Request('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(`"Hello World!"`);
});
it('responds with Hello World! (integration style)', async () => {
const response = await SELF.fetch(request, env, ctx);
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
});
});