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