|
| 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.io/license |
| 7 | + */ |
| 8 | + |
| 9 | +import { concatMap, count, take, timeout } from 'rxjs/operators'; |
| 10 | +import { buildEsbuildBrowser } from '../../index'; |
| 11 | +import { InlineStyleLanguage } from '../../schema'; |
| 12 | +import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup'; |
| 13 | + |
| 14 | +describeBuilder(buildEsbuildBrowser, BROWSER_BUILDER_INFO, (harness) => { |
| 15 | + describe('Option: "inlineStyleLanguage"', () => { |
| 16 | + beforeEach(async () => { |
| 17 | + // Setup application component with inline style property |
| 18 | + await harness.modifyFile('src/app/app.component.ts', (content) => { |
| 19 | + return content |
| 20 | + .replace('styleUrls', 'styles') |
| 21 | + .replace('./app.component.css', '__STYLE_MARKER__'); |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + for (const aot of [true, false]) { |
| 26 | + describe(`[${aot ? 'AOT' : 'JIT'}]`, () => { |
| 27 | + it('supports SCSS inline component styles when set to "scss"', async () => { |
| 28 | + harness.useTarget('build', { |
| 29 | + ...BASE_OPTIONS, |
| 30 | + inlineStyleLanguage: InlineStyleLanguage.Scss, |
| 31 | + aot, |
| 32 | + }); |
| 33 | + |
| 34 | + await harness.modifyFile('src/app/app.component.ts', (content) => |
| 35 | + content.replace('__STYLE_MARKER__', '$primary: indianred;\\nh1 { color: $primary; }'), |
| 36 | + ); |
| 37 | + |
| 38 | + const { result } = await harness.executeOnce(); |
| 39 | + |
| 40 | + expect(result?.success).toBe(true); |
| 41 | + harness.expectFile('dist/main.js').content.toContain('color: indianred'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('supports Sass inline component styles when set to "sass"', async () => { |
| 45 | + harness.useTarget('build', { |
| 46 | + ...BASE_OPTIONS, |
| 47 | + inlineStyleLanguage: InlineStyleLanguage.Sass, |
| 48 | + aot, |
| 49 | + }); |
| 50 | + |
| 51 | + await harness.modifyFile('src/app/app.component.ts', (content) => |
| 52 | + content.replace('__STYLE_MARKER__', '$primary: indianred\\nh1\\n\\tcolor: $primary'), |
| 53 | + ); |
| 54 | + |
| 55 | + const { result } = await harness.executeOnce(); |
| 56 | + |
| 57 | + expect(result?.success).toBe(true); |
| 58 | + harness.expectFile('dist/main.js').content.toContain('color: indianred'); |
| 59 | + }); |
| 60 | + |
| 61 | + it('supports Less inline component styles when set to "less"', async () => { |
| 62 | + harness.useTarget('build', { |
| 63 | + ...BASE_OPTIONS, |
| 64 | + inlineStyleLanguage: InlineStyleLanguage.Less, |
| 65 | + aot, |
| 66 | + }); |
| 67 | + |
| 68 | + await harness.modifyFile('src/app/app.component.ts', (content) => |
| 69 | + content.replace('__STYLE_MARKER__', '@primary: indianred;\\nh1 { color: @primary; }'), |
| 70 | + ); |
| 71 | + |
| 72 | + const { result } = await harness.executeOnce(); |
| 73 | + |
| 74 | + expect(result?.success).toBe(true); |
| 75 | + harness.expectFile('dist/main.js').content.toContain('color: indianred'); |
| 76 | + }); |
| 77 | + |
| 78 | + xit('updates produced stylesheet in watch mode', async () => { |
| 79 | + harness.useTarget('build', { |
| 80 | + ...BASE_OPTIONS, |
| 81 | + main: 'src/main.ts', |
| 82 | + inlineStyleLanguage: InlineStyleLanguage.Scss, |
| 83 | + aot, |
| 84 | + watch: true, |
| 85 | + }); |
| 86 | + |
| 87 | + await harness.modifyFile('src/app/app.component.ts', (content) => |
| 88 | + content.replace('__STYLE_MARKER__', '$primary: indianred;\\nh1 { color: $primary; }'), |
| 89 | + ); |
| 90 | + |
| 91 | + const buildCount = await harness |
| 92 | + .execute() |
| 93 | + .pipe( |
| 94 | + timeout(30000), |
| 95 | + concatMap(async ({ result }, index) => { |
| 96 | + expect(result?.success).toBe(true); |
| 97 | + |
| 98 | + switch (index) { |
| 99 | + case 0: |
| 100 | + harness.expectFile('dist/main.js').content.toContain('color: indianred'); |
| 101 | + harness.expectFile('dist/main.js').content.not.toContain('color: aqua'); |
| 102 | + |
| 103 | + await harness.modifyFile('src/app/app.component.ts', (content) => |
| 104 | + content.replace( |
| 105 | + '$primary: indianred;\\nh1 { color: $primary; }', |
| 106 | + '$primary: aqua;\\nh1 { color: $primary; }', |
| 107 | + ), |
| 108 | + ); |
| 109 | + break; |
| 110 | + case 1: |
| 111 | + harness.expectFile('dist/main.js').content.not.toContain('color: indianred'); |
| 112 | + harness.expectFile('dist/main.js').content.toContain('color: aqua'); |
| 113 | + |
| 114 | + await harness.modifyFile('src/app/app.component.ts', (content) => |
| 115 | + content.replace( |
| 116 | + '$primary: aqua;\\nh1 { color: $primary; }', |
| 117 | + '$primary: blue;\\nh1 { color: $primary; }', |
| 118 | + ), |
| 119 | + ); |
| 120 | + break; |
| 121 | + case 2: |
| 122 | + harness.expectFile('dist/main.js').content.not.toContain('color: indianred'); |
| 123 | + harness.expectFile('dist/main.js').content.not.toContain('color: aqua'); |
| 124 | + harness.expectFile('dist/main.js').content.toContain('color: blue'); |
| 125 | + break; |
| 126 | + } |
| 127 | + }), |
| 128 | + take(3), |
| 129 | + count(), |
| 130 | + ) |
| 131 | + .toPromise(); |
| 132 | + |
| 133 | + expect(buildCount).toBe(3); |
| 134 | + }); |
| 135 | + }); |
| 136 | + } |
| 137 | + }); |
| 138 | +}); |
0 commit comments