Skip to content

Commit 6658fc9

Browse files
committed
Refactor tests to use vitest-pool-workers and improve template
- Add @cloudflare/vitest-pool-workers for proper Workers runtime testing - Refactor src/index.ts to export testable helper functions - Rewrite tests with 34 comprehensive unit and integration tests - Add test/env.d.ts for cloudflare:test type augmentation - Update tsconfig.json to include test files and proper types - Configure vitest.config.ts for queue consumer testing - Add upload_source_maps to wrangler.jsonc - Update README with detailed setup instructions - Add preview_image_url for templates gallery
1 parent af61d92 commit 6658fc9

File tree

40 files changed

+16449
-4449
lines changed

40 files changed

+16449
-4449
lines changed
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
2-
"name": "astro-blog-starter-template",
3-
"compatibility_date": "2025-10-08",
4-
"compatibility_flags": ["nodejs_compat"],
5-
"main": "./dist/_worker.js/index.js",
6-
"assets": {
7-
"directory": "./dist",
8-
"binding": "ASSETS"
9-
},
10-
"observability": {
11-
"enabled": true
12-
},
13-
"upload_source_maps": true
2+
"name": "astro-blog-starter-template",
3+
"compatibility_date": "2025-10-08",
4+
"compatibility_flags": [
5+
"nodejs_compat"
6+
],
7+
"main": "./dist/_worker.js/index.js",
8+
"assets": {
9+
"directory": "./dist",
10+
"binding": "ASSETS"
11+
},
12+
"observability": {
13+
"enabled": true
14+
},
15+
"upload_source_maps": true
1416
}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"compatibility_date": "2025-10-08",
3-
"main": "src/index.ts",
4-
"name": "chanfana-openapi-template",
5-
"upload_source_maps": true,
6-
"observability": {
7-
"enabled": true
8-
},
9-
"d1_databases": [
10-
{
11-
"binding": "DB",
12-
"database_name": "openapi-template-db",
13-
"database_id": "18d141d5-062d-46a0-a92a-bade3f8c4b00"
14-
}
15-
]
2+
"compatibility_date": "2025-10-08",
3+
"main": "src/index.ts",
4+
"name": "chanfana-openapi-template",
5+
"upload_source_maps": true,
6+
"observability": {
7+
"enabled": true
8+
},
9+
"d1_databases": [
10+
{
11+
"binding": "DB",
12+
"database_name": "openapi-template-db",
13+
"database_id": "18d141d5-062d-46a0-a92a-bade3f8c4b00"
14+
}
15+
]
1616
}

containers-template/wrangler.jsonc

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
{
2-
"$schema": "node_modules/wrangler/config-schema.json",
3-
"name": "containers-template",
4-
"main": "src/index.ts",
5-
"compatibility_date": "2025-10-08",
6-
"compatibility_flags": ["nodejs_compat"],
7-
"observability": {
8-
"enabled": true
9-
},
10-
"containers": [
11-
{
12-
"class_name": "MyContainer",
13-
"image": "./Dockerfile",
14-
"max_instances": 10
15-
}
16-
],
17-
"durable_objects": {
18-
"bindings": [
19-
{
20-
"class_name": "MyContainer",
21-
"name": "MY_CONTAINER"
22-
}
23-
]
24-
},
25-
"migrations": [
26-
{
27-
"new_sqlite_classes": ["MyContainer"],
28-
"tag": "v1"
29-
}
30-
],
31-
"upload_source_maps": true
2+
"$schema": "node_modules/wrangler/config-schema.json",
3+
"name": "containers-template",
4+
"main": "src/index.ts",
5+
"compatibility_date": "2025-10-08",
6+
"compatibility_flags": [
7+
"nodejs_compat"
8+
],
9+
"observability": {
10+
"enabled": true
11+
},
12+
"containers": [
13+
{
14+
"class_name": "MyContainer",
15+
"image": "./Dockerfile",
16+
"max_instances": 10
17+
}
18+
],
19+
"durable_objects": {
20+
"bindings": [
21+
{
22+
"class_name": "MyContainer",
23+
"name": "MY_CONTAINER"
24+
}
25+
]
26+
},
27+
"migrations": [
28+
{
29+
"new_sqlite_classes": [
30+
"MyContainer"
31+
],
32+
"tag": "v1"
33+
}
34+
],
35+
"upload_source_maps": true
3236
}

d1-starter-sessions-api-template/wrangler.jsonc

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
* https://developers.cloudflare.com/workers/wrangler/configuration/
44
*/
55
{
6-
"$schema": "node_modules/wrangler/config-schema.json",
7-
"name": "d1-starter-sessions-api-template",
8-
"main": "src/index.ts",
9-
"compatibility_date": "2025-10-08",
10-
"observability": {
11-
"enabled": true
12-
},
13-
"assets": {
14-
"directory": "./public/"
15-
},
16-
/**
6+
"$schema": "node_modules/wrangler/config-schema.json",
7+
"name": "d1-starter-sessions-api-template",
8+
"main": "src/index.ts",
9+
"compatibility_date": "2025-10-08",
10+
"observability": {
11+
"enabled": true
12+
},
13+
"assets": {
14+
"directory": "./public/"
15+
},
16+
/**
1717
* Bindings
1818
* Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
1919
* databases, object storage, AI inference, real-time communication and more.
2020
* https://developers.cloudflare.com/workers/runtime-apis/bindings/
2121
*/
22-
"d1_databases": [
23-
{
24-
"binding": "DB01",
25-
"database_name": "d1-starter-sessions-api",
26-
"database_id": "3690f364-3425-4fab-8eb7-c74c5717578a"
27-
}
28-
],
29-
"upload_source_maps": true
22+
"d1_databases": [
23+
{
24+
"binding": "DB01",
25+
"database_name": "d1-starter-sessions-api",
26+
"database_id": "3690f364-3425-4fab-8eb7-c74c5717578a"
27+
}
28+
],
29+
"upload_source_maps": true
3030
}

d1-template/wrangler.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"compatibility_date": "2025-10-08",
3-
"main": "src/index.ts",
4-
"name": "d1-template",
5-
"upload_source_maps": true,
6-
"d1_databases": [
7-
{
8-
"binding": "DB",
9-
"database_id": "151f7d9b-365f-41d7-83ed-0bf4eeef5086",
10-
"database_name": "d1-template-database"
11-
}
12-
],
13-
"observability": {
14-
"enabled": true
15-
}
2+
"compatibility_date": "2025-10-08",
3+
"main": "src/index.ts",
4+
"name": "d1-template",
5+
"upload_source_maps": true,
6+
"d1_databases": [
7+
{
8+
"binding": "DB",
9+
"database_id": "151f7d9b-365f-41d7-83ed-0bf4eeef5086",
10+
"database_name": "d1-template-database"
11+
}
12+
],
13+
"observability": {
14+
"enabled": true
15+
}
1616
}
Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
{
2-
"compatibility_date": "2025-10-08",
3-
"main": "src/server/index.ts",
4-
"name": "durable-chat-template",
5-
"migrations": [
6-
{
7-
"new_sqlite_classes": ["Chat"],
8-
"tag": "v1"
9-
}
10-
],
11-
"assets": {
12-
"directory": "./public",
13-
"binding": "ASSETS",
14-
"not_found_handling": "single-page-application"
15-
},
16-
"build": {
17-
"command": "esbuild src/client/index.tsx --bundle --splitting --format=esm --platform=browser --outdir=public/dist"
18-
},
19-
"durable_objects": {
20-
"bindings": [
21-
{
22-
"class_name": "Chat",
23-
"name": "Chat"
24-
}
25-
]
26-
},
27-
"observability": {
28-
"enabled": true
29-
},
30-
"upload_source_maps": true
2+
"compatibility_date": "2025-10-08",
3+
"main": "src/server/index.ts",
4+
"name": "durable-chat-template",
5+
"migrations": [
6+
{
7+
"new_sqlite_classes": [
8+
"Chat"
9+
],
10+
"tag": "v1"
11+
}
12+
],
13+
"assets": {
14+
"directory": "./public",
15+
"binding": "ASSETS",
16+
"not_found_handling": "single-page-application"
17+
},
18+
"build": {
19+
"command": "esbuild src/client/index.tsx --bundle --splitting --format=esm --platform=browser --outdir=public/dist"
20+
},
21+
"durable_objects": {
22+
"bindings": [
23+
{
24+
"class_name": "Chat",
25+
"name": "Chat"
26+
}
27+
]
28+
},
29+
"observability": {
30+
"enabled": true
31+
},
32+
"upload_source_maps": true
3133
}
Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
{
2-
"$schema": "node_modules/wrangler/config-schema.json",
3-
"name": "hello-world-do-template",
4-
"main": "src/index.ts",
5-
"compatibility_date": "2025-10-08",
6-
"upload_source_maps": true,
7-
"migrations": [
8-
{
9-
"new_sqlite_classes": ["MyDurableObject"],
10-
"tag": "v1"
11-
}
12-
],
13-
"durable_objects": {
14-
"bindings": [
15-
{
16-
"class_name": "MyDurableObject",
17-
"name": "MY_DURABLE_OBJECT"
18-
}
19-
]
20-
},
21-
"observability": {
22-
"enabled": true
23-
}
2+
"$schema": "node_modules/wrangler/config-schema.json",
3+
"name": "hello-world-do-template",
4+
"main": "src/index.ts",
5+
"compatibility_date": "2025-10-08",
6+
"upload_source_maps": true,
7+
"migrations": [
8+
{
9+
"new_sqlite_classes": [
10+
"MyDurableObject"
11+
],
12+
"tag": "v1"
13+
}
14+
],
15+
"durable_objects": {
16+
"bindings": [
17+
{
18+
"class_name": "MyDurableObject",
19+
"name": "MY_DURABLE_OBJECT"
20+
}
21+
]
22+
},
23+
"observability": {
24+
"enabled": true
25+
}
2426
}

llm-chat-app-template/wrangler.jsonc

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
* https://developers.cloudflare.com/workers/wrangler/configuration/
44
*/
55
{
6-
"$schema": "node_modules/wrangler/config-schema.json",
7-
"name": "llm-chat-app-template",
8-
"main": "src/index.ts",
9-
"compatibility_date": "2025-10-08",
10-
"compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"],
11-
"assets": {
12-
"binding": "ASSETS",
13-
"directory": "./public"
14-
},
15-
"observability": {
16-
"enabled": true
17-
},
18-
"ai": {
19-
"binding": "AI"
20-
},
21-
"upload_source_maps": true
6+
"$schema": "node_modules/wrangler/config-schema.json",
7+
"name": "llm-chat-app-template",
8+
"main": "src/index.ts",
9+
"compatibility_date": "2025-10-08",
10+
"compatibility_flags": [
11+
"nodejs_compat",
12+
"global_fetch_strictly_public"
13+
],
14+
"assets": {
15+
"binding": "ASSETS",
16+
"directory": "./public"
17+
},
18+
"observability": {
19+
"enabled": true
20+
},
21+
"ai": {
22+
"binding": "AI"
23+
},
24+
"upload_source_maps": true
2225
}

0 commit comments

Comments
 (0)