@virtualstate/app-history
Version:
Native JavaScript [app-history](https://github.com/WICG/app-history) implementation
71 lines (63 loc) • 2.15 kB
text/typescript
/* c8 ignore start */
// import {run, dispatchEvent, addEventListener} from "@opennetwork/environment";
import process from "./node-process";
import {getConfig} from "./config";
console.log("====== START NEW SET OF TESTS ======");
if (typeof process !== "undefined") {
process.on("uncaughtException", (...args: unknown[]) => {
console.log("process uncaught exception", ...args);
process.exit(1);
});
process.on("unhandledRejection", (...args: unknown[]) => {
console.log("process unhandled rejection", ...args);
process.exit(1);
});
process.on("error", (...args: unknown[]) => {
console.log("process error", ...args);
process.exit(1);
});
}
async function runTests() {
await import("./app-history.class");
if (typeof window === "undefined" && typeof process !== "undefined") {
await import("./app-history.imported");
if (getConfig().FLAGS?.includes("WEB_PLATFORM_TESTS")) {
await import("./app-history.playwright.wpt");
}
if (getConfig().FLAGS?.includes("PLAYWRIGHT")) {
await import("./app-history.playwright");
}
}
else {
await import("./app-history.scope");
}
}
if (typeof window === "undefined") {
console.log("Running tests within shell");
} else {
if (sessionStorage.testsRanInThisWindow) {
throw new Error("Tests already ran in this window, network navigation caused");
}
sessionStorage.setItem("testsRanInThisWindow", "1");
console.log("Running tests within window");
}
let exitCode = 0,
caught = undefined;
try {
await runTests();
} catch (error) {
caught = error;
exitCode = 1;
console.error("Caught test error!");
if (typeof window === "undefined" && typeof process !== "undefined") {
console.error(caught);
} else {
throw await Promise.reject(caught);
}
}
// Settle tests, allow for the above handlers to fire if they need to
await new Promise(resolve => setTimeout(resolve, 200));
if (typeof process !== "undefined" && exitCode) {
process.exit(exitCode);
}
export default exitCode;