From 15bf6e55fea0f27a84cb69d2de832f6889aeae9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=A4nisch?= Date: Fri, 17 May 2019 01:41:56 +0200 Subject: [PATCH] fix(context): resolve publicPath (#1536) --- src/runtime/context.ts | 2 +- src/runtime/test/context.spec.tsx | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/runtime/context.ts b/src/runtime/context.ts index f8292857f5b..f25fd3189fa 100644 --- a/src/runtime/context.ts +++ b/src/runtime/context.ts @@ -11,7 +11,7 @@ export const getContext = (_elm: HTMLElement, context: string) => { return doc; } else if (context === 'isServer') { return BUILD.hydrateServerSide; - } else if (context === 'resourcesUrl') { + } else if (context === 'resourcesUrl' || context === 'publicPath') { return getAssetPath('.'); } else if (context === 'queue') { return { diff --git a/src/runtime/test/context.spec.tsx b/src/runtime/test/context.spec.tsx index 5078dfaaf9b..1bfbb53db5c 100644 --- a/src/runtime/test/context.spec.tsx +++ b/src/runtime/test/context.spec.tsx @@ -14,6 +14,7 @@ describe('context', () => { @Prop({ context: 'document' }) doc: Document; @Prop({ context: 'isServer' }) isServer: boolean; @Prop({ context: 'resourcesUrl' }) resourcesUrl: string; + @Prop({ context: 'publicPath' }) publicPath: string; @Prop({ context: 'queue' }) queue: QueueApi; } const {win, doc, rootInstance} = await newSpecPage({ @@ -24,6 +25,7 @@ describe('context', () => { expect(rootInstance.win).toEqual(win); expect(rootInstance.doc).toEqual(doc); expect(rootInstance.resourcesUrl).toEqual('/'); + expect(rootInstance.publicPath).toEqual('/'); expect(rootInstance.queue.write).toEqual(writeTask); expect(rootInstance.queue.read).toEqual(readTask); expect(rootInstance.queue.tick).not.toBeUndefined(); @@ -35,15 +37,18 @@ describe('context', () => { }) class CmpA { @Prop({ context: 'resourcesUrl' }) resourcesUrl: boolean; + @Prop({ context: 'publicPath' }) publicPath: boolean; } const {rootInstance} = await newSpecPage({ components: [CmpA], html: ``, context: { - resourcesUrl: '/blabla' + resourcesUrl: '/blabla', + publicPath: '/blubblub' } }); expect(rootInstance.resourcesUrl).toEqual('/blabla'); + expect(rootInstance.publicPath).toEqual('/blubblub'); }); it('should extend context', async () => {