mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-30 21:01:54 +08:00
Fix overlay warning
This commit is contained in:
parent
d57bba3a06
commit
6883d83ad1
@ -0,0 +1,72 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { envVars } from "../generated/env";
|
||||
import { StackClientApp } from "../lib/hexclave-app";
|
||||
import { mountPushedConfigErrorOverlay } from ".";
|
||||
|
||||
function createMockElement() {
|
||||
return {
|
||||
style: {},
|
||||
appendChild: () => {},
|
||||
addEventListener: () => {},
|
||||
setAttribute: () => {},
|
||||
replaceChildren: () => {},
|
||||
remove: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
describe("pushed config error overlay", () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("defers the first project refresh until after construction-time callers finish", async () => {
|
||||
const app = new StackClientApp({
|
||||
baseUrl: "http://localhost:12345",
|
||||
projectId: "00000000-0000-4000-8000-000000000000",
|
||||
publishableClientKey: "stack-pk-test",
|
||||
tokenStore: "memory",
|
||||
redirectMethod: "none",
|
||||
devTool: false,
|
||||
});
|
||||
const getProject = vi.fn(async () => ({
|
||||
pushedConfigError: null,
|
||||
configWarnings: [],
|
||||
}));
|
||||
Reflect.set(app, "getProject", getProject);
|
||||
const appendChild = vi.fn();
|
||||
vi.stubEnv("NODE_ENV", "development");
|
||||
expect(Reflect.get(envVars, "NODE_ENV")).toBe("development");
|
||||
|
||||
vi.stubGlobal("window", {
|
||||
"__hexclave-pushed-config-error-overlay": null,
|
||||
location: {
|
||||
href: "http://localhost:3000",
|
||||
},
|
||||
});
|
||||
vi.stubGlobal("document", {
|
||||
body: {
|
||||
appendChild,
|
||||
},
|
||||
createElement: () => createMockElement(),
|
||||
createTextNode: () => createMockElement(),
|
||||
});
|
||||
vi.stubGlobal("localStorage", {
|
||||
getItem: () => null,
|
||||
setItem: () => {},
|
||||
removeItem: () => {},
|
||||
});
|
||||
|
||||
const cleanup = mountPushedConfigErrorOverlay(app);
|
||||
try {
|
||||
expect(appendChild).toHaveBeenCalledOnce();
|
||||
expect(getProject).not.toHaveBeenCalled();
|
||||
|
||||
await Promise.resolve();
|
||||
|
||||
expect(getProject).toHaveBeenCalledOnce();
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -528,7 +528,10 @@ export function mountPushedConfigErrorOverlay(app: StackClientApp<true>): () =>
|
||||
});
|
||||
};
|
||||
|
||||
refresh();
|
||||
// This is mounted from the base client-app constructor, which also runs
|
||||
// before subclass field initializers. Defer the first app call so overridden
|
||||
// methods like adminApp.getProject() can safely touch subclass caches.
|
||||
queueMicrotask(refresh);
|
||||
const interval = setInterval(refresh, REFRESH_INTERVAL_MS);
|
||||
|
||||
const cleanup = () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user