|
| 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 | +import { logging } from '@angular-devkit/core'; |
| 12 | + |
| 13 | +describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { |
| 14 | + describe('Option: "stylePreprocessorOptions.sass"', () => { |
| 15 | + it('should cause the build to fail when using `fatalDeprecations` in global styles', async () => { |
| 16 | + await harness.writeFile('src/styles.scss', 'p { color: darken(red, 10%) }'); |
| 17 | + |
| 18 | + harness.useTarget('build', { |
| 19 | + ...BASE_OPTIONS, |
| 20 | + styles: ['src/styles.scss'], |
| 21 | + stylePreprocessorOptions: { |
| 22 | + sass: { |
| 23 | + fatalDeprecations: ['color-functions'], |
| 24 | + }, |
| 25 | + }, |
| 26 | + }); |
| 27 | + |
| 28 | + const { result, logs } = await harness.executeOnce({ outputLogsOnFailure: false }); |
| 29 | + |
| 30 | + expect(result?.success).toBeFalse(); |
| 31 | + expect(logs).not.toContain( |
| 32 | + jasmine.objectContaining<logging.LogEntry>({ |
| 33 | + message: jasmine.stringMatching('darken() is deprecated'), |
| 34 | + }), |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should succeed without `fatalDeprecations` despite using deprecated color functions', async () => { |
| 39 | + await harness.writeFiles({ |
| 40 | + 'src/styles.scss': 'p { color: darken(red, 10%) }', |
| 41 | + 'src/app/app.component.scss': 'p { color: darken(red, 10%) }', |
| 42 | + }); |
| 43 | + |
| 44 | + await harness.modifyFile('src/app/app.component.ts', (content) => { |
| 45 | + return content.replace('./app.component.css', 'app.component.scss'); |
| 46 | + }); |
| 47 | + |
| 48 | + harness.useTarget('build', { |
| 49 | + ...BASE_OPTIONS, |
| 50 | + styles: ['src/styles.scss'], |
| 51 | + stylePreprocessorOptions: { |
| 52 | + sass: {}, |
| 53 | + }, |
| 54 | + }); |
| 55 | + |
| 56 | + const { result } = await harness.executeOnce(); |
| 57 | + |
| 58 | + expect(result?.success).toBeTrue(); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should cause the build to fail when using `fatalDeprecations` in component styles', async () => { |
| 62 | + await harness.modifyFile('src/app/app.component.ts', (content) => { |
| 63 | + return content.replace('./app.component.css', 'app.component.scss'); |
| 64 | + }); |
| 65 | + |
| 66 | + await harness.writeFile('src/app/app.component.scss', 'p { color: darken(red, 10%) }'); |
| 67 | + |
| 68 | + harness.useTarget('build', { |
| 69 | + ...BASE_OPTIONS, |
| 70 | + stylePreprocessorOptions: { |
| 71 | + sass: { |
| 72 | + fatalDeprecations: ['color-functions'], |
| 73 | + }, |
| 74 | + }, |
| 75 | + }); |
| 76 | + |
| 77 | + const { result, logs } = await harness.executeOnce({ |
| 78 | + outputLogsOnFailure: false, |
| 79 | + }); |
| 80 | + |
| 81 | + expect(result?.success).toBeFalse(); |
| 82 | + expect(logs).not.toContain( |
| 83 | + jasmine.objectContaining<logging.LogEntry>({ |
| 84 | + message: jasmine.stringMatching('darken() is deprecated'), |
| 85 | + }), |
| 86 | + ); |
| 87 | + }); |
| 88 | + }); |
| 89 | +}); |
0 commit comments