From 1d40cc3e37921e2967d2488cd6c57d8086f0adb8 Mon Sep 17 00:00:00 2001 From: antoine Date: Tue, 19 May 2026 08:01:40 +0200 Subject: [PATCH 1/2] fix: use text/javascript MIME type for local-config.js endpoint --- e2e/widget.spec.ts | 5 ++--- src/index.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/e2e/widget.spec.ts b/e2e/widget.spec.ts index 217609e..4be7854 100644 --- a/e2e/widget.spec.ts +++ b/e2e/widget.spec.ts @@ -223,12 +223,11 @@ test.describe('Widget Loading', () => { expect(savedAfterResize).toBe(savedTop); }); - test('missing local test config returns an empty script', async ({ page }) => { + test('missing local test config returns a javascript file', async ({ page }) => { const response = await page.request.get('/test/local-config.js'); expect(response.status()).toBe(200); - expect(response.headers()['content-type']).toContain('application/javascript'); - expect(await response.text()).toBe(''); + expect(response.headers()['content-type']).toBe('text/javascript; charset=utf-8'); }); test('test pages use upstream repo when no local override is present', async ({ page }) => { diff --git a/src/index.ts b/src/index.ts index 58ea2ef..a01624e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -72,7 +72,7 @@ app.get('/test/local-config.js', async c => { } return new Response('', { headers: { - 'content-type': 'application/javascript; charset=utf-8', + 'content-type': 'text/javascript; charset=utf-8', }, }); }); From 2bc8a8c16b6296a40b1198a41eeccd06e9de2a6c Mon Sep 17 00:00:00 2001 From: neonwatty Date: Tue, 19 May 2026 04:56:51 -0700 Subject: [PATCH 2/2] test: cover local config route fallback --- test/localConfigRoute.test.ts | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/localConfigRoute.test.ts diff --git a/test/localConfigRoute.test.ts b/test/localConfigRoute.test.ts new file mode 100644 index 0000000..19668b5 --- /dev/null +++ b/test/localConfigRoute.test.ts @@ -0,0 +1,46 @@ +import { describe, expect, it } from 'vitest'; +import app from '../src/index'; +import type { Env } from '../src/types'; + +function createEnv(assetResponse: Response): Env { + return { + GITHUB_APP_ID: 'test-app-id', + GITHUB_PRIVATE_KEY: 'test-private-key', + ENVIRONMENT: 'test', + ALLOWED_ORIGINS: 'http://localhost:8787', + GITHUB_APP_NAME: 'test-app', + MAX_SCREENSHOT_SIZE_MB: '5', + ASSETS: { + fetch: async () => assetResponse, + } as Fetcher, + }; +} + +describe('GET /test/local-config.js', () => { + it('returns an empty JavaScript response when the local config asset is missing', async () => { + const response = await app.fetch( + new Request('http://localhost/test/local-config.js'), + createEnv(new Response('Not found', { status: 404 })) + ); + + expect(response.status).toBe(200); + expect(response.headers.get('content-type')).toBe('text/javascript; charset=utf-8'); + expect(await response.text()).toBe(''); + }); + + it('passes through an existing local config asset', async () => { + const source = 'window.BugDropTestConfig = { repo: "local-owner/local-repo" };'; + const response = await app.fetch( + new Request('http://localhost/test/local-config.js'), + createEnv( + new Response(source, { + headers: { 'content-type': 'text/javascript; charset=utf-8' }, + }) + ) + ); + + expect(response.status).toBe(200); + expect(response.headers.get('content-type')).toBe('text/javascript; charset=utf-8'); + expect(await response.text()).toBe(source); + }); +});