test(@angular-devkit/build-angular): change extractLicenses unit test to use build harness

This change adds a unit tests for the browser builder's extractLicenses option using the builder test harness.
This commit is contained in:
Alan Agius 2021-01-11 19:14:58 +01:00
parent df897f0e41
commit a266f55b6c
2 changed files with 45 additions and 30 deletions

View File

@ -1,30 +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 { Architect } from '@angular-devkit/architect';
import { browserBuild, createArchitect, host } from '../../test-utils';
describe('Browser Builder license extraction', () => {
const target = { project: 'app', target: 'build' };
let architect: Architect;
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
});
afterEach(async () => host.restore().toPromise());
// Ignored because license works when trying manually on a project, but doesn't work here.
it('works', async () => {
// TODO: make license extraction independent from optimization level.
const overrides = { extractLicenses: true, optimization: true };
const { files } = await browserBuild(architect, host, target, overrides);
expect(await files['3rdpartylicenses.txt']).not.toBeUndefined();
});
});

View File

@ -0,0 +1,45 @@
/**
* @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 { buildWebpackBrowser } from '../../index';
import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup';
describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
describe('Option: "extractLicenses"', () => {
it(`should generate '3rdpartylicenses.txt' when 'extractLicenses' is true`, async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
extractLicenses: true,
});
const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness.expectFile('dist/3rdpartylicenses.txt').content.toContain('MIT');
});
it(`should not generate '3rdpartylicenses.txt' when 'extractLicenses' is false`, async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
extractLicenses: false,
});
const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness.expectFile('dist/3rdpartylicenses.txt').toNotExist();
});
it(`should not generate '3rdpartylicenses.txt' when 'extractLicenses' is not set`, async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
});
const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness.expectFile('dist/3rdpartylicenses.txt').toNotExist();
});
});
});