From a89beb0a6245fd7632eae0c772ee4c20f01f5b62 Mon Sep 17 00:00:00 2001 From: KimlikDAO-bot Date: Tue, 7 Jan 2025 13:07:39 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Skip=20tests=20requiring=20auth?= =?UTF-8?q?=20if=20not=20available?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 2 +- kastro/cloudflare/test/workers.test.js | 61 ++++++++++++++------------ kastro/image.js | 8 ++-- kastro/kastro.js | 2 +- kdjs/compile.js | 2 +- kdjs/externs/bun/test.d.js | 8 +++- 6 files changed, 45 insertions(+), 38 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 436ba52..7e5322c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: - uses: oven-sh/setup-bun@v2 - run: | bun i - bun test --timeout 15000 + bun test kdjs_unit_tests_crypto: name: kdjs unit tests, crypto diff --git a/kastro/cloudflare/test/workers.test.js b/kastro/cloudflare/test/workers.test.js index 98672e8..d9bac28 100644 --- a/kastro/cloudflare/test/workers.test.js +++ b/kastro/cloudflare/test/workers.test.js @@ -1,4 +1,4 @@ -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import process from "node:process"; import { bekle as wait } from "../../../util/promises"; import { Auth } from "../api"; @@ -21,38 +21,41 @@ const getAuth = () => { .then((mod) => /** @type {Auth} */({ account: mod["CloudflareAuth"].accountId, apiToken: mod["CloudflareAuth"].token, - })); + })) + .catch(() => /** @type {Auth} */({ account: "", apiToken: "" })); } -test("upload, fetch and delete worker", async () => { - /** @const {Auth} */ +describe("Tests with Cloudflare auth", async () => { const auth = await getAuth(); - /** @const {string} */ - const name = `test-worker-${Math.floor(1000 + Math.random() * 9000)}`; - /** @const {string} */ - const code = `export default {fetch(){return new Response("${name}",{headers:{"content-type":"text/plain"}})}}`; - const uploadResult = await workers.upload(auth, name, code); - expect(uploadResult.success).toBeTrue(); + test.if(!!auth.account)("upload, fetch and delete worker", async () => { + /** @const {string} */ + const name = `test-worker-${Math.floor(1000 + Math.random() * 9000)}`; + /** @const {string} */ + const code = `export default {fetch(){return new Response("${name}",{headers:{"content-type":"text/plain"}})}}`; + + const uploadResult = await workers.upload(auth, name, code); + expect(uploadResult.success).toBeTrue(); - const workersDevResult = await workers.enableWorkersDev(auth, name); - expect(workersDevResult.success).toBeTrue(); + const workersDevResult = await workers.enableWorkersDev(auth, name); + expect(workersDevResult.success).toBeTrue(); - const maxAttempts = 5; - let attempt = 0; - for (; attempt < maxAttempts; ++attempt) { - await wait(5000); - try { - const fetchResult = await fetch(`https://${name}.kimlikdao-testing.workers.dev`); - if (fetchResult.status == 200) { - const text = await fetchResult.text(); - expect(text).toBe(name); - break; - } - } catch (_) { } - } - await workers.delete(auth, name); - expect(attempt).toBeLessThan(maxAttempts); -}, { - timeout: 15_000 + const maxAttempts = 5; + let attempt = 0; + for (; attempt < maxAttempts; ++attempt) { + await wait(5000); + try { + const fetchResult = await fetch(`https://${name}.kimlikdao-testing.workers.dev`); + if (fetchResult.status == 200) { + const text = await fetchResult.text(); + expect(text).toBe(name); + break; + } + } catch (_) { } + } + await workers.delete(auth, name); + expect(attempt).toBeLessThan(maxAttempts); + }, { + timeout: 15_000 + }); }); diff --git a/kastro/image.js b/kastro/image.js index f7c16c9..8d066cf 100644 --- a/kastro/image.js +++ b/kastro/image.js @@ -104,11 +104,9 @@ const Favicon = ({ src, raster, BuildMode, ...props }) => { * @return {!Promise} */ const Image = ({ inline, ...props }) => { - if (inline) { - if (props.src.endsWith(".svg") || props.src.endsWith(".svg.jsx")) - return InlineSvgImage(props); - throw new Error("We only inline svgs; for other formats serving directly is more efficient"); - } + if (inline && (props.src.endsWith(".svg") || props.src.endsWith(".svg.jsx"))) + return InlineSvgImage(props); + if (props.rel == "icon") return Favicon(props); diff --git a/kastro/kastro.js b/kastro/kastro.js index 97de8fb..76462c0 100644 --- a/kastro/kastro.js +++ b/kastro/kastro.js @@ -153,7 +153,7 @@ const serveCrate = async (crateName, buildMode) => { if (id.endsWith(".jsx")) { const lines = code.split("\n"); const filteredLines = lines.filter((line) => line.includes("util/dom") || - line.trim().startsWith("export const")); + line.trim().startsWith("export const") || (line.includes("import") && line.includes('.css"'))); return filteredLines.join("\n"); } const globals = getGlobals(); diff --git a/kdjs/compile.js b/kdjs/compile.js index 7f99de0..0305291 100644 --- a/kdjs/compile.js +++ b/kdjs/compile.js @@ -67,10 +67,10 @@ const compile = async (params, checkFreshFn) => { "jscomp_error": jsCompErrors, "jscomp_warning": jsCompWarnings, "language_in": "UNSTABLE", + "chunk_output_type": "ES_MODULES", "module_resolution": "NODE", "dependency_mode": "PRUNE", "entry_point": /** @type {string} */(params["entry"]), - "chunk_output_type": "ES_MODULES" }; if (params["define"]) options["define"] = /** @type {(!Array|boolean|string)} */(params["define"]); diff --git a/kdjs/externs/bun/test.d.js b/kdjs/externs/bun/test.d.js index 9798221..7306564 100644 --- a/kdjs/externs/bun/test.d.js +++ b/kdjs/externs/bun/test.d.js @@ -11,7 +11,7 @@ const TestOptions = {}; /** * @param {string} description - * @param {function():void} run + * @param {function():(!Promise<*>|void)} run */ const describe = function (description, run) { }; @@ -29,6 +29,12 @@ const it = function (invariant, run, testOptions) { }; */ const test = function (invariant, run, testOptions) { }; +/** + * @param {boolean} condition + * @return {function(string,(function():void|function():!Promise),TestOptions=):void} + */ +test.if = function (condition) { } + /** * @template T * @template MATCHER := cond(isTemplatized(T) && sub(rawTypeOf(T), 'IThenable'),