From 969d6d8819498ffe95ba797c414ffabcb4810358 Mon Sep 17 00:00:00 2001 From: Hossein Mohammadi Date: Mon, 30 Sep 2024 15:37:04 +0330 Subject: [PATCH] test: combine prefetchScript with loadScript --- .../ScriptManager/__tests__/Federated.test.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/repack/src/modules/ScriptManager/__tests__/Federated.test.ts b/packages/repack/src/modules/ScriptManager/__tests__/Federated.test.ts index a8dbc037e..41fe04dea 100644 --- a/packages/repack/src/modules/ScriptManager/__tests__/Federated.test.ts +++ b/packages/repack/src/modules/ScriptManager/__tests__/Federated.test.ts @@ -119,4 +119,27 @@ describe('Federated', () => { await ScriptManager.shared.loadScript('miniApp2'); expect(loadingScript2IsFinished).toEqual(true); }); + + it('should wait loadScript and prefetchScript', async () => { + const cache = new FakeCache(); + ScriptManager.shared.setStorage(cache); + + ScriptManager.shared.addResolver(async (scriptId, caller) => { + return { + url: Script.getRemoteURL(scriptId), + cache: true, + }; + }); + + let prefetchScriptIsFinished = false; + + // loadScript should wait first time called loadScript although we are not awaited, because scriptId is same + ScriptManager.shared + .prefetchScript('miniApp') + .then(() => (prefetchScriptIsFinished = true)); + + await ScriptManager.shared.loadScript('miniApp'); + + expect(prefetchScriptIsFinished).toEqual(true); + }); });