45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// A tab reloading onto a newer build (lib/staleBuild) renders the chunk it could not load as a render
|
|
// error: the boundary must neither report it as a crash (a fatal notice outlives the reload) nor flash
|
|
// the crash screen before the reload lands. Its own file: staleBuild's "reloading" flag is module state
|
|
// and never turns back off.
|
|
import { afterEach, expect, it, vi } from "vitest";
|
|
import { cleanup, render } from "@testing-library/react";
|
|
|
|
const notify = vi.fn();
|
|
vi.mock("../lib/notifications", () => ({ notify: (...args: unknown[]) => notify(...args) }));
|
|
|
|
import { clear, events } from "../lib/log";
|
|
import { installStaleBuildReload } from "../lib/staleBuild";
|
|
import ErrorBoundary from "./ErrorBoundary";
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
clear();
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("a missing chunk while reloading for a new build is no crash: nothing reported, nothing shown", () => {
|
|
vi.spyOn(console, "error").mockImplementation(() => {}); // React reports the throw itself too
|
|
sessionStorage.clear();
|
|
const reload = vi.fn();
|
|
const uninstall = installStaleBuildReload(reload);
|
|
window.dispatchEvent(new Event("vite:preloadError", { cancelable: true }));
|
|
uninstall();
|
|
expect(reload).toHaveBeenCalledOnce();
|
|
|
|
const Missing = () => {
|
|
throw new Error("Failed to fetch dynamically imported module");
|
|
};
|
|
const { container } = render(
|
|
<ErrorBoundary>
|
|
<Missing />
|
|
</ErrorBoundary>,
|
|
);
|
|
|
|
expect(events().filter((e) => e.event === "ui.crash")).toEqual([]);
|
|
expect(notify).not.toHaveBeenCalled();
|
|
expect(container.innerHTML).toBe("");
|
|
});
|