|
| 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 | +/* eslint-disable max-len */ |
| 10 | +import fetch from 'node-fetch'; // eslint-disable-line import/no-extraneous-dependencies |
| 11 | +import { concatMap, count, take, timeout } from 'rxjs/operators'; |
| 12 | +import { URL } from 'url'; |
| 13 | +import { serveWebpackBrowser } from '../../index'; |
| 14 | +import { |
| 15 | + BASE_OPTIONS, |
| 16 | + BUILD_TIMEOUT, |
| 17 | + DEV_SERVER_BUILDER_INFO, |
| 18 | + describeBuilder, |
| 19 | + setupBrowserTarget, |
| 20 | +} from '../setup'; |
| 21 | + |
| 22 | +describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => { |
| 23 | + describe('Behavior: "i18n $localize calls are replaced during watching"', () => { |
| 24 | + beforeEach(() => { |
| 25 | + harness.useProject('test', { |
| 26 | + root: '.', |
| 27 | + sourceRoot: 'src', |
| 28 | + cli: { |
| 29 | + cache: { |
| 30 | + enabled: false, |
| 31 | + }, |
| 32 | + }, |
| 33 | + i18n: { |
| 34 | + sourceLocale: { |
| 35 | + 'code': 'fr', |
| 36 | + }, |
| 37 | + }, |
| 38 | + }); |
| 39 | + |
| 40 | + setupBrowserTarget(harness, { localize: ['fr'] }); |
| 41 | + }); |
| 42 | + |
| 43 | + it('$localize are replaced in watch', async () => { |
| 44 | + harness.useTarget('serve', { |
| 45 | + ...BASE_OPTIONS, |
| 46 | + }); |
| 47 | + |
| 48 | + await harness.writeFile( |
| 49 | + 'src/app/app.component.html', |
| 50 | + ` |
| 51 | + <p id="hello" i18n="An introduction header for this sample">Hello {{ title }}! </p> |
| 52 | + `, |
| 53 | + ); |
| 54 | + |
| 55 | + const buildCount = await harness |
| 56 | + .execute() |
| 57 | + .pipe( |
| 58 | + timeout(BUILD_TIMEOUT), |
| 59 | + concatMap(async ({ result }, index) => { |
| 60 | + expect(result?.success).toBe(true); |
| 61 | + |
| 62 | + const response = await fetch(new URL('main.js', `${result?.baseUrl}`)); |
| 63 | + expect(await response?.text()).not.toContain('$localize`:'); |
| 64 | + |
| 65 | + switch (index) { |
| 66 | + case 0: { |
| 67 | + await harness.modifyFile('src/app/app.component.html', (content) => |
| 68 | + content.replace('introduction', 'intro'), |
| 69 | + ); |
| 70 | + break; |
| 71 | + } |
| 72 | + } |
| 73 | + }), |
| 74 | + take(2), |
| 75 | + count(), |
| 76 | + ) |
| 77 | + .toPromise(); |
| 78 | + |
| 79 | + expect(buildCount).toBe(2); |
| 80 | + }); |
| 81 | + }); |
| 82 | +}); |
0 commit comments