-
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): allow multiple polyfills with esb…
…uild-based builder Previously when using the esbuild-based browser application, the `polyfills` option was limited to only one entry. The option now can be used with multiple entries and has full support for package resolution. This provides equivalent behavior to the current default Webpack-based builder.
- Loading branch information
1 parent
50b9e59
commit cdfa7ca
Showing
3 changed files
with
106 additions
and
18 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
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
69 changes: 69 additions & 0 deletions
69
...angular_devkit/build_angular/src/builders/browser-esbuild/tests/options/polyfills_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,69 @@ | ||
/** | ||
* @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 { buildEsbuildBrowser } from '../../index'; | ||
import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup'; | ||
|
||
describeBuilder(buildEsbuildBrowser, BROWSER_BUILDER_INFO, (harness) => { | ||
describe('Option: "polyfills"', () => { | ||
it('uses a provided TypeScript file', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
polyfills: 'src/polyfills.ts', | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
|
||
expect(result?.success).toBe(true); | ||
|
||
harness.expectFile('dist/polyfills.js').toExist(); | ||
}); | ||
|
||
it('uses a provided JavaScript file', async () => { | ||
await harness.writeFile('src/polyfills.js', `console.log('main');`); | ||
|
||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
polyfills: 'src/polyfills.js', | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
|
||
expect(result?.success).toBe(true); | ||
|
||
harness.expectFile('dist/polyfills.js').content.toContain(`console.log("main")`); | ||
}); | ||
|
||
it('fails and shows an error when file does not exist', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
polyfills: 'src/missing.ts', | ||
}); | ||
|
||
const { result, logs } = await harness.executeOnce({ outputLogsOnFailure: false }); | ||
|
||
expect(result?.success).toBe(false); | ||
expect(logs).toContain( | ||
jasmine.objectContaining({ message: jasmine.stringMatching('Could not resolve') }), | ||
); | ||
|
||
harness.expectFile('dist/polyfills.js').toNotExist(); | ||
}); | ||
|
||
it('resolves module specifiers in array', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
polyfills: ['zone.js', 'zone.js/testing'], | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
harness.expectFile('dist/polyfills.js').toExist(); | ||
}); | ||
}); | ||
}); |