|
| 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 { buildApplication } from '../../index'; |
| 10 | +import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; |
| 11 | + |
| 12 | +describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { |
| 13 | + describe('Option: "deployUrl"', () => { |
| 14 | + beforeEach(async () => { |
| 15 | + // Add a global stylesheet to test link elements |
| 16 | + await harness.writeFile('src/styles.css', '/* Global styles */'); |
| 17 | + |
| 18 | + // Reduce the input index HTML to a single line to simplify comparing |
| 19 | + await harness.writeFile( |
| 20 | + 'src/index.html', |
| 21 | + '<html><head><base href="/"></head><body><app-root></app-root></body></html>', |
| 22 | + ); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should update script src and link href attributes when option is set to relative URL', async () => { |
| 26 | + harness.useTarget('build', { |
| 27 | + ...BASE_OPTIONS, |
| 28 | + styles: ['src/styles.css'], |
| 29 | + deployUrl: 'deployUrl/', |
| 30 | + }); |
| 31 | + |
| 32 | + const { result } = await harness.executeOnce(); |
| 33 | + expect(result?.success).toBe(true); |
| 34 | + harness |
| 35 | + .expectFile('dist/browser/index.html') |
| 36 | + .content.toEqual( |
| 37 | + `<html><head><base href="/"><link rel="stylesheet" href="deployUrl/styles.css"></head>` + |
| 38 | + `<body><app-root></app-root>` + |
| 39 | + `<script src="deployUrl/main.js" type="module"></script></body></html>`, |
| 40 | + ); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should update script src and link href attributes when option is set to absolute URL', async () => { |
| 44 | + harness.useTarget('build', { |
| 45 | + ...BASE_OPTIONS, |
| 46 | + styles: ['src/styles.css'], |
| 47 | + deployUrl: 'https://example.com/some/path/', |
| 48 | + }); |
| 49 | + |
| 50 | + const { result } = await harness.executeOnce(); |
| 51 | + expect(result?.success).toBe(true); |
| 52 | + harness |
| 53 | + .expectFile('dist/browser/index.html') |
| 54 | + .content.toEqual( |
| 55 | + `<html><head><base href="/"><link rel="stylesheet" href="https://example.com/some/path/styles.css"></head>` + |
| 56 | + `<body><app-root></app-root>` + |
| 57 | + `<script src="https://example.com/some/path/main.js" type="module"></script></body></html>`, |
| 58 | + ); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should update resources component stylesheets to reference deployURL', async () => { |
| 62 | + await harness.writeFile('src/app/test.svg', '<svg></svg>'); |
| 63 | + await harness.writeFile( |
| 64 | + 'src/app/app.component.css', |
| 65 | + `* { background-image: url('./test.svg'); }`, |
| 66 | + ); |
| 67 | + |
| 68 | + harness.useTarget('build', { |
| 69 | + ...BASE_OPTIONS, |
| 70 | + deployUrl: 'https://example.com/some/path/', |
| 71 | + }); |
| 72 | + |
| 73 | + const { result } = await harness.executeOnce(); |
| 74 | + expect(result?.success).toBe(true); |
| 75 | + harness |
| 76 | + .expectFile('dist/browser/main.js') |
| 77 | + .content.toContain(`https://example.com/some/path/media/test.svg`); |
| 78 | + }); |
| 79 | + }); |
| 80 | +}); |
0 commit comments