Skip to content

Commit d944e13

Browse files
authored
Merge pull request #386 from dajiaji/refine-test
Refine test to add test:cloudflare to deno task.
2 parents d3474e8 + b08bcd6 commit d944e13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+14772
-1047
lines changed

.github/workflows/ci_cloudflare.yml

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,68 +20,7 @@ jobs:
2020
- uses: actions/setup-node@v4
2121
with:
2222
node-version: v20.x
23-
- name: Install esbuild
24-
run: npm install -g esbuild
2523
- name: Prepare test
2624
run: deno task npm
27-
- name: Run test for ./packages/core
28-
working-directory: ./packages/core/test/runtimes/cloudflare
29-
run: |
30-
npm install
31-
npm link @hpke/core
32-
nohup npm start &
33-
sleep 3
34-
deno test --import-map=../../../../../import_map.json core.spec.ts --allow-net --config ../../../deno.json
35-
- name: Run test for ./packages/chacha20poly1305
36-
working-directory: ./packages/chacha20poly1305/test/runtimes/cloudflare
37-
run: |
38-
npm install
39-
npm link @hpke/core
40-
npm link @hpke/chacha20poly1305
41-
nohup npm start &
42-
sleep 3
43-
deno test --import-map=../../../../../import_map.json chacha20poly1305.spec.ts --allow-net --config ../../../deno.json
44-
- name: Run test for ./packages/dhkem-x25519
45-
working-directory: ./packages/dhkem-x25519/test/runtimes/cloudflare
46-
run: |
47-
npm install
48-
npm link @hpke/core
49-
npm link @hpke/dhkem-x25519
50-
nohup npm start &
51-
sleep 3
52-
deno test --import-map=../../../../../import_map.json dhkem-x25519.spec.ts --allow-net --config ../../../deno.json
53-
- name: Run test for ./packages/dhkem-x448
54-
working-directory: ./packages/dhkem-x448/test/runtimes/cloudflare
55-
run: |
56-
npm install
57-
npm link @hpke/core
58-
npm link @hpke/dhkem-x448
59-
nohup npm start &
60-
sleep 3
61-
deno test --import-map=../../../../../import_map.json dhkem-x448.spec.ts --allow-net --config ../../../deno.json
62-
- name: Run test for ./packages/dhkem-secp256k1
63-
working-directory: ./packages/dhkem-secp256k1/test/runtimes/cloudflare
64-
run: |
65-
npm install
66-
npm link @hpke/core
67-
npm link @hpke/dhkem-secp256k1
68-
nohup npm start &
69-
sleep 3
70-
deno test --import-map=../../../../../import_map.json dhkem-secp256k1.spec.ts --allow-net --config ../../../deno.json
71-
- name: Run test for ./packages/hybridkem-x25519-kyber768
72-
working-directory: ./packages/hybridkem-x25519-kyber768/test/runtimes/cloudflare
73-
run: |
74-
npm install
75-
npm link @hpke/core
76-
npm link @hpke/hybridkem-x25519-kyber768
77-
nohup npm start &
78-
sleep 3
79-
deno test --import-map=../../../../../import_map.json hybridkem-x25519-kyber768.spec.ts --allow-net --config ../../../deno.json
80-
- name: Run test for ./packages/hpke-js
81-
working-directory: ./packages/hpke-js/test/runtimes/cloudflare
82-
run: |
83-
npm install
84-
npm link hpke-js
85-
nohup npm start &
86-
sleep 3
87-
deno test --import-map=../../../../../import_map.json hpke.spec.ts --allow-net --config ../../../deno.json
25+
- name: Run test
26+
run: deno task test:cloudflare

deno.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"npm/",
2121
"**/*/*.js",
2222
"**/*/npm/",
23+
"**/*/.wrangler/",
2324
"coverage/*.json"
2425
]
2526
},
@@ -28,6 +29,7 @@
2829
"npm/",
2930
"**/*/*.js",
3031
"**/*/npm/",
32+
"**/*/.wrangler/",
3133
"coverage/*.json"
3234
]
3335
},
@@ -36,11 +38,27 @@
3638
"npm/",
3739
"**/*/*.js",
3840
"**/*/npm/",
41+
"**/*/.wrangler/",
3942
"coverage/*.json"
4043
]
4144
},
4245
"tasks": {
4346
"test": "deno fmt && deno lint && deno test --import-map=./import_map.json -A --fail-fast --doc --coverage=coverage --parallel --allow-read",
47+
"test:core": "cd packages/core && deno task test",
48+
"test:chacha20poly1305": "cd packages/chacha20poly1305 && deno task test",
49+
"test:dhkem-x25519": "cd packages/dhkem-x25519 && deno task test",
50+
"test:dhkem-x448": "cd packages/dhkem-x448 && deno task test",
51+
"test:dhkem-secp256k1": "cd packages/dhkem-secp256k1 && deno task test",
52+
"test:hybridkem-x25519-kyber768": "cd packages/hybridkem-x25519-kyber768 && deno task test",
53+
"test:hpke-js": "cd packages/hpke-js && deno task test",
54+
"test:cloudflare": "deno task test:cloudflare:core && deno task test:cloudflare:chacha20poly1305 && deno task test:cloudflare:dhkem-x25519 && deno task test:cloudflare:dhkem-x448 && deno task test:cloudflare:dhkem-secp256k1 && deno task test:cloudflare:hybridkem-x25519-kyber768 && deno task test:cloudflare:hpke-js",
55+
"test:cloudflare:core": "cd packages/core && deno task test:cloudflare",
56+
"test:cloudflare:chacha20poly1305": "cd packages/chacha20poly1305 && deno task test:cloudflare",
57+
"test:cloudflare:dhkem-x25519": "cd packages/dhkem-x25519 && deno task test:cloudflare",
58+
"test:cloudflare:dhkem-x448": "cd packages/dhkem-x448 && deno task test:cloudflare",
59+
"test:cloudflare:dhkem-secp256k1": "cd packages/dhkem-secp256k1 && deno task test:cloudflare",
60+
"test:cloudflare:hybridkem-x25519-kyber768": "cd packages/hybridkem-x25519-kyber768 && deno task test:cloudflare",
61+
"test:cloudflare:hpke-js": "cd packages/hpke-js && deno task test:cloudflare",
4462
"cov": "deno coverage ./coverage --lcov --exclude='test'",
4563
"dnt": "deno task dnt:core && deno task dnt:chacha20poly1305 && deno task dnt:dhkem-x25519 && deno task dnt:dhkem-x448 && deno task dnt:dhkem-secp256k1 && deno task dnt:hybridkem-x25519-kyber768 && deno task dnt:hpke-js",
4664
"npm": "deno task dnt && deno task npm-link && deno task npm-pack",

packages/chacha20poly1305/deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
},
4848
"tasks": {
4949
"test": "deno fmt && deno lint && deno test --import-map=../../import_map.json -A --fail-fast --doc --coverage=coverage --parallel --allow-read",
50+
"test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link @hpke/core @hpke/chacha20poly1305 && npm run test",
5051
"cov": "deno coverage ./coverage --lcov --exclude='test'",
5152
"dnt": "deno run --import-map=../../import_map.json -A dnt.ts",
5253
"minify": "esbuild ../../npm/packages/chacha20poly1305/esm/chacha20poly1305/mod.js --bundle --format=esm --minify"

packages/chacha20poly1305/test/runtimes/cloudflare/chacha20poly1305.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import { assertEquals } from "@std/assert";
2-
import { describe, it } from "@std/testing/bdd";
1+
import { SELF } from "cloudflare:test";
2+
import { describe, expect, it } from "vitest";
33

44
describe("Cloudflare Workers", () => {
55
describe("GET /test", () => {
66
it("should return ok", async () => {
77
for (const kem of ["0x0010", "0x0011", "0x0012"]) {
88
for (const kdf of ["0x0001", "0x0002", "0x0003"]) {
9-
const res = await fetch(
10-
`http://localhost:8792/test?kem=${kem}&kdf=${kdf}`,
9+
const res = await SELF.fetch(
10+
`https://example.com/test?kem=${kem}&kdf=${kdf}`,
1111
);
12-
assertEquals("ok", await res.text());
12+
expect(res.status).toBe(200);
13+
expect(await res.text()).toBe("ok");
1314
}
1415
}
1516
});

0 commit comments

Comments
 (0)