Skip to content

Commit a24c212

Browse files
clydinfilipesilva
authored andcommitted
test(@angular-devkit/build-angular): add dev-server builder build budget behavior tests
This change adds expanded unit tests for the dev-server builder's build budget behavior using the builder test harness.
1 parent 420f4f2 commit a24c212

File tree

3 files changed

+38
-36
lines changed

3 files changed

+38
-36
lines changed

packages/angular_devkit/build_angular/src/dev-server/budgets_spec.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. 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+
import { Type as BudgetType } from '../../../';
9+
import { serveWebpackBrowser } from '../../index';
10+
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO, describeBuilder, setupBrowserTarget } from '../setup';
11+
12+
describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => {
13+
describe('Behavior: "browser builder budgets"', () => {
14+
beforeEach(() => {
15+
setupBrowserTarget(harness, {
16+
// Add a budget error for any file over 100 bytes
17+
budgets: [{ type: BudgetType.All, maximumError: '100b' }],
18+
optimization: true,
19+
});
20+
});
21+
22+
it('should ignore budgets defined in the "browserTarget" options', async () => {
23+
harness.useTarget('serve', {
24+
...BASE_OPTIONS,
25+
});
26+
27+
const { result } = await harness.executeOnce();
28+
29+
expect(result?.success).toBe(true);
30+
});
31+
});
32+
});

packages/angular_devkit/build_angular/src/dev-server/tests/setup.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { buildWebpackBrowser } from '../../browser';
9+
import { Schema as BrowserSchema } from '../../browser/schema';
910
import { BASE_OPTIONS as BROWSER_BASE_OPTIONS } from '../../browser/tests/setup';
1011
import { BuilderHarness } from '../../testing/builder-harness';
1112
import { Schema } from '../schema';
@@ -33,8 +34,12 @@ export const BASE_OPTIONS = Object.freeze<Schema>({
3334
*/
3435
export const BUILD_TIMEOUT = 15000;
3536

36-
export function setupBrowserTarget<T>(harness: BuilderHarness<T>): void {
37+
export function setupBrowserTarget<T>(
38+
harness: BuilderHarness<T>,
39+
extraOptions?: Partial<BrowserSchema>,
40+
): void {
3741
harness.withBuilderTarget('build', buildWebpackBrowser, {
3842
...BROWSER_BASE_OPTIONS,
43+
...extraOptions,
3944
});
4045
}

0 commit comments

Comments
 (0)