@fedify/fedify
Version:
An ActivityPub server framework
42 lines (41 loc) • 1.77 kB
JavaScript
import "@js-temporal/polyfill";
import "urlpattern-polyfill";
globalThis.addEventListener = () => {};
import { a as red, i as buildMessage, l as AssertionError, n as diffStr, r as diff, s as format } from "./assert_equals-Ew3jOFa3.mjs";
//#region ../../node_modules/.pnpm/@jsr+std__assert@0.226.0/node_modules/@jsr/std__assert/assert_strict_equals.js
/**
* Make an assertion that `actual` and `expected` are equal using
* {@linkcode Object.is} for equality comparison. If not, then throw.
*
* @example Usage
* ```ts no-eval
* import { assertStrictEquals } from "@std/assert/assert-strict-equals";
*
* const a = {};
* const b = a;
* assertStrictEquals(a, b); // Doesn't throw
*
* const c = {};
* const d = {};
* assertStrictEquals(c, d); // Throws
* ```
*
* @typeParam T The type of the expected value.
* @param actual The actual value to compare.
* @param expected The expected value to compare.
* @param msg The optional message to display if the assertion fails.
*/ function assertStrictEquals(actual, expected, msg) {
if (Object.is(actual, expected)) return;
const msgSuffix = msg ? `: ${msg}` : ".";
let message;
const actualString = format(actual);
const expectedString = format(expected);
if (actualString === expectedString) message = `Values have the same structure but are not reference-equal${msgSuffix}\n\n${red(actualString.split("\n").map((l) => ` ${l}`).join("\n"))}\n`;
else {
const stringDiff = typeof actual === "string" && typeof expected === "string";
message = `Values are not strictly equal${msgSuffix}\n${buildMessage(stringDiff ? diffStr(actual, expected) : diff(actualString.split("\n"), expectedString.split("\n")), { stringDiff }).join("\n")}`;
}
throw new AssertionError(message);
}
//#endregion
export { assertStrictEquals as t };