From e1e993fff22d154132235197842377e83398d3ef Mon Sep 17 00:00:00 2001 From: Christian Westgaard Date: Fri, 18 Oct 2024 14:46:41 +0200 Subject: [PATCH] Try more awaits --- .../dependencies/initServiceUrlRoot.test.ts | 88 +++++++++---------- 1 file changed, 40 insertions(+), 48 deletions(-) diff --git a/src/deno/lib/enonic/react4xp/dependencies/initServiceUrlRoot.test.ts b/src/deno/lib/enonic/react4xp/dependencies/initServiceUrlRoot.test.ts index e451e354..5e1f999c 100644 --- a/src/deno/lib/enonic/react4xp/dependencies/initServiceUrlRoot.test.ts +++ b/src/deno/lib/enonic/react4xp/dependencies/initServiceUrlRoot.test.ts @@ -6,74 +6,66 @@ declare namespace globalThis { let app: App let log: Log let __: DoubleUnderscore - // let _devMode: boolean let _assetUrl: string - // let _resources: Record } -await Deno.test("handles mode: inline", () => { - globalThis._assetUrl = '/admin/site/inline/default/draft/_/asset/com.enonic.app.react4xp:0000018a9816e580'; - import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts').then(({initServiceUrlRoot}) => { - assertEquals(initServiceUrlRoot(), '/admin/site/inline/default/draft/_/service/com.enonic.app.react4xp/'); - }); +function mockAssetUrl(mode: string) { + return `/admin/site/${mode}/default/draft/_/asset/com.enonic.app.react4xp:0000018a9816e580`; +} + +await Deno.test("handles mode: inline", async () => { + globalThis._assetUrl = mockAssetUrl('inline'); + const {initServiceUrlRoot} = await import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts'); + assertEquals(initServiceUrlRoot(), '/admin/site/inline/default/draft/_/service/com.enonic.app.react4xp/'); }); -await Deno.test("handles mode: inline using type: absolute", () => { - globalThis._assetUrl = '/admin/site/inline/default/draft/_/asset/com.enonic.app.react4xp:0000018a9816e580'; - import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts').then(({initServiceUrlRoot}) => { - assertEquals(initServiceUrlRoot({ - urlType: 'absolute' - }), 'http://localhost:8080/admin/site/inline/default/draft/_/service/com.enonic.app.react4xp/'); - }); +await Deno.test("handles mode: inline using type: absolute", async () => { + globalThis._assetUrl = mockAssetUrl('inline'); + const {initServiceUrlRoot} = await import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts'); + assertEquals(initServiceUrlRoot({ + urlType: 'absolute' + }), 'http://localhost:8080/admin/site/inline/default/draft/_/service/com.enonic.app.react4xp/'); }); -await Deno.test("handles mode: edit", () => { - globalThis._assetUrl = '/admin/site/edit/default/draft/_/asset/com.enonic.app.react4xp:0000018a9816e580'; - import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts').then(({initServiceUrlRoot}) => { - assertEquals(initServiceUrlRoot(), '/admin/site/preview/default/draft/_/service/com.enonic.app.react4xp/'); - }); +await Deno.test("handles mode: edit", async () => { + globalThis._assetUrl = mockAssetUrl('edit'); + const {initServiceUrlRoot} = await import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts'); + assertEquals(initServiceUrlRoot(), '/admin/site/preview/default/draft/_/service/com.enonic.app.react4xp/'); }); -await Deno.test("handles mode: edit type: absolute", () => { - globalThis._assetUrl = '/admin/site/edit/default/draft/_/asset/com.enonic.app.react4xp:0000018a9816e580'; - import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts').then(({initServiceUrlRoot}) => { - assertEquals(initServiceUrlRoot({ - urlType: 'absolute' - }), 'http://localhost:8080/admin/site/preview/default/draft/_/service/com.enonic.app.react4xp/'); - }); +await Deno.test("handles mode: edit type: absolute", async () => { + globalThis._assetUrl = mockAssetUrl('edit'); + const {initServiceUrlRoot} = await import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts'); + assertEquals(initServiceUrlRoot({ + urlType: 'absolute' + }), 'http://localhost:8080/admin/site/preview/default/draft/_/service/com.enonic.app.react4xp/'); }); -await Deno.test("handles mode: preview", () => { - globalThis._assetUrl = '/admin/site/preview/default/draft/_/asset/com.enonic.app.react4xp:0000018a9816e580'; +await Deno.test("handles mode: preview", async () => { + globalThis._assetUrl = mockAssetUrl('preview'); import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts').then(({initServiceUrlRoot}) => { assertEquals(initServiceUrlRoot(), '/admin/site/preview/default/draft/_/service/com.enonic.app.react4xp/'); }); }); -await Deno.test("handles mode: preview type: absolute", () => { - globalThis._assetUrl = '/admin/site/preview/default/draft/_/asset/com.enonic.app.react4xp:0000018a9816e580'; - import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts').then(({initServiceUrlRoot}) => { - assertEquals(initServiceUrlRoot({ - urlType: 'absolute' - }), 'http://localhost:8080/admin/site/preview/default/draft/_/service/com.enonic.app.react4xp/'); - }); +await Deno.test("handles mode: preview type: absolute", async () => { + globalThis._assetUrl = mockAssetUrl('preview'); + const {initServiceUrlRoot} = await import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts'); + assertEquals(initServiceUrlRoot({ + urlType: 'absolute' + }), 'http://localhost:8080/admin/site/preview/default/draft/_/service/com.enonic.app.react4xp/'); }); -await Deno.test("handles mode: live", () => { +await Deno.test("handles mode: live", async () => { globalThis._assetUrl = '/site/default/master/_/asset/com.enonic.app.react4xp:0000018a9816e580'; - import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts').then(({initServiceUrlRoot}) => { - assertEquals(initServiceUrlRoot(), '/site/default/master/_/service/com.enonic.app.react4xp/'); - }); + const {initServiceUrlRoot} = await import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts'); + assertEquals(initServiceUrlRoot(), '/site/default/master/_/service/com.enonic.app.react4xp/'); }); -await Deno.test("handles mode: live type: absolute", () => { +await Deno.test("handles mode: live type: absolute", async () => { globalThis._assetUrl = '/site/default/master/_/asset/com.enonic.app.react4xp:0000018a9816e580'; - import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts').then(({initServiceUrlRoot}) => { - assertEquals(initServiceUrlRoot({ - urlType: 'absolute' - }), 'http://localhost:8080/site/default/master/_/service/com.enonic.app.react4xp/'); - }); + const {initServiceUrlRoot} = await import('../../../../../main/resources/lib/enonic/react4xp/dependencies/initServiceUrlRoot.ts'); + assertEquals(initServiceUrlRoot({ + urlType: 'absolute' + }), 'http://localhost:8080/site/default/master/_/service/com.enonic.app.react4xp/'); });