Skip to content

Commit 0e276cb

Browse files
committed
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.
1 parent 8e40bcc commit 0e276cb

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import { buildApplication } from '../../index';
10+
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';
11+
12+
describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
13+
describe('Option: "clearScreen"', () => {
14+
beforeEach(async () => {
15+
await harness.writeFile('src/main.ts', 'console.log("TEST");');
16+
});
17+
18+
for (const clearScreen of [true, false]) {
19+
it(`should ${clearScreen ? '' : 'not '}clear the screen before a rebuild when ${clearScreen}`, async () => {
20+
const clearSpy = spyOn(console, 'clear');
21+
22+
harness.useTarget('build', {
23+
...BASE_OPTIONS,
24+
watch: true,
25+
clearScreen,
26+
});
27+
28+
await harness.executeWithCases([
29+
async ({ result }) => {
30+
expect(result?.success).toBeTrue();
31+
expect(clearSpy).not.toHaveBeenCalled();
32+
33+
await harness.writeFile('src/main.ts', 'console.log("CHANGED");');
34+
},
35+
({ result }) => {
36+
expect(result?.success).toBeTrue();
37+
expect(clearSpy).toHaveBeenCalledTimes(clearScreen ? 1 : 0);
38+
},
39+
]);
40+
});
41+
}
42+
});
43+
});

0 commit comments

Comments
 (0)