From c9a002c04bbf41027336600b45cf7cee98f96d91 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 5 Apr 2021 11:43:43 -0400 Subject: [PATCH] test(@angular-devkit/build-angular): add initial dev-server builder hmr and liveReload option tests The CommonJS usage warning tests are moved to use the builder harness for both the `hmr` and `liveReload` options. --- .../src/dev-server/common-js-warning_spec.ts | 46 ------------------- .../src/dev-server/tests/options/hmr_spec.ts | 38 +++++++++++++++ .../tests/options/live-reload_spec.ts | 38 +++++++++++++++ 3 files changed, 76 insertions(+), 46 deletions(-) delete mode 100644 packages/angular_devkit/build_angular/src/dev-server/common-js-warning_spec.ts create mode 100644 packages/angular_devkit/build_angular/src/dev-server/tests/options/hmr_spec.ts create mode 100644 packages/angular_devkit/build_angular/src/dev-server/tests/options/live-reload_spec.ts diff --git a/packages/angular_devkit/build_angular/src/dev-server/common-js-warning_spec.ts b/packages/angular_devkit/build_angular/src/dev-server/common-js-warning_spec.ts deleted file mode 100644 index 309938c9b0ba..000000000000 --- a/packages/angular_devkit/build_angular/src/dev-server/common-js-warning_spec.ts +++ /dev/null @@ -1,46 +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 { logging } from '@angular-devkit/core'; -import { createArchitect, host } from '../test-utils'; - -describe('Dev Server Builder commonjs warning', () => { - const targetSpec = { project: 'app', target: 'serve' }; - - let architect: Architect; - let logger: logging.Logger; - let logs: string[]; - - beforeEach(async () => { - await host.initialize().toPromise(); - architect = (await createArchitect(host.root())).architect; - - // Create logger - logger = new logging.Logger(''); - logs = []; - logger.subscribe(e => logs.push(e.message)); - }); - - afterEach(async () => host.restore().toPromise()); - - it('should not show warning when using HMR', async () => { - const run = await architect.scheduleTarget(targetSpec, { hmr: true }, { logger }); - const output = await run.result; - expect(output.success).toBe(true); - expect(logs.join()).not.toContain('Warning'); - await run.stop(); - }); - - it('should not show warning when using live-reload', async () => { - const run = await architect.scheduleTarget(targetSpec, { liveReload: true}, { logger }); - const output = await run.result; - expect(output.success).toBe(true); - expect(logs.join()).not.toContain('Warning'); - await run.stop(); - }); -}); diff --git a/packages/angular_devkit/build_angular/src/dev-server/tests/options/hmr_spec.ts b/packages/angular_devkit/build_angular/src/dev-server/tests/options/hmr_spec.ts new file mode 100644 index 000000000000..d0f76f7f1ee5 --- /dev/null +++ b/packages/angular_devkit/build_angular/src/dev-server/tests/options/hmr_spec.ts @@ -0,0 +1,38 @@ +/** + * @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 { serveWebpackBrowser } from '../../index'; +import { + BASE_OPTIONS, + DEV_SERVER_BUILDER_INFO, + describeBuilder, + setupBrowserTarget, +} from '../setup'; + +describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => { + describe('Option: "hmr"', () => { + beforeEach(() => { + setupBrowserTarget(harness); + }); + + it('should not show a CommonJS usage warning when enabled', async () => { + harness.useTarget('serve', { + ...BASE_OPTIONS, + hmr: true, + }); + + const { result, logs } = await harness.executeOnce(); + + expect(result?.success).toBe(true); + expect(logs).not.toContain( + jasmine.objectContaining({ + message: jasmine.stringMatching('CommonJS or AMD dependencies'), + }), + ); + }); + }); +}); diff --git a/packages/angular_devkit/build_angular/src/dev-server/tests/options/live-reload_spec.ts b/packages/angular_devkit/build_angular/src/dev-server/tests/options/live-reload_spec.ts new file mode 100644 index 000000000000..12ce756e1b3e --- /dev/null +++ b/packages/angular_devkit/build_angular/src/dev-server/tests/options/live-reload_spec.ts @@ -0,0 +1,38 @@ +/** + * @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 { serveWebpackBrowser } from '../../index'; +import { + BASE_OPTIONS, + DEV_SERVER_BUILDER_INFO, + describeBuilder, + setupBrowserTarget, +} from '../setup'; + +describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => { + describe('Option: "liveReload"', () => { + beforeEach(() => { + setupBrowserTarget(harness); + }); + + it('should not show a CommonJS usage warning when enabled', async () => { + harness.useTarget('serve', { + ...BASE_OPTIONS, + liveReload: true, + }); + + const { result, logs } = await harness.executeOnce(); + + expect(result?.success).toBe(true); + expect(logs).not.toContain( + jasmine.objectContaining({ + message: jasmine.stringMatching('CommonJS or AMD dependencies'), + }), + ); + }); + }); +});