Skip to content

Commit fc595a7

Browse files
committed
Make bun test use JSR.
1 parent 5c75011 commit fc595a7

File tree

9 files changed

+259
-20
lines changed

9 files changed

+259
-20
lines changed

.github/workflows/ci_bun.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,20 @@ jobs:
4949
- working-directory: ./core
5050
run: |
5151
deno task dnt
52-
deno task minify > test/runtimes/hpke-core.js
52+
deno run -A dnt.ts 0.0.0
5353
deno task minify > ../x/dhkem-x25519/test/runtimes/hpke-core.js
5454
deno task minify > ../x/dhkem-x448/test/runtimes/hpke-core.js
5555
deno task minify > ../x/chacha20poly1305/test/runtimes/hpke-core.js
5656
deno task minify > ../x/hybridkem-x25519-kyber768/test/runtimes/hpke-core.js
5757
deno task minify > ../x/dhkem-secp256k1/test/runtimes/hpke-core.js
58+
- name: Run npm pack for core
59+
working-directory: ./core/npm
60+
run: npm pack
5861
- name: Run test for core
5962
working-directory: ./core/test/runtimes/bun
6063
run: |
61-
nohup bun src/index.js &
64+
bun install
65+
nohup bun src/index.ts &
6266
sleep 3
6367
deno test core.spec.ts --allow-net
6468
- working-directory: ./x/dhkem-x25519

core/test/runtimes/bun/.gitignore

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
2+
3+
# Logs
4+
5+
logs
6+
_.log
7+
npm-debug.log_
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
.pnpm-debug.log*
12+
13+
# Caches
14+
15+
.cache
16+
17+
# Diagnostic reports (https://nodejs.org/api/report.html)
18+
19+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
20+
21+
# Runtime data
22+
23+
pids
24+
_.pid
25+
_.seed
26+
*.pid.lock
27+
28+
# Directory for instrumented libs generated by jscoverage/JSCover
29+
30+
lib-cov
31+
32+
# Coverage directory used by tools like istanbul
33+
34+
coverage
35+
*.lcov
36+
37+
# nyc test coverage
38+
39+
.nyc_output
40+
41+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
42+
43+
.grunt
44+
45+
# Bower dependency directory (https://bower.io/)
46+
47+
bower_components
48+
49+
# node-waf configuration
50+
51+
.lock-wscript
52+
53+
# Compiled binary addons (https://nodejs.org/api/addons.html)
54+
55+
build/Release
56+
57+
# Dependency directories
58+
59+
node_modules/
60+
jspm_packages/
61+
62+
# Snowpack dependency directory (https://snowpack.dev/)
63+
64+
web_modules/
65+
66+
# TypeScript cache
67+
68+
*.tsbuildinfo
69+
70+
# Optional npm cache directory
71+
72+
.npm
73+
74+
# Optional eslint cache
75+
76+
.eslintcache
77+
78+
# Optional stylelint cache
79+
80+
.stylelintcache
81+
82+
# Microbundle cache
83+
84+
.rpt2_cache/
85+
.rts2_cache_cjs/
86+
.rts2_cache_es/
87+
.rts2_cache_umd/
88+
89+
# Optional REPL history
90+
91+
.node_repl_history
92+
93+
# Output of 'npm pack'
94+
95+
*.tgz
96+
97+
# Yarn Integrity file
98+
99+
.yarn-integrity
100+
101+
# dotenv environment variable files
102+
103+
.env
104+
.env.development.local
105+
.env.test.local
106+
.env.production.local
107+
.env.local
108+
109+
# parcel-bundler cache (https://parceljs.org/)
110+
111+
.parcel-cache
112+
113+
# Next.js build output
114+
115+
.next
116+
out
117+
118+
# Nuxt.js build / generate output
119+
120+
.nuxt
121+
dist
122+
123+
# Gatsby files
124+
125+
# Comment in the public line in if your project uses Gatsby and not Next.js
126+
127+
# https://nextjs.org/blog/next-9-1#public-directory-support
128+
129+
# public
130+
131+
# vuepress build output
132+
133+
.vuepress/dist
134+
135+
# vuepress v2.x temp and cache directory
136+
137+
.temp
138+
139+
# Docusaurus cache and generated files
140+
141+
.docusaurus
142+
143+
# Serverless directories
144+
145+
.serverless/
146+
147+
# FuseBox cache
148+
149+
.fusebox/
150+
151+
# DynamoDB Local files
152+
153+
.dynamodb/
154+
155+
# TernJS port file
156+
157+
.tern-port
158+
159+
# Stores VSCode versions used for testing VSCode extensions
160+
161+
.vscode-test
162+
163+
# yarn v2
164+
165+
.yarn/cache
166+
.yarn/unplugged
167+
.yarn/build-state.yml
168+
.yarn/install-state.gz
169+
.pnp.*
170+
171+
# IntelliJ based IDEs
172+
.idea
173+
174+
# Finder (MacOS) folder config
175+
.DS_Store

core/test/runtimes/bun/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# bunx
2+
3+
To install dependencies:
4+
5+
```bash
6+
bun install
7+
```
8+
9+
To run:
10+
11+
```bash
12+
bun run index.ts
13+
```
14+
15+
This project was created using `bun init` in bun v1.1.22. [Bun](https://bun.sh)
16+
is a fast all-in-one JavaScript runtime.

core/test/runtimes/bun/bun.lockb

3.41 KB
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "bun",
3+
"module": "src/index.ts",
4+
"type": "module",
5+
"devDependencies": {
6+
"@types/bun": "latest"
7+
},
8+
"peerDependencies": {
9+
"typescript": "^5.0.0"
10+
},
11+
"dependencies": {
12+
"@hpke/core": "file:../../../npm/hpke-core-0.0.0.tgz"
13+
}
14+
}

core/test/runtimes/bun/src/index.js

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { testServer } from "./server.ts";
2+
3+
export default {
4+
port: 3002,
5+
async fetch(request: Request): Promise<Response> {
6+
return await testServer(request);
7+
},
8+
};

core/test/runtimes/server.js renamed to core/test/runtimes/bun/src/server.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import {
1+
import type {
22
AeadId,
3+
KdfId,
4+
KemId,
5+
} from "@hpke/core";
6+
7+
import {
38
Aes128Gcm,
49
Aes256Gcm,
510
CipherSuite,
@@ -10,11 +15,9 @@ import {
1015
HkdfSha256,
1116
HkdfSha384,
1217
HkdfSha512,
13-
KdfId,
14-
KemId,
15-
} from "./hpke-core.js";
18+
} from "@hpke/core";
1619

17-
function createKem(id) {
20+
function createKem(id: KemId) {
1821
switch (id) {
1922
case KemId.DhkemP256HkdfSha256:
2023
return new DhkemP256HkdfSha256();
@@ -28,7 +31,7 @@ function createKem(id) {
2831
throw new Error("ng: invalid kem");
2932
}
3033

31-
function createKdf(id) {
34+
function createKdf(id: KdfId) {
3235
switch (id) {
3336
case KdfId.HkdfSha256:
3437
return new HkdfSha256();
@@ -42,7 +45,7 @@ function createKdf(id) {
4245
throw new Error("ng: invalid kdf");
4346
}
4447

45-
function createAead(id) {
48+
function createAead(id: AeadId) {
4649
switch (id) {
4750
case AeadId.Aes128Gcm:
4851
return new Aes128Gcm();
@@ -58,7 +61,7 @@ function createAead(id) {
5861
throw new Error("ng: invalid aead");
5962
}
6063

61-
export async function testServer(request) {
64+
export async function testServer(request: Request): Promise<Response> {
6265
const url = new URL(request.url);
6366
if (url.pathname !== "/test") {
6467
return new Response("ng: invalid path");
@@ -95,8 +98,8 @@ export async function testServer(request) {
9598
if ("hello world!" !== new TextDecoder().decode(pt)) {
9699
return new Response("ng");
97100
}
98-
} catch (e) {
99-
return new Response("ng: " + e.message);
101+
} catch (e: unknown) {
102+
return new Response("ng: " + (e as Error).message);
100103
}
101104
return new Response("ok");
102105
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"compilerOptions": {
3+
// Enable latest features
4+
"lib": ["ESNext", "DOM"],
5+
"target": "ESNext",
6+
"module": "ESNext",
7+
"moduleDetection": "force",
8+
"jsx": "react-jsx",
9+
"allowJs": true,
10+
11+
// Bundler mode
12+
"moduleResolution": "bundler",
13+
"allowImportingTsExtensions": true,
14+
"verbatimModuleSyntax": true,
15+
"noEmit": true,
16+
17+
// Best practices
18+
"strict": true,
19+
"skipLibCheck": true,
20+
"noFallthroughCasesInSwitch": true,
21+
22+
// Some stricter flags (disabled by default)
23+
"noUnusedLocals": false,
24+
"noUnusedParameters": false,
25+
"noPropertyAccessFromIndexSignature": false
26+
}
27+
}

0 commit comments

Comments
 (0)