diff --git a/packages/angular_devkit/build_angular/src/browser/specs/license-extraction_spec.ts b/packages/angular_devkit/build_angular/src/browser/specs/license-extraction_spec.ts deleted file mode 100644 index 056d6449a6fd..000000000000 --- a/packages/angular_devkit/build_angular/src/browser/specs/license-extraction_spec.ts +++ /dev/null @@ -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(); - }); -}); diff --git a/packages/angular_devkit/build_angular/src/browser/tests/options/extract-licenses_spec.ts b/packages/angular_devkit/build_angular/src/browser/tests/options/extract-licenses_spec.ts new file mode 100644 index 000000000000..50b29d23ee1b --- /dev/null +++ b/packages/angular_devkit/build_angular/src/browser/tests/options/extract-licenses_spec.ts @@ -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(); + }); + }); +});