-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular-devkit/build-angular): ensure
$localize
calls are repl…
…aced in watch mode When `translations` is undefined `$localize` calls are not replaced. https://github.com/angular/angular-cli/blob/2c9a33dddb38694b6940ec6981c49904de1ab636/packages/angular_devkit/build_angular/src/builders/dev-server/index.ts#L382 Closes #22435 (cherry picked from commit 426ddb6)
- Loading branch information
1 parent
d674dcd
commit 6a617ff
Showing
3 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...uild_angular/src/builders/dev-server/tests/behavior/build_localize_replaced_watch_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/* eslint-disable max-len */ | ||
import fetch from 'node-fetch'; // eslint-disable-line import/no-extraneous-dependencies | ||
import { concatMap, count, take, timeout } from 'rxjs/operators'; | ||
import { URL } from 'url'; | ||
import { serveWebpackBrowser } from '../../index'; | ||
import { | ||
BASE_OPTIONS, | ||
BUILD_TIMEOUT, | ||
DEV_SERVER_BUILDER_INFO, | ||
describeBuilder, | ||
setupBrowserTarget, | ||
} from '../setup'; | ||
|
||
describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => { | ||
describe('Behavior: "i18n $localize calls are replaced during watching"', () => { | ||
beforeEach(() => { | ||
harness.useProject('test', { | ||
root: '.', | ||
sourceRoot: 'src', | ||
cli: { | ||
cache: { | ||
enabled: false, | ||
}, | ||
}, | ||
i18n: { | ||
sourceLocale: { | ||
'code': 'fr', | ||
}, | ||
}, | ||
}); | ||
|
||
setupBrowserTarget(harness, { localize: ['fr'] }); | ||
}); | ||
|
||
it('$localize are replaced in watch', async () => { | ||
harness.useTarget('serve', { | ||
...BASE_OPTIONS, | ||
}); | ||
|
||
await harness.writeFile( | ||
'src/app/app.component.html', | ||
` | ||
<p id="hello" i18n="An introduction header for this sample">Hello {{ title }}! </p> | ||
`, | ||
); | ||
|
||
const buildCount = await harness | ||
.execute() | ||
.pipe( | ||
timeout(BUILD_TIMEOUT), | ||
concatMap(async ({ result }, index) => { | ||
expect(result?.success).toBe(true); | ||
|
||
const response = await fetch(new URL('main.js', `${result?.baseUrl}`)); | ||
expect(await response?.text()).not.toContain('$localize`:'); | ||
|
||
switch (index) { | ||
case 0: { | ||
await harness.modifyFile('src/app/app.component.html', (content) => | ||
content.replace('introduction', 'intro'), | ||
); | ||
break; | ||
} | ||
} | ||
}), | ||
take(2), | ||
count(), | ||
) | ||
.toPromise(); | ||
|
||
expect(buildCount).toBe(2); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters