API-testing CloudFlare workers - Fri Nov 1020234:35 PMindex.test.ts
package.json
API-testing CloudFlare workers
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { unstable_dev, type UnstableDevWorker } from 'wrangler';
describe('Worker', () => {
let worker: UnstableDevWorker;
beforeAll(async () => {
worker = await unstable_dev('src/index.ts');
});
afterAll(async () => {
await worker.stop();
});
it('should return a response', async () => {
const resp = await worker.fetch('/');
if (resp) {
const text = await resp.text();
expect(text).toMatchInlineSnapshot();
}
});
})
This is tested with
"vitest": "0.29.8",
"wrangler": "2.13.0"
0193595e-9520-7fe5-b332-64fd6cec5610