






















@@ -233,14 +233,19 @@ describe("setActivePluginRegistry", () => {
233233},
234234] as const)("continues cleanup when the $name", async ({ refresh }) => {
235235let releaseFirstCleanup: (() => void) | undefined;
236-let markFirstCleanupStarted!: () => void;
237-let markSecondCleanupCalled!: () => void;
236+let markFirstCleanupStarted: (() => void) | undefined;
237+let markSecondCleanupCalled: (() => void) | undefined;
238238const firstCleanupStarted = new Promise<void>((resolve) => {
239239markFirstCleanupStarted = resolve;
240240});
241241const secondCleanupCalled = new Promise<void>((resolve) => {
242242markSecondCleanupCalled = resolve;
243243});
244+if (!markFirstCleanupStarted || !markSecondCleanupCalled) {
245+throw new Error("Expected cleanup signal callbacks to be initialized");
246+}
247+const notifyFirstCleanupStarted = markFirstCleanupStarted;
248+const notifySecondCleanupCalled = markSecondCleanupCalled;
244249const previous = createEmptyPluginRegistry();
245250previous.plugins.push(
246251createPluginRecord({
@@ -256,7 +261,7 @@ describe("setActivePluginRegistry", () => {
256261lifecycle: {
257262id: "first-cleanup",
258263async cleanup() {
259-markFirstCleanupStarted();
264+notifyFirstCleanupStarted();
260265await new Promise<void>((resolve) => {
261266releaseFirstCleanup = resolve;
262267});
@@ -271,7 +276,7 @@ describe("setActivePluginRegistry", () => {
271276lifecycle: {
272277id: "second-cleanup",
273278cleanup() {
274-markSecondCleanupCalled();
279+notifySecondCleanupCalled();
275280},
276281},
277282source: "/virtual/cleanup-refresh-race/index.ts",
@@ -285,7 +290,10 @@ describe("setActivePluginRegistry", () => {
285290await waitForCleanupSignal(firstCleanupStarted, "first cleanup start");
286291287292refresh(next);
288-releaseFirstCleanup?.();
293+if (!releaseFirstCleanup) {
294+throw new Error("Expected first cleanup release callback to be initialized");
295+}
296+releaseFirstCleanup();
289297290298await waitForCleanupSignal(secondCleanupCalled, "second cleanup");
291299});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。