-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular-devkit/build-angular): ensure browser-esbuild is used in…
… dev server with browser builder and forceEsbuild To ensure that the `forceEsbuild` development server option chooses the correct underlying build implementation when the project contains the `browser` builder within the build target, an explicit check and conversion of the builder name is now performed during the initialization phase of the development server builder. (cherry picked from commit d07ef2f)
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
.../angular_devkit/build_angular/src/builders/dev-server/tests/options/force-esbuild_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { executeDevServer } from '../../index'; | ||
import { executeOnceAndFetch } from '../execute-fetch'; | ||
import { describeServeBuilder } from '../jasmine-helpers'; | ||
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup'; | ||
|
||
const ESBUILD_LOG_TEXT = 'Application bundle generation complete.'; | ||
const WEBPACK_LOG_TEXT = 'Compiled successfully.'; | ||
|
||
describeServeBuilder( | ||
executeDevServer, | ||
DEV_SERVER_BUILDER_INFO, | ||
(harness, setupTarget, isViteRun) => { | ||
describe('option: "forceEsbuild"', () => { | ||
beforeEach(async () => { | ||
setupTarget(harness, {}); | ||
|
||
// Application code is not needed for these tests | ||
await harness.writeFile('src/main.ts', 'console.log("foo");'); | ||
}); | ||
|
||
it('should use build target specified build system when not present', async () => { | ||
harness.useTarget('serve', { | ||
...BASE_OPTIONS, | ||
forceEsbuild: undefined, | ||
}); | ||
|
||
const { result, response, logs } = await executeOnceAndFetch(harness, '/main.js'); | ||
|
||
expect(result?.success).toBeTrue(); | ||
expect(await response?.text()).toContain('console.log'); | ||
expect(logs).toContain( | ||
jasmine.objectContaining({ | ||
message: jasmine.stringMatching(isViteRun ? ESBUILD_LOG_TEXT : WEBPACK_LOG_TEXT), | ||
}), | ||
); | ||
}); | ||
|
||
it('should use build target specified build system when false', async () => { | ||
harness.useTarget('serve', { | ||
...BASE_OPTIONS, | ||
forceEsbuild: false, | ||
}); | ||
|
||
const { result, response, logs } = await executeOnceAndFetch(harness, '/main.js'); | ||
|
||
expect(result?.success).toBeTrue(); | ||
expect(await response?.text()).toContain('console.log'); | ||
expect(logs).toContain( | ||
jasmine.objectContaining({ | ||
message: jasmine.stringMatching(isViteRun ? ESBUILD_LOG_TEXT : WEBPACK_LOG_TEXT), | ||
}), | ||
); | ||
}); | ||
|
||
it('should always use the esbuild build system with Vite when true', async () => { | ||
harness.useTarget('serve', { | ||
...BASE_OPTIONS, | ||
forceEsbuild: true, | ||
}); | ||
|
||
const { result, response, logs } = await executeOnceAndFetch(harness, '/main.js'); | ||
|
||
expect(result?.success).toBeTrue(); | ||
expect(await response?.text()).toContain('console.log'); | ||
expect(logs).toContain( | ||
jasmine.objectContaining({ message: jasmine.stringMatching(ESBUILD_LOG_TEXT) }), | ||
); | ||
}); | ||
}); | ||
}, | ||
); |