|
| 1 | +import { HttpServer } from '@open-draft/test-server/lib/http' |
| 2 | +import { test, expect } from '../../playwright.extend' |
| 3 | + |
| 4 | +const httpServer = new HttpServer((app) => { |
| 5 | + app.get('/resource', (req, res) => { |
| 6 | + res.set(req.headers) |
| 7 | + res.send('hello world') |
| 8 | + }) |
| 9 | +}) |
| 10 | + |
| 11 | +test.beforeAll(async () => { |
| 12 | + await httpServer.listen() |
| 13 | +}) |
| 14 | + |
| 15 | +test.afterAll(async () => { |
| 16 | + await httpServer.close() |
| 17 | +}) |
| 18 | + |
| 19 | +test('removes the internal passthrough request header', async ({ |
| 20 | + loadExample, |
| 21 | + fetch, |
| 22 | +}) => { |
| 23 | + await loadExample(require.resolve('./worker-passthrough-header.mocks.ts')) |
| 24 | + |
| 25 | + const response = await fetch(httpServer.http.url('/resource'), { |
| 26 | + headers: { 'x-custom-header': 'yes' }, |
| 27 | + }) |
| 28 | + const headers = await response.allHeaders() |
| 29 | + |
| 30 | + expect(headers).toMatchObject({ |
| 31 | + // The default header value. |
| 32 | + accept: '*/*', |
| 33 | + 'x-custom-header': 'yes', |
| 34 | + }) |
| 35 | + await expect(response.text()).resolves.toBe('hello world') |
| 36 | +}) |
| 37 | + |
| 38 | +test('preserves existing "accept" header values when removing the internal passthrough request header', async ({ |
| 39 | + loadExample, |
| 40 | + fetch, |
| 41 | +}) => { |
| 42 | + await loadExample(require.resolve('./worker-passthrough-header.mocks.ts')) |
| 43 | + |
| 44 | + const response = await fetch(httpServer.http.url('/resource'), { |
| 45 | + headers: { |
| 46 | + accept: 'text/plain, application/json', |
| 47 | + 'x-custom-header': 'yes', |
| 48 | + }, |
| 49 | + }) |
| 50 | + const headers = await response.allHeaders() |
| 51 | + |
| 52 | + expect(headers).toMatchObject({ |
| 53 | + accept: 'text/plain, application/json', |
| 54 | + 'x-custom-header': 'yes', |
| 55 | + }) |
| 56 | + await expect(response.text()).resolves.toBe('hello world') |
| 57 | +}) |
0 commit comments