@fedify/fedify
Version:
An ActivityPub server framework
58 lines (57 loc) • 2.16 kB
JavaScript
import "@js-temporal/polyfill";
import "urlpattern-polyfill";
globalThis.addEventListener = () => {};
import { l as AssertionError } from "./assert_equals-Ew3jOFa3.mjs";
import { n as assertIsError } from "./assert_throws-4NwKEy2q.mjs";
//#region ../../node_modules/.pnpm/@jsr+std__assert@0.226.0/node_modules/@jsr/std__assert/assert_false.js
/**
* Make an assertion, error will be thrown if `expr` have truthy value.
*
* @example Usage
* ```ts no-eval
* import { assertFalse } from "@std/assert/assert-false";
*
* assertFalse(false); // Doesn't throw
* assertFalse(true); // Throws
* ```
*
* @param expr The expression to test.
* @param msg The optional message to display if the assertion fails.
*/ function assertFalse(expr, msg = "") {
if (expr) throw new AssertionError(msg);
}
//#endregion
//#region ../../node_modules/.pnpm/@jsr+std__assert@0.226.0/node_modules/@jsr/std__assert/assert_rejects.js
async function assertRejects(fn, errorClassOrMsg, msgIncludesOrMsg, msg) {
let ErrorClass = void 0;
let msgIncludes = void 0;
let err;
if (typeof errorClassOrMsg !== "string") {
if (errorClassOrMsg === void 0 || errorClassOrMsg.prototype instanceof Error || errorClassOrMsg.prototype === Error.prototype) {
ErrorClass = errorClassOrMsg;
msgIncludes = msgIncludesOrMsg;
}
} else msg = errorClassOrMsg;
let doesThrow = false;
let isPromiseReturned = false;
const msgSuffix = msg ? `: ${msg}` : ".";
try {
const possiblePromise = fn();
if (possiblePromise && typeof possiblePromise === "object" && typeof possiblePromise.then === "function") {
isPromiseReturned = true;
await possiblePromise;
} else throw Error();
} catch (error) {
if (!isPromiseReturned) throw new AssertionError(`Function throws when expected to reject${msgSuffix}`);
if (ErrorClass) {
if (!(error instanceof Error)) throw new AssertionError(`A non-Error object was rejected${msgSuffix}`);
assertIsError(error, ErrorClass, msgIncludes, msg);
}
err = error;
doesThrow = true;
}
if (!doesThrow) throw new AssertionError(`Expected function to reject${msgSuffix}`);
return err;
}
//#endregion
export { assertFalse as n, assertRejects as t };