-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular-devkit/build-angular): cache stylesheet load errors with…
… application builder When using the `application` and/or `browser-esbuild` builders, stylesheets that generate errors will now have the errors cached between rebuilds during watch mode (include `ng serve`). This not only avoids reprocessing files that contain errors and that have not changed but also provides file watching information from the cache to ensure the error-causing files are properly invalidated.
- Loading branch information
Showing
5 changed files
with
147 additions
and
16 deletions.
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
...evkit/build_angular/src/builders/application/tests/behavior/rebuild-global_styles_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** | ||
* @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.io/license | ||
*/ | ||
|
||
import { concatMap, count, timeout } from 'rxjs'; | ||
import { buildApplication } from '../../index'; | ||
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; | ||
|
||
/** | ||
* Maximum time in milliseconds for single build/rebuild | ||
* This accounts for CI variability. | ||
*/ | ||
export const BUILD_TIMEOUT = 30_000; | ||
|
||
describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { | ||
describe('Behavior: "Rebuilds when global stylesheets change"', () => { | ||
beforeEach(async () => { | ||
// Application code is not needed for styles tests | ||
await harness.writeFile('src/main.ts', 'console.log("TEST");'); | ||
}); | ||
|
||
it('rebuilds Sass stylesheet after error on rebuild from import', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
watch: true, | ||
styles: ['src/styles.scss'], | ||
}); | ||
|
||
await harness.writeFile('src/styles.scss', "@import './a';"); | ||
await harness.writeFile('src/a.scss', '$primary: aqua;\\nh1 { color: $primary; }'); | ||
|
||
const builderAbort = new AbortController(); | ||
const buildCount = await harness | ||
.execute({ signal: builderAbort.signal, outputLogsOnFailure: false }) | ||
.pipe( | ||
timeout(30000), | ||
concatMap(async ({ result }, index) => { | ||
switch (index) { | ||
case 0: | ||
expect(result?.success).toBe(true); | ||
harness.expectFile('dist/browser/styles.css').content.toContain('color: aqua'); | ||
harness.expectFile('dist/browser/styles.css').content.not.toContain('color: blue'); | ||
|
||
await harness.writeFile( | ||
'src/a.scss', | ||
'invalid-invalid-invalid\\nh1 { color: $primary; }', | ||
); | ||
break; | ||
case 1: | ||
expect(result?.success).toBe(false); | ||
|
||
await harness.writeFile('src/a.scss', '$primary: blue;\\nh1 { color: $primary; }'); | ||
break; | ||
case 2: | ||
expect(result?.success).toBe(true); | ||
harness.expectFile('dist/browser/styles.css').content.not.toContain('color: aqua'); | ||
harness.expectFile('dist/browser/styles.css').content.toContain('color: blue'); | ||
|
||
// Test complete - abort watch mode | ||
builderAbort.abort(); | ||
break; | ||
} | ||
}), | ||
count(), | ||
) | ||
.toPromise(); | ||
|
||
expect(buildCount).toBe(3); | ||
}); | ||
|
||
it('rebuilds Sass stylesheet after error on initial build from import', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
watch: true, | ||
styles: ['src/styles.scss'], | ||
}); | ||
|
||
await harness.writeFile('src/styles.scss', "@import './a';"); | ||
await harness.writeFile('src/a.scss', 'invalid-invalid-invalid\\nh1 { color: $primary; }'); | ||
|
||
const builderAbort = new AbortController(); | ||
const buildCount = await harness | ||
.execute({ signal: builderAbort.signal, outputLogsOnFailure: false }) | ||
.pipe( | ||
timeout(30000), | ||
concatMap(async ({ result }, index) => { | ||
switch (index) { | ||
case 0: | ||
expect(result?.success).toBe(false); | ||
|
||
await harness.writeFile('src/a.scss', '$primary: aqua;\\nh1 { color: $primary; }'); | ||
break; | ||
case 1: | ||
expect(result?.success).toBe(true); | ||
harness.expectFile('dist/browser/styles.css').content.toContain('color: aqua'); | ||
harness.expectFile('dist/browser/styles.css').content.not.toContain('color: blue'); | ||
|
||
await harness.writeFile('src/a.scss', '$primary: blue;\\nh1 { color: $primary; }'); | ||
break; | ||
case 2: | ||
expect(result?.success).toBe(true); | ||
harness.expectFile('dist/browser/styles.css').content.not.toContain('color: aqua'); | ||
harness.expectFile('dist/browser/styles.css').content.toContain('color: blue'); | ||
|
||
// Test complete - abort watch mode | ||
builderAbort.abort(); | ||
break; | ||
} | ||
}), | ||
count(), | ||
) | ||
.toPromise(); | ||
|
||
expect(buildCount).toBe(3); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters