|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google Inc. 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 | +import { buildWebpackBrowser } from '../../index'; |
| 9 | +import { InlineStyleLanguage } from '../../schema'; |
| 10 | +import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup'; |
| 11 | + |
| 12 | +describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => { |
| 13 | + describe('Option: "inlineStyleLanguage"', () => { |
| 14 | + beforeEach(async () => { |
| 15 | + // Setup application component with inline style property |
| 16 | + await harness.modifyFile('src/app/app.component.ts', (content) => { |
| 17 | + return content |
| 18 | + .replace('styleUrls', 'styles') |
| 19 | + .replace('./app.component.css', '__STYLE_MARKER__'); |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + for (const aot of [true, false]) { |
| 24 | + describe(`[${aot ? 'AOT' : 'JIT'}]`, () => { |
| 25 | + it('supports SCSS inline component styles when set to "scss"', async () => { |
| 26 | + harness.useTarget('build', { |
| 27 | + ...BASE_OPTIONS, |
| 28 | + inlineStyleLanguage: InlineStyleLanguage.Scss, |
| 29 | + aot, |
| 30 | + }); |
| 31 | + |
| 32 | + await harness.modifyFile('src/app/app.component.ts', (content) => |
| 33 | + content.replace( |
| 34 | + '__STYLE_MARKER__', |
| 35 | + '$primary-color: green;\\nh1 { color: $primary-color; }', |
| 36 | + ), |
| 37 | + ); |
| 38 | + |
| 39 | + const { result } = await harness.executeOnce(); |
| 40 | + |
| 41 | + expect(result?.success).toBe(true); |
| 42 | + harness.expectFile('dist/main.js').content.toContain('color: green'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('supports Sass inline component styles when set to "sass"', async () => { |
| 46 | + harness.useTarget('build', { |
| 47 | + ...BASE_OPTIONS, |
| 48 | + inlineStyleLanguage: InlineStyleLanguage.Sass, |
| 49 | + aot, |
| 50 | + }); |
| 51 | + |
| 52 | + await harness.modifyFile('src/app/app.component.ts', (content) => |
| 53 | + content.replace( |
| 54 | + '__STYLE_MARKER__', |
| 55 | + '$primary-color: green\\nh1\\n\\tcolor: $primary-color', |
| 56 | + ), |
| 57 | + ); |
| 58 | + |
| 59 | + const { result } = await harness.executeOnce(); |
| 60 | + |
| 61 | + expect(result?.success).toBe(true); |
| 62 | + harness.expectFile('dist/main.js').content.toContain('color: green'); |
| 63 | + }); |
| 64 | + |
| 65 | + // Stylus currently does not function due to the sourcemap logic within the `stylus-loader` |
| 66 | + // which tries to read each stylesheet directly from disk. In this case, each stylesheet is |
| 67 | + // virtual and cannot be read from disk. This issue affects data URIs in general. |
| 68 | + // xit('supports Stylus inline component styles when set to "stylus"', async () => { |
| 69 | + // harness.useTarget('build', { |
| 70 | + // ...BASE_OPTIONS, |
| 71 | + // inlineStyleLanguage: InlineStyleLanguage.Stylus, |
| 72 | + // aot, |
| 73 | + // }); |
| 74 | + |
| 75 | + // await harness.modifyFile('src/app/app.component.ts', (content) => |
| 76 | + // content.replace( |
| 77 | + // '__STYLE_MARKER__', |
| 78 | + // '$primary-color = green;\\nh1 { color: $primary-color; }', |
| 79 | + // ), |
| 80 | + // ); |
| 81 | + |
| 82 | + // const { result } = await harness.executeOnce(); |
| 83 | + |
| 84 | + // expect(result?.success).toBe(true); |
| 85 | + // harness.expectFile('dist/main.js').content.toContain('color: green'); |
| 86 | + // }); |
| 87 | + |
| 88 | + it('supports Less inline component styles when set to "less"', async () => { |
| 89 | + harness.useTarget('build', { |
| 90 | + ...BASE_OPTIONS, |
| 91 | + inlineStyleLanguage: InlineStyleLanguage.Less, |
| 92 | + aot, |
| 93 | + }); |
| 94 | + |
| 95 | + await harness.modifyFile('src/app/app.component.ts', (content) => |
| 96 | + content.replace( |
| 97 | + '__STYLE_MARKER__', |
| 98 | + '@primary-color: green;\\nh1 { color: @primary-color; }', |
| 99 | + ), |
| 100 | + ); |
| 101 | + |
| 102 | + const { result } = await harness.executeOnce(); |
| 103 | + |
| 104 | + expect(result?.success).toBe(true); |
| 105 | + harness.expectFile('dist/main.js').content.toContain('color: green'); |
| 106 | + }); |
| 107 | + }); |
| 108 | + } |
| 109 | + }); |
| 110 | +}); |
0 commit comments