|
| 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 | +const ESBUILD_LOG_TEXT = 'Application bundle generation complete.'; |
| 15 | +const WEBPACK_LOG_TEXT = 'Compiled successfully.'; |
| 16 | + |
| 17 | +describeServeBuilder( |
| 18 | + executeDevServer, |
| 19 | + DEV_SERVER_BUILDER_INFO, |
| 20 | + (harness, setupTarget, isViteRun) => { |
| 21 | + describe('option: "forceEsbuild"', () => { |
| 22 | + beforeEach(async () => { |
| 23 | + setupTarget(harness, {}); |
| 24 | + |
| 25 | + // Application code is not needed for these tests |
| 26 | + await harness.writeFile('src/main.ts', 'console.log("foo");'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should use build target specified build system when not present', async () => { |
| 30 | + harness.useTarget('serve', { |
| 31 | + ...BASE_OPTIONS, |
| 32 | + forceEsbuild: undefined, |
| 33 | + }); |
| 34 | + |
| 35 | + const { result, response, logs } = await executeOnceAndFetch(harness, '/main.js'); |
| 36 | + |
| 37 | + expect(result?.success).toBeTrue(); |
| 38 | + expect(await response?.text()).toContain('console.log'); |
| 39 | + expect(logs).toContain( |
| 40 | + jasmine.objectContaining({ |
| 41 | + message: jasmine.stringMatching(isViteRun ? ESBUILD_LOG_TEXT : WEBPACK_LOG_TEXT), |
| 42 | + }), |
| 43 | + ); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should use build target specified build system when false', async () => { |
| 47 | + harness.useTarget('serve', { |
| 48 | + ...BASE_OPTIONS, |
| 49 | + forceEsbuild: false, |
| 50 | + }); |
| 51 | + |
| 52 | + const { result, response, logs } = await executeOnceAndFetch(harness, '/main.js'); |
| 53 | + |
| 54 | + expect(result?.success).toBeTrue(); |
| 55 | + expect(await response?.text()).toContain('console.log'); |
| 56 | + expect(logs).toContain( |
| 57 | + jasmine.objectContaining({ |
| 58 | + message: jasmine.stringMatching(isViteRun ? ESBUILD_LOG_TEXT : WEBPACK_LOG_TEXT), |
| 59 | + }), |
| 60 | + ); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should always use the esbuild build system with Vite when true', async () => { |
| 64 | + harness.useTarget('serve', { |
| 65 | + ...BASE_OPTIONS, |
| 66 | + forceEsbuild: true, |
| 67 | + }); |
| 68 | + |
| 69 | + const { result, response, logs } = await executeOnceAndFetch(harness, '/main.js'); |
| 70 | + |
| 71 | + expect(result?.success).toBeTrue(); |
| 72 | + expect(await response?.text()).toContain('console.log'); |
| 73 | + expect(logs).toContain( |
| 74 | + jasmine.objectContaining({ message: jasmine.stringMatching(ESBUILD_LOG_TEXT) }), |
| 75 | + ); |
| 76 | + }); |
| 77 | + }); |
| 78 | + }, |
| 79 | +); |
0 commit comments