From 0e276cb4f406f5e91b9183dcbb7979c368bc6752 Mon Sep 17 00:00:00 2001 From: MeAkib Date: Thu, 22 Oct 2026 23:23:43 +0600 Subject: [PATCH] test(@angular/build): add spec for the application `clearScreen` option The `clearScreen` option had no test. Run the application builder in watch mode and check that `console.clear` is called before a rebuild only when the option is enabled. --- .../tests/options/clear-screen_spec.ts | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 packages/angular/build/src/builders/application/tests/options/clear-screen_spec.ts diff --git a/packages/angular/build/src/builders/application/tests/options/clear-screen_spec.ts b/packages/angular/build/src/builders/application/tests/options/clear-screen_spec.ts new file mode 100644 index 000000000000..42da06beeb32 --- /dev/null +++ b/packages/angular/build/src/builders/application/tests/options/clear-screen_spec.ts @@ -0,0 +1,43 @@ +/** + * @license + * Copyright Google LLC 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.dev/license + */ + +import { buildApplication } from '../../index'; +import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; + +describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { + describe('Option: "clearScreen"', () => { + beforeEach(async () => { + await harness.writeFile('src/main.ts', 'console.log("TEST");'); + }); + + for (const clearScreen of [true, false]) { + it(`should ${clearScreen ? '' : 'not '}clear the screen before a rebuild when ${clearScreen}`, async () => { + const clearSpy = spyOn(console, 'clear'); + + harness.useTarget('build', { + ...BASE_OPTIONS, + watch: true, + clearScreen, + }); + + await harness.executeWithCases([ + async ({ result }) => { + expect(result?.success).toBeTrue(); + expect(clearSpy).not.toHaveBeenCalled(); + + await harness.writeFile('src/main.ts', 'console.log("CHANGED");'); + }, + ({ result }) => { + expect(result?.success).toBeTrue(); + expect(clearSpy).toHaveBeenCalledTimes(clearScreen ? 1 : 0); + }, + ]); + }); + } + }); +});