Skip to content

Commit

Permalink
🚧 Skip tests requiring auth if not available
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Jan 7, 2025
1 parent c33a93c commit 5c3038e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 37 deletions.
61 changes: 32 additions & 29 deletions kastro/cloudflare/test/workers.test.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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
});
});
8 changes: 3 additions & 5 deletions kastro/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ const Favicon = ({ src, raster, BuildMode, ...props }) => {
* @return {!Promise<string>}
*/
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);

Expand Down
2 changes: 1 addition & 1 deletion kastro/kastro.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion kdjs/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>|boolean|string)} */(params["define"]);
Expand Down
8 changes: 7 additions & 1 deletion kdjs/externs/bun/test.d.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const TestOptions = {};

/**
* @param {string} description
* @param {function():void} run
* @param {function():(!Promise<*>|void)} run
*/
const describe = function (description, run) { };

Expand All @@ -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<void>),TestOptions=):void}
*/
test.if = function (condition) { }

/**
* @template T
* @template MATCHER := cond(isTemplatized(T) && sub(rawTypeOf(T), 'IThenable'),
Expand Down

0 comments on commit 5c3038e

Please sign in to comment.