fix(@angular/build): ensure tests run when compilation error is resolved · angular/angular-cli@4b8b7ca
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 { execute } from '../../index';
10+import {
11+BASE_OPTIONS,
12+describeBuilder,
13+UNIT_TEST_BUILDER_INFO,
14+setupApplicationTarget,
15+} from '../setup';
16+17+describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
18+describe('Watch Mode Behavior', () => {
19+beforeEach(async () => {
20+setupApplicationTarget(harness);
21+});
22+23+it('should run tests when a compilation error is fixed and a test failure is introduced simultaneously', async () => {
24+harness.useTarget('test', {
25+ ...BASE_OPTIONS,
26+watch: true,
27+});
28+29+await harness.executeWithCases([
30+// 1. Initial success
31+({ result }) => {
32+expect(result?.success).toBeTrue();
33+34+// 2. Introduce compilation error
35+harness.writeFiles({
36+'src/app/app.component.spec.ts': `
37+ import { describe, expect, test } from 'vitest'
38+ describe('AppComponent', () => {
39+ test('should create the app', () => {
40+ expect(true).toBe(true); // Syntax error incoming
41+ const x: string = 1; // Type error
42+ });
43+ });`,
44+});
45+},
46+// 3. Expect compilation error
47+({ result }) => {
48+expect(result?.success).toBeFalse();
49+50+// 4. Fix compilation error BUT introduce test failure
51+harness.writeFiles({
52+'src/app/app.component.spec.ts': `
53+ import { describe, expect, test } from 'vitest'
54+ describe('AppComponent', () => {
55+ test('should create the app', () => {
56+ expect(true).toBe(false); // Logic failure
57+ });
58+ });`,
59+});
60+},
61+// 5. Expect test failure (NOT success, which would happen if the test was skipped)
62+({ result }) => {
63+expect(result?.success).toBeFalse();
64+},
65+]);
66+});
67+});
68+});