sandbox-web-ide/backend/ai/test/index.spec.ts

31 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-05-13 23:00:02 -07:00
// test/index.spec.ts
2024-10-24 12:44:38 -06:00
import {
createExecutionContext,
env,
SELF,
waitOnExecutionContext,
} from "cloudflare:test"
import { describe, expect, it } from "vitest"
import worker from "../src/index"
2024-05-13 23:00:02 -07:00
// For now, you'll need to do something like this to get a correctly-typed
// `Request` to pass to `worker.fetch()`.
2024-10-24 12:44:38 -06:00
const IncomingRequest = Request<unknown, IncomingRequestCfProperties>
2024-05-13 23:00:02 -07:00
2024-10-24 12:44:38 -06:00
describe("Hello World worker", () => {
it("responds with Hello World! (unit style)", async () => {
const request = new IncomingRequest("http://example.com")
2024-05-13 23:00:02 -07:00
// Create an empty context to pass to `worker.fetch()`.
2024-10-24 12:44:38 -06:00
const ctx = createExecutionContext()
const response = await worker.fetch(request, env, ctx)
2024-05-13 23:00:02 -07:00
// Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
2024-10-24 12:44:38 -06:00
await waitOnExecutionContext(ctx)
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`)
})
2024-05-13 23:00:02 -07:00
2024-10-24 12:44:38 -06:00
it("responds with Hello World! (integration style)", async () => {
const response = await SELF.fetch("https://example.com")
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`)
})
})