Browse Source

Retain awaited client cleanup after rebase

turtle1999 1 week ago
parent
commit
39e6e6fb89

+ 2 - 2
packages/test-support/client-runtime/README.i18n.yaml

@@ -2,5 +2,5 @@
 # side as of the last confirmed-consistent state. Both languages carry equal authority;
 # after editing either side, bring the other along and re-record with:
 #   pnpm run verify-translation-pairing --write packages/test-support/client-runtime/README.md
-README.md: e32f7858b32e15e5200f9a986cb88e29309c44cb
-README.zh.md: 1b7da6f38723607dedd5eb16a15ade0b974ed135
+README.md: 20f6454012d0d8e4c78d9a0ea0df960d22a71f5a
+README.zh.md: d9c6888f17df3f37e699bb6be0f7ee44ce82d373

File diff suppressed because it is too large
+ 0 - 0
packages/test-support/client-runtime/README.md


File diff suppressed because it is too large
+ 0 - 0
packages/test-support/client-runtime/README.zh.md


+ 5 - 2
packages/test-support/client-runtime/src/assembly/test-client.ts

@@ -303,11 +303,14 @@ export class TestClient {
   }
 
   /**
-   * Remove one Loader entry.
+   * Remove one Loader entry and wait for its plugin cleanup.
    * @param name - package name of the row.
    */
   async unload(name: string): Promise<void> {
-    await this.ctx.loader.remove(this.entryOf(name).id)
+    const entry = this.entryOf(name)
+    const disposal = entry.fiber?.dispose()
+    this.ctx.loader.remove(entry.id)
+    await disposal
   }
 
   /**

+ 18 - 1
packages/test-support/client-runtime/tests/assembly-test-client.client.spec.ts

@@ -136,7 +136,24 @@ describe('TestClient (jsdom)', () => {
     await client.reload(SIDEBAR)
     await client.flush()
     expect(client.ctx.slots.entries(SIDEBAR_SETTINGS)).toHaveLength(1)
-    await client.unload(SIDEBAR)
+    const cleanupStarted = Promise.withResolvers<undefined>()
+    const releaseCleanup = Promise.withResolvers<undefined>()
+    const sidebar = [...client.ctx.loader.entries()].find(entry => entry.options.name === SIDEBAR)!
+    sidebar.fiber!.ctx.effect(() => async () => {
+      cleanupStarted.resolve(undefined)
+      await releaseCleanup.promise
+    })
+    let unloaded = false
+    const unloading = client.unload(SIDEBAR).then(() => { unloaded = true })
+    try {
+      await cleanupStarted.promise
+      await client.flush()
+      expect(unloaded).toBe(false)
+    } finally {
+      releaseCleanup.resolve(undefined)
+      await unloading
+    }
+    expect(unloaded).toBe(true)
     await client.flush()
     expect(client.ctx.slots.entries(SIDEBAR_SETTINGS)).toHaveLength(0)
     await expect(client.reload(SIDEBAR)).rejects.toThrow(`no Loader entry named ${SIDEBAR}`)

Some files were not shown because too many files changed in this diff