|
| 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(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => { |
| 15 | + describe('Behavior: "buildTarget baseHref"', () => { |
| 16 | + beforeEach(async () => { |
| 17 | + setupTarget(harness, { |
| 18 | + baseHref: '/test/', |
| 19 | + }); |
| 20 | + |
| 21 | + // Application code is not needed for these tests |
| 22 | + await harness.writeFile('src/main.ts', 'console.log("foo");'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('uses the baseHref defined in the "buildTarget" options as the serve path', async () => { |
| 26 | + harness.useTarget('serve', { |
| 27 | + ...BASE_OPTIONS, |
| 28 | + }); |
| 29 | + |
| 30 | + const { result, response } = await executeOnceAndFetch(harness, '/test/main.js'); |
| 31 | + |
| 32 | + expect(result?.success).toBeTrue(); |
| 33 | + const baseUrl = new URL(`${result?.baseUrl}/`); |
| 34 | + expect(baseUrl.pathname).toBe('/test/'); |
| 35 | + expect(await response?.text()).toContain('console.log'); |
| 36 | + }); |
| 37 | + |
| 38 | + it('serves the application from baseHref location without trailing slash', async () => { |
| 39 | + harness.useTarget('serve', { |
| 40 | + ...BASE_OPTIONS, |
| 41 | + }); |
| 42 | + |
| 43 | + const { result, response } = await executeOnceAndFetch(harness, '/test'); |
| 44 | + |
| 45 | + expect(result?.success).toBeTrue(); |
| 46 | + expect(await response?.text()).toContain('<script src="main.js" type="module">'); |
| 47 | + }); |
| 48 | + }); |
| 49 | +}); |
0 commit comments