Skip to content

Commit e671d28

Browse files
committed
Ask Claude to write tests.
prompt: Please write tests for this library using vitest. The tests should use a mock or fake KV namespace for storage. Be sure to study README.md and storage-schema.md in addition to oauth-provider.ts to fully understand the functionality. Try to cover all the important logic. Claude initially wrote a separate mock library. prompt: Let's just put the whole test including mocks in one file. Claude spent several minutes thinking and produced the test. It failed immediately due to `cloudflare:workers` not being available. prompt: Looks like for this test to run under node, we need to mock out the `cloudflare:workers` module. We just need to define the `WorkerEntrypoint` class. Can you do that? Claude did this. Yay. Several tests are still failing, but they do run. Will debug in separate commits.
1 parent 5fbd3c6 commit e671d28

File tree

5 files changed

+930
-0
lines changed

5 files changed

+930
-0
lines changed

__tests__/mocks/cloudflare-workers.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Mock for cloudflare:workers module
3+
* Provides a minimal implementation of WorkerEntrypoint for testing
4+
*/
5+
6+
export class WorkerEntrypoint {
7+
ctx: any;
8+
env: any;
9+
10+
constructor(ctx: any, env: any) {
11+
this.ctx = ctx;
12+
this.env = env;
13+
}
14+
15+
fetch(request: Request): Response | Promise<Response> {
16+
throw new Error('Method not implemented. This should be overridden by subclasses.');
17+
}
18+
}

0 commit comments

Comments
 (0)