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.
This commit is contained in:
Charles Lyding 2021-03-05 11:45:50 -05:00 committed by Filipe Silva
parent 420f4f2655
commit a24c212203
3 changed files with 38 additions and 36 deletions

View File

@ -1,35 +0,0 @@
/**
* @license
* Copyright Google Inc. 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 { normalize, virtualFs } from '@angular-devkit/core';
import { createArchitect, host } from '../test-utils';
describe('Dev Server Builder bundle budgets', () => {
const targetSpec = { project: 'app', target: 'serve' };
beforeEach(async () => host.initialize().toPromise());
afterEach(async () => host.restore().toPromise());
it('should ignore budgets', async () => {
const config = host.scopedSync().read(normalize('angular.json'));
const jsonConfig = JSON.parse(virtualFs.fileBufferToString(config));
const buildOptions = jsonConfig.projects.app.targets.build.options;
buildOptions.budgets = [{ type: 'all', maximumError: '100b' }],
buildOptions.optimization = true;
host.writeMultipleFiles({
'angular.json': JSON.stringify(jsonConfig),
});
const architect = (await createArchitect(host.root())).architect;
const run = await architect.scheduleTarget(targetSpec);
const output = await run.result;
expect(output.success).toBe(true);
await run.stop();
});
});

View File

@ -0,0 +1,32 @@
/**
* @license
* Copyright Google Inc. 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 { Type as BudgetType } from '../../../';
import { serveWebpackBrowser } from '../../index';
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO, describeBuilder, setupBrowserTarget } from '../setup';
describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => {
describe('Behavior: "browser builder budgets"', () => {
beforeEach(() => {
setupBrowserTarget(harness, {
// Add a budget error for any file over 100 bytes
budgets: [{ type: BudgetType.All, maximumError: '100b' }],
optimization: true,
});
});
it('should ignore budgets defined in the "browserTarget" options', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
});
const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
});
});
});

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import { buildWebpackBrowser } from '../../browser';
import { Schema as BrowserSchema } from '../../browser/schema';
import { BASE_OPTIONS as BROWSER_BASE_OPTIONS } from '../../browser/tests/setup';
import { BuilderHarness } from '../../testing/builder-harness';
import { Schema } from '../schema';
@ -33,8 +34,12 @@ export const BASE_OPTIONS = Object.freeze<Schema>({
*/
export const BUILD_TIMEOUT = 15000;
export function setupBrowserTarget<T>(harness: BuilderHarness<T>): void {
export function setupBrowserTarget<T>(
harness: BuilderHarness<T>,
extraOptions?: Partial<BrowserSchema>,
): void {
harness.withBuilderTarget('build', buildWebpackBrowser, {
...BROWSER_BASE_OPTIONS,
...extraOptions,
});
}