diff --git a/dotcom-rendering/playwright.config.ts b/dotcom-rendering/playwright.config.ts index 6ee1a0b70bb..066a72d17dd 100644 --- a/dotcom-rendering/playwright.config.ts +++ b/dotcom-rendering/playwright.config.ts @@ -45,5 +45,8 @@ export default defineConfig({ reuseExistingServer: true, stdout: 'pipe', stderr: 'pipe', + env: { + PLAYWRIGHT: 'true', + }, }, }); diff --git a/dotcom-rendering/src/client/decidePublicPath.test.ts b/dotcom-rendering/src/client/decidePublicPath.test.ts index 85ebbf20e3c..3a8efbbe5fd 100644 --- a/dotcom-rendering/src/client/decidePublicPath.test.ts +++ b/dotcom-rendering/src/client/decidePublicPath.test.ts @@ -44,7 +44,7 @@ describe('decidePublicPath', () => { it('with production flag and localhost', () => { process.env.NODE_ENV = 'production'; mockHostname('localhost'); - expect(decidePublicPath()).toEqual('/assets/'); + expect(decidePublicPath()).toEqual('http://localhost:3030/assets/'); }); it('with no flag', () => { diff --git a/dotcom-rendering/src/client/decidePublicPath.ts b/dotcom-rendering/src/client/decidePublicPath.ts index 41bb44db145..a723d648ed2 100644 --- a/dotcom-rendering/src/client/decidePublicPath.ts +++ b/dotcom-rendering/src/client/decidePublicPath.ts @@ -6,8 +6,15 @@ export const decidePublicPath = (): string => { const isDev = process.env.NODE_ENV === 'development'; const isLocalHost = window.location.hostname === 'localhost'; - // Use relative path if running locally or in CI - return isDev || isLocalHost - ? '/assets/' - : `${window.guardian.config.frontendAssetsFullURL}assets/`; + const isPlaywright = process.env.PLAYWRIGHT === 'true'; + + if (isPlaywright && isDev) { + return `/assets/`; + } + + if (isDev || isLocalHost) { + return `http://localhost:3030/assets/`; + } + + return `${window.guardian.config.frontendAssetsFullURL}assets/`; };