Skip to content

Commit 96a4d4e

Browse files
committed
update to vitest v4
1 parent c3e579c commit 96a4d4e

File tree

14 files changed

+1039
-1386
lines changed

14 files changed

+1039
-1386
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
cache: "npm"
1616

1717
- run: npm ci
18+
- run: npm run cf-typegen
1819
- run: npm run typecheck
1920
- run: npm run lint
2021
- run: npm run format:check

.github/workflows/push.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ jobs:
2121
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
2222
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
2323
environment: production
24-
wranglerVersion: "4.14.1"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
.wrangler/
33
coverage/
4+
worker-configuration.d.ts

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ Artifacts that target windows must be `.zip` files. All other non windows target
482482
git clone https://github.com/zigtools/release-worker
483483
cd release-worker
484484
npm install
485+
npm run cf-typegen
485486
npx wrangler d1 execute staging-db-backend --local --file=./migrations/0000_initial.sql
486487
npm run dev
487488
```

package-lock.json

Lines changed: 898 additions & 1265 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,25 @@
66
"deploy": "wrangler deploy",
77
"dev": "wrangler dev",
88
"start": "wrangler dev",
9+
"cf-typegen": "wrangler types --strict-vars=false",
10+
"typecheck": "wrangler types --strict-vars=false --check && tsc",
911
"test": "vitest",
10-
"cf-typegen": "wrangler types --include-runtime=false --strict-vars=false",
1112
"coverage": "vitest run --coverage",
12-
"typecheck": "tsc",
1313
"format": "prettier --write .",
1414
"format:check": "prettier --check .",
1515
"lint": "eslint"
1616
},
1717
"devDependencies": {
18-
"@cloudflare/vitest-pool-workers": "^0.12.0",
19-
"@cloudflare/workers-types": "^4.20250430.0",
18+
"@cloudflare/vitest-pool-workers": "^0.13.0",
2019
"@eslint/js": "^9.8.0",
2120
"@types/eslint__js": "^8.42.3",
2221
"@types/node": "^22.15.3",
23-
"@vitest/coverage-istanbul": "~3.2.0",
22+
"@vitest/coverage-istanbul": "^4.1.0",
2423
"eslint": "^9.8.0",
2524
"prettier": "^3.2.5",
2625
"typescript": "^5.4.5",
2726
"typescript-eslint": "^8.10.0",
28-
"vitest": "~3.2.0",
27+
"vitest": "^4.1.0",
2928
"wrangler": "^4.59.3"
3029
}
3130
}

test/env.d.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
declare module "cloudflare:test" {
2-
interface ProvidedEnv extends Env {
3-
ZIGTOOLS_DB: D1Database;
4-
TEST_MIGRATIONS: D1Migration[]; // Defined in `vitest.config.ts`
5-
}
1+
declare module "cloudflare:workers" {
2+
interface ProvidedEnv extends Env {}
63
}

test/index.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { SELF } from "cloudflare:test";
1+
import { env, exports } from "cloudflare:workers";
22
import { test, expect } from "vitest";
33

44
test("unknown URL path", async () => {
5-
const response = await SELF.fetch("https://example.com/unknown", {});
5+
const response = await exports.default.fetch(
6+
"https://example.com/unknown",
7+
{},
8+
);
69
expect(response.status).toBe(404);
710
expect(Object.fromEntries(response.headers.entries())).toStrictEqual({
811
"access-control-allow-origin": "*",
@@ -11,7 +14,7 @@ test("unknown URL path", async () => {
1114
});
1215

1316
test("standard OPTIONS request", async () => {
14-
const response = await SELF.fetch("https://example.com", {
17+
const response = await exports.default.fetch("https://example.com", {
1518
method: "OPTIONS",
1619
});
1720
expect(response.status).toBe(200);
@@ -21,7 +24,7 @@ test("standard OPTIONS request", async () => {
2124
});
2225

2326
test("CORS OPTIONS request", async () => {
24-
const response = await SELF.fetch("https://example.com", {
27+
const response = await exports.default.fetch("https://example.com", {
2528
method: "OPTIONS",
2629
headers: {
2730
Origin: "https://foo.example",

test/publish.test.ts

Lines changed: 83 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { createExecutionContext, env, SELF } from "cloudflare:test";
1+
import { env, exports } from "cloudflare:workers";
2+
import {
3+
createExecutionContext,
4+
waitOnExecutionContext,
5+
} from "cloudflare:test";
26
import assert from "node:assert";
37
import { vi, describe, test, expect, beforeEach, afterEach } from "vitest";
48
import {
@@ -27,7 +31,7 @@ async function searchZLSRelease(
2731

2832
async function sendPublishForm(body: PublishRequest): Promise<Response> {
2933
assert(typeof env.API_TOKEN === "string" && env.API_TOKEN);
30-
return await SELF.fetch(
34+
return await exports.default.fetch(
3135
new Request("https://example.com/v1/zls/publish", {
3236
body: JSON.stringify(body),
3337
method: "POST",
@@ -121,8 +125,14 @@ function getSampleArtifacts(version: string): Record<string, ArtifactMetadata> {
121125
}
122126

123127
describe("/v1/zls/publish", () => {
128+
afterEach(async () => {
129+
await env.ZIGTOOLS_DB.exec("DELETE FROM ZLSReleases");
130+
});
131+
124132
test("expect POST method", async () => {
125-
const response = await SELF.fetch("https://example.com/v1/zls/publish");
133+
const response = await exports.default.fetch(
134+
"https://example.com/v1/zls/publish",
135+
);
126136
expect(await response.text()).toBe("method must be 'POST'");
127137
expect(response.status).toBe(405);
128138
});
@@ -146,103 +156,127 @@ describe("/v1/zls/publish", () => {
146156

147157
describe("check authorization", () => {
148158
test("missing Authorization header", async () => {
149-
const response = await SELF.fetch("https://example.com/v1/zls/publish", {
150-
method: "POST",
151-
});
159+
const response = await exports.default.fetch(
160+
"https://example.com/v1/zls/publish",
161+
{
162+
method: "POST",
163+
},
164+
);
152165

153166
expect(await response.text()).toBe("Authorization failed");
154167
expect(response.status).toBe(401);
155168
});
156169

157170
test("invalid Authorization header", async () => {
158-
const response = await SELF.fetch("https://example.com/v1/zls/publish", {
159-
body: null,
160-
method: "POST",
161-
headers: {
162-
Authorization: "invalid",
171+
const response = await exports.default.fetch(
172+
"https://example.com/v1/zls/publish",
173+
{
174+
body: null,
175+
method: "POST",
176+
headers: {
177+
Authorization: "invalid",
178+
},
163179
},
164-
});
180+
);
165181
expect(await response.text()).toContain(
166182
"Unexpected Authorization header",
167183
);
168184
expect(response.status).toBe(400);
169185
});
170186

171187
test("non Basic Authorization header", async () => {
172-
const response = await SELF.fetch("https://example.com/v1/zls/publish", {
173-
body: null,
174-
method: "POST",
175-
headers: {
176-
Authorization: "Bearer foo",
188+
const response = await exports.default.fetch(
189+
"https://example.com/v1/zls/publish",
190+
{
191+
body: null,
192+
method: "POST",
193+
headers: {
194+
Authorization: "Bearer foo",
195+
},
177196
},
178-
});
197+
);
179198
expect(await response.text()).toBe(
180199
"Expected 'Basic' authentication scheme!",
181200
);
182201
expect(response.status).toBe(400);
183202
});
184203

185204
test("invalid Basic Authorization header", async () => {
186-
const response = await SELF.fetch("https://example.com/v1/zls/publish", {
187-
body: null,
188-
method: "POST",
189-
headers: {
190-
Authorization: "Basic :",
205+
const response = await exports.default.fetch(
206+
"https://example.com/v1/zls/publish",
207+
{
208+
body: null,
209+
method: "POST",
210+
headers: {
211+
Authorization: "Basic :",
212+
},
191213
},
192-
});
214+
);
193215
expect(await response.text()).toContain(
194216
"Unexpected Authorization header",
195217
);
196218
expect(response.status).toBe(401);
197219
});
198220

199221
test("wrong username", async () => {
200-
const response = await SELF.fetch("https://example.com/v1/zls/publish", {
201-
body: null,
202-
method: "POST",
203-
headers: {
204-
Authorization: `Basic ${Buffer.from(`wrong:${env.API_TOKEN}`).toString("base64")}`,
222+
const response = await exports.default.fetch(
223+
"https://example.com/v1/zls/publish",
224+
{
225+
body: null,
226+
method: "POST",
227+
headers: {
228+
Authorization: `Basic ${Buffer.from(`wrong:${env.API_TOKEN}`).toString("base64")}`,
229+
},
205230
},
206-
});
231+
);
207232
expect(await response.text()).toBe("Authorization failed");
208233
expect(response.status).toBe(401);
209234
});
210235

211236
test("wrong password", async () => {
212-
const response = await SELF.fetch("https://example.com/v1/zls/publish", {
213-
body: null,
214-
method: "POST",
215-
headers: {
216-
Authorization: `Basic ${Buffer.from("admin:wrong").toString("base64")}`,
237+
const response = await exports.default.fetch(
238+
"https://example.com/v1/zls/publish",
239+
{
240+
body: null,
241+
method: "POST",
242+
headers: {
243+
Authorization: `Basic ${Buffer.from("admin:wrong").toString("base64")}`,
244+
},
217245
},
218-
});
246+
);
219247
expect(await response.text()).toBe("Authorization failed");
220248
expect(response.status).toBe(401);
221249
});
222250
});
223251

224252
describe("validate request body", () => {
225253
test("body is not a json", async () => {
226-
const response = await SELF.fetch("https://example.com/v1/zls/publish", {
227-
body: null,
228-
method: "POST",
229-
headers: {
230-
Authorization: `Basic ${Buffer.from(`admin:${env.API_TOKEN}`).toString("base64")}`,
254+
const response = await exports.default.fetch(
255+
"https://example.com/v1/zls/publish",
256+
{
257+
body: null,
258+
method: "POST",
259+
headers: {
260+
Authorization: `Basic ${Buffer.from(`admin:${env.API_TOKEN}`).toString("base64")}`,
261+
},
231262
},
232-
});
263+
);
233264
expect(await response.text()).toBe(`Unexpected end of JSON input`);
234265
expect(response.status).toBe(400);
235266
});
236267

237268
test("body is not a JSON object", async () => {
238-
const response = await SELF.fetch("https://example.com/v1/zls/publish", {
239-
body: JSON.stringify(5),
240-
method: "POST",
241-
headers: {
242-
"content-type": "application/json;charset=UTF-8",
243-
Authorization: `Basic ${Buffer.from(`admin:${env.API_TOKEN}`).toString("base64")}`,
269+
const response = await exports.default.fetch(
270+
"https://example.com/v1/zls/publish",
271+
{
272+
body: JSON.stringify(5),
273+
method: "POST",
274+
headers: {
275+
"content-type": "application/json;charset=UTF-8",
276+
Authorization: `Basic ${Buffer.from(`admin:${env.API_TOKEN}`).toString("base64")}`,
277+
},
244278
},
245-
});
279+
);
246280
expect(await response.text()).toBe(`request body is not a JSON object!`);
247281
expect(response.status).toBe(400);
248282
});

0 commit comments

Comments
 (0)