Skip to content

Commit

Permalink
Merge pull request #36 from dajiaji/fix-cloudflare-test
Browse files Browse the repository at this point in the history
Fix test for cloudflare workers.
  • Loading branch information
dajiaji authored Sep 14, 2024
2 parents a2b494d + 74dcc9c commit e6a1a82
Show file tree
Hide file tree
Showing 14 changed files with 3,673 additions and 41 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/ci_cloudflare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: v20.x
- run: |
npm install -g esbuild
deno task dnt
deno task minify > test/runtimes/crystals-kyber.js
- name: Prepare test
run: deno task npm
- name: Run test
working-directory: ./test/runtimes/cloudflare
run: |
npm install
nohup npm start &
sleep 3
deno test crystals-kyber.spec.ts --allow-net
run: deno task test:cloudflare
13 changes: 10 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "@dajiaji/crystals-kyber-js",
"version": "1.1.1",
"exports": "./mod.ts",
"imports": {
"testing/": "https://deno.land/[email protected]/testing/",
"dnt": "https://deno.land/x/dnt@0.39.0/mod.ts"
"@deno/dnt": "jsr:@deno/dnt@^0.41.3",
"testing/": "https://deno.land/std@0.213.0/testing/"
},
"fmt": {
"include": [
Expand All @@ -25,8 +28,12 @@
},
"tasks": {
"test": "deno fmt && deno lint && deno test test -A --fail-fast --doc --coverage=coverage --parallel --allow-read",
"test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link crystals-kyber-js && npm run test",
"cov": "deno coverage ./coverage --lcov --exclude='test'",
"dnt": "deno run -A dnt.ts $(git describe --tags $(git rev-list --tags --max-count=1))",
"npm": "deno task dnt && deno task npm-link && deno task npm-pack",
"dnt": "deno run -A dnt.ts",
"npm-link": "cd npm && npm link",
"npm-pack": "cd npm && npm pack --dry-run",
"minify": "esbuild npm/esm/mod.js --bundle --format=esm --minify"
}
}
117 changes: 117 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions dnt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { build, emptyDir } from "dnt";
import { build, emptyDir } from "@deno/dnt";

await emptyDir("./npm");
await emptyDir("test/runtimes/browsers/node_modules");
await emptyDir("test/runtimes/bun/node_modules");
await emptyDir("test/runtimes/cloudflare/node_modules");

const denoPkg = JSON.parse(await Deno.readTextFile("./deno.json"));

await build({
entryPoints: ["./mod.ts"],
Expand All @@ -18,7 +23,7 @@ await build({
},
package: {
name: "crystals-kyber-js",
version: Deno.args[0],
version: denoPkg.version,
description:
"A CRYSTALS-KYBER implementation written in TypeScript for various JavaScript runtimes",
repository: {
Expand Down
3 changes: 2 additions & 1 deletion test/runtimes/browsers/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// playwright.config.ts
import { devices, PlaywrightTestConfig } from "@playwright/test";
import type { PlaywrightTestConfig } from "@playwright/test";
import { devices } from "@playwright/test";

const config: PlaywrightTestConfig = {
projects: [
Expand Down
19 changes: 11 additions & 8 deletions test/runtimes/cloudflare/crystals-kyber.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import { assertEquals } from "testing/asserts.ts";
import { describe, it } from "testing/bdd.ts";
import { SELF } from "cloudflare:test";
import { describe, expect, it } from "vitest";

describe("Cloudflare Workers", () => {
describe("GET /kyber512", () => {
it("should return ok", async () => {
const res = await fetch("http://localhost:8787/kyber512");
assertEquals("ok", await res.text());
const res = await SELF.fetch("https://example.com/kyber512");
expect(res.status).toBe(200);
expect(await res.text()).toBe("ok");
});
});

describe("GET /kyber768", () => {
it("should return ok", async () => {
const res = await fetch("http://localhost:8787/kyber768");
assertEquals("ok", await res.text());
const res = await SELF.fetch("https://example.com/kyber768");
expect(res.status).toBe(200);
expect(await res.text()).toBe("ok");
});
});

describe("GET /kyber1024", () => {
it("should return ok", async () => {
const res = await fetch("http://localhost:8787/kyber1024");
assertEquals("ok", await res.text());
const res = await SELF.fetch("https://example.com/kyber1024");
expect(res.status).toBe(200);
expect(await res.text()).toBe("ok");
});
});
});
Loading

0 comments on commit e6a1a82

Please sign in to comment.