Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions e2e/widget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
});
Expand Down
46 changes: 46 additions & 0 deletions test/localConfigRoute.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading