|
| 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 { buildApplication } from '../../index'; |
| 10 | +import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; |
| 11 | + |
| 12 | +describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { |
| 13 | + describe('Option: "fonts.inline"', () => { |
| 14 | + beforeEach(async () => { |
| 15 | + await harness.modifyFile('/src/index.html', (content) => |
| 16 | + content.replace( |
| 17 | + '<head>', |
| 18 | + `<head><link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`, |
| 19 | + ), |
| 20 | + ); |
| 21 | + |
| 22 | + await harness.writeFile( |
| 23 | + 'src/styles.css', |
| 24 | + '@import url(https://fonts.googleapis.com/css?family=Roboto:300,400,500);', |
| 25 | + ); |
| 26 | + |
| 27 | + await harness.writeFile( |
| 28 | + 'src/app/app.component.css', |
| 29 | + '@import url(https://fonts.googleapis.com/css?family=Roboto:300,400,500);', |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
| 33 | + it(`should not inline fonts when fonts optimization is set to false`, async () => { |
| 34 | + harness.useTarget('build', { |
| 35 | + ...BASE_OPTIONS, |
| 36 | + optimization: { |
| 37 | + scripts: true, |
| 38 | + styles: true, |
| 39 | + fonts: false, |
| 40 | + }, |
| 41 | + styles: ['src/styles.css'], |
| 42 | + }); |
| 43 | + |
| 44 | + const { result } = await harness.executeOnce(); |
| 45 | + |
| 46 | + expect(result?.success).toBeTrue(); |
| 47 | + for (const file of ['styles.css', 'index.html', 'main.js']) { |
| 48 | + harness |
| 49 | + .expectFile(`dist/browser/${file}`) |
| 50 | + .content.toContain(`https://fonts.googleapis.com/css?family=Roboto:300,400,500`); |
| 51 | + } |
| 52 | + }); |
| 53 | + |
| 54 | + it(`should inline fonts when fonts optimization is unset`, async () => { |
| 55 | + harness.useTarget('build', { |
| 56 | + ...BASE_OPTIONS, |
| 57 | + optimization: { |
| 58 | + scripts: true, |
| 59 | + styles: true, |
| 60 | + fonts: undefined, |
| 61 | + }, |
| 62 | + styles: ['src/styles.css'], |
| 63 | + }); |
| 64 | + |
| 65 | + const { result } = await harness.executeOnce(); |
| 66 | + |
| 67 | + expect(result?.success).toBeTrue(); |
| 68 | + for (const file of ['styles.css', 'index.html', 'main.js']) { |
| 69 | + harness |
| 70 | + .expectFile(`dist/browser/${file}`) |
| 71 | + .content.not.toContain(`https://fonts.googleapis.com/css?family=Roboto:300,400,500`); |
| 72 | + harness |
| 73 | + .expectFile(`dist/browser/${file}`) |
| 74 | + .content.toMatch(/@font-face{font-family:'?Roboto/); |
| 75 | + } |
| 76 | + }); |
| 77 | + |
| 78 | + it(`should inline fonts when fonts optimization is true`, async () => { |
| 79 | + harness.useTarget('build', { |
| 80 | + ...BASE_OPTIONS, |
| 81 | + optimization: { |
| 82 | + scripts: true, |
| 83 | + styles: true, |
| 84 | + fonts: true, |
| 85 | + }, |
| 86 | + styles: ['src/styles.css'], |
| 87 | + }); |
| 88 | + |
| 89 | + const { result } = await harness.executeOnce(); |
| 90 | + |
| 91 | + expect(result?.success).toBeTrue(); |
| 92 | + for (const file of ['styles.css', 'index.html', 'main.js']) { |
| 93 | + harness |
| 94 | + .expectFile(`dist/browser/${file}`) |
| 95 | + .content.not.toContain(`https://fonts.googleapis.com/css?family=Roboto:300,400,500`); |
| 96 | + harness |
| 97 | + .expectFile(`dist/browser/${file}`) |
| 98 | + .content.toMatch(/@font-face{font-family:'?Roboto/); |
| 99 | + } |
| 100 | + }); |
| 101 | + }); |
| 102 | +}); |
0 commit comments