|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | + |
| 9 | +import { executeDevServer } from '../../index'; |
| 10 | +import { executeOnceAndFetch } from '../execute-fetch'; |
| 11 | +import { describeServeBuilder } from '../jasmine-helpers'; |
| 12 | +import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup'; |
| 13 | + |
| 14 | +describeServeBuilder( |
| 15 | + executeDevServer, |
| 16 | + DEV_SERVER_BUILDER_INFO, |
| 17 | + (harness, setupTarget, isViteRun) => { |
| 18 | + (isViteRun ? describe : xdescribe)('option: "headers"', () => { |
| 19 | + beforeEach(async () => { |
| 20 | + setupTarget(harness, { |
| 21 | + styles: ['src/styles.css'], |
| 22 | + }); |
| 23 | + |
| 24 | + // Application code is not needed for these tests |
| 25 | + await harness.writeFile('src/main.ts', ''); |
| 26 | + await harness.writeFile('src/styles.css', ''); |
| 27 | + }); |
| 28 | + |
| 29 | + it('index response headers should include configured header', async () => { |
| 30 | + harness.useTarget('serve', { |
| 31 | + ...BASE_OPTIONS, |
| 32 | + headers: { |
| 33 | + 'x-custom': 'foo', |
| 34 | + }, |
| 35 | + }); |
| 36 | + |
| 37 | + const { result, response } = await executeOnceAndFetch(harness, '/'); |
| 38 | + |
| 39 | + expect(result?.success).toBeTrue(); |
| 40 | + expect(await response?.headers.get('x-custom')).toBe('foo'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('media resource response headers should include configured header', async () => { |
| 44 | + await harness.writeFiles({ |
| 45 | + 'src/styles.css': `h1 { background: url('./test.svg')}`, |
| 46 | + 'src/test.svg': `<svg xmlns="http://www.w3.org/2000/svg"> |
| 47 | + <text x="20" y="20" font-size="20" fill="red">Hello World</text> |
| 48 | + </svg>`, |
| 49 | + }); |
| 50 | + |
| 51 | + harness.useTarget('serve', { |
| 52 | + ...BASE_OPTIONS, |
| 53 | + headers: { |
| 54 | + 'x-custom': 'foo', |
| 55 | + }, |
| 56 | + }); |
| 57 | + |
| 58 | + const { result, response } = await executeOnceAndFetch(harness, '/media/test.svg'); |
| 59 | + |
| 60 | + expect(result?.success).toBeTrue(); |
| 61 | + expect(await response?.headers.get('x-custom')).toBe('foo'); |
| 62 | + }); |
| 63 | + }); |
| 64 | + }, |
| 65 | +); |
0 commit comments