|
| 1 | +import dedent from "ts-dedent"; |
| 2 | +import { test } from "./helpers"; |
| 3 | + |
| 4 | +// This test requires CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN |
| 5 | +// environment variables to be set, as it exercises remote proxy sessions |
| 6 | +// that connect to the Cloudflare API. |
| 7 | +test.skipIf( |
| 8 | + !process.env.CLOUDFLARE_ACCOUNT_ID || !process.env.CLOUDFLARE_API_TOKEN |
| 9 | +)( |
| 10 | + "disposes remote proxy sessions on pool close", |
| 11 | + async ({ expect, seed, vitestRun }) => { |
| 12 | + await seed({ |
| 13 | + "vitest.config.mts": dedent` |
| 14 | + import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config"; |
| 15 | + export default defineWorkersConfig({ |
| 16 | + test: { |
| 17 | + reporters: ["hanging-process", "verbose"], |
| 18 | + poolOptions: { |
| 19 | + workers: { |
| 20 | + wrangler: { configPath: "./wrangler.jsonc" }, |
| 21 | + }, |
| 22 | + }, |
| 23 | + } |
| 24 | + }); |
| 25 | + `, |
| 26 | + "wrangler.jsonc": dedent` |
| 27 | + { |
| 28 | + "name": "test-worker", |
| 29 | + "main": "src/index.ts", |
| 30 | + "compatibility_date": "2025-06-01", |
| 31 | + "compatibility_flags": ["nodejs_compat"], |
| 32 | + "ai": { "binding": "AI" }, |
| 33 | + "account_id": "${process.env.CLOUDFLARE_ACCOUNT_ID}" |
| 34 | + } |
| 35 | + `, |
| 36 | + "src/index.ts": dedent` |
| 37 | + export default { |
| 38 | + async fetch(request, env, ctx) { |
| 39 | + return new Response("Hello"); |
| 40 | + } |
| 41 | + } |
| 42 | + `, |
| 43 | + "src/index.test.ts": dedent` |
| 44 | + import { SELF } from "cloudflare:test"; |
| 45 | + import { it, expect } from "vitest"; |
| 46 | + it("responds with Hello", async () => { |
| 47 | + const response = await SELF.fetch("http://localhost/"); |
| 48 | + expect(await response.text()).toBe("Hello"); |
| 49 | + }); |
| 50 | + `, |
| 51 | + }); |
| 52 | + |
| 53 | + const result = await vitestRun({ |
| 54 | + flags: ["--reporter=hanging-process", "--reporter=verbose"], |
| 55 | + }); |
| 56 | + |
| 57 | + expect(result.stderr).not.toContain( |
| 58 | + "something prevents Vite server from exiting" |
| 59 | + ); |
| 60 | + }, |
| 61 | + 20_000 |
| 62 | +); |
0 commit comments