@@ -7,6 +7,7 @@ import { updateJsonFile } from '../../utils/project';
77import { readNgVersion } from '../../utils/version' ;
88import { Server } from 'node:http' ;
99import { AddressInfo } from 'node:net' ;
10+ import type { Page } from 'puppeteer' ;
1011
1112// Configurations for each locale.
1213const translationFile = 'src/locale/messages.xlf' ;
@@ -61,6 +62,35 @@ export const langTranslations = [
6162] ;
6263export const sourceLocale = langTranslations [ 0 ] . lang ;
6364
65+ export async function browserCheck ( page : Page , lang : string ) {
66+ const translation = langTranslations . find ( ( t ) => t . lang === lang ) ?. translation ;
67+ if ( ! translation ) {
68+ throw new Error ( `Could not find translation for language '${ lang } '` ) ;
69+ }
70+
71+ const getParagraph = async ( id : string ) => page . $eval ( `p#${ id } ` , ( el ) => el . textContent ?. trim ( ) ) ;
72+
73+ const hello = await getParagraph ( 'hello' ) ;
74+ if ( hello !== translation . hello ) {
75+ throw new Error ( `Expected 'hello' to be '${ translation . hello } ', but got '${ hello } '.` ) ;
76+ }
77+
78+ const locale = await getParagraph ( 'locale' ) ;
79+ if ( locale !== lang ) {
80+ throw new Error ( `Expected 'locale' to be '${ lang } ', but got '${ locale } '.` ) ;
81+ }
82+
83+ const date = await getParagraph ( 'date' ) ;
84+ if ( date !== translation . date ) {
85+ throw new Error ( `Expected 'date' to be '${ translation . date } ', but got '${ date } '.` ) ;
86+ }
87+
88+ const plural = await getParagraph ( 'plural' ) ;
89+ if ( plural !== translation . plural ) {
90+ throw new Error ( `Expected 'plural' to be '${ translation . plural } ', but got '${ plural } '.` ) ;
91+ }
92+ }
93+
6494export interface ExternalServer {
6595 readonly server : Server ;
6696 readonly port : number ;
@@ -173,47 +203,12 @@ export async function setupI18nConfig() {
173203 ` ,
174204 ) ;
175205
176- // Add e2e specs for each lang.
177- for ( const { lang, translation } of langTranslations ) {
178- await writeFile (
179- `./e2e/src/app.${ lang } .e2e-spec.ts` ,
180- `
181- import { browser, logging, element, by } from 'protractor';
182-
183- describe('workspace-project App', () => {
184- const getParagraph = async (name: string) => element(by.css('app-root p#' + name)).getText();
185- beforeEach(() => browser.get(browser.baseUrl));
186- afterEach(async () => {
187- // Assert that there are no errors emitted from the browser
188- const logs = await browser.manage().logs().get(logging.Type.BROWSER);
189- expect(logs).not.toContain(jasmine.objectContaining({
190- level: logging.Level.SEVERE,
191- } as logging.Entry));
192- });
193-
194- it('should display welcome message', async () =>
195- expect(await getParagraph('hello')).toEqual('${ translation . hello } '));
196-
197- it('should display locale', async () =>
198- expect(await getParagraph('locale')).toEqual('${ lang } '));
199-
200- it('should display localized date', async () =>
201- expect(await getParagraph('date')).toEqual('${ translation . date } '));
202-
203- it('should display pluralized message', async () =>
204- expect(await getParagraph('plural')).toEqual('${ translation . plural } '));
205- });
206- ` ,
207- ) ;
208- }
209-
210206 // Update angular.json to build, serve, and test each locale.
211207 await updateJsonFile ( 'angular.json' , ( workspaceJson ) => {
212208 const appProject = workspaceJson . projects [ 'test-project' ] ;
213209 const appArchitect = workspaceJson . projects [ 'test-project' ] . architect ;
214210 const buildConfigs = appArchitect [ 'build' ] . configurations ;
215211 const serveConfigs = appArchitect [ 'serve' ] . configurations ;
216- const e2eConfigs = appArchitect [ 'e2e' ] . configurations ;
217212
218213 appArchitect [ 'build' ] . defaultConfiguration = undefined ;
219214
@@ -245,10 +240,6 @@ export async function setupI18nConfig() {
245240
246241 buildConfigs [ lang ] = { localize : [ lang ] } ;
247242 serveConfigs [ lang ] = { buildTarget : `test-project:build:${ lang } ` } ;
248- e2eConfigs [ lang ] = {
249- specs : [ `./src/app.${ lang } .e2e-spec.ts` ] ,
250- devServerTarget : `test-project:serve:${ lang } ` ,
251- } ;
252243 }
253244 } ) ;
254245
0 commit comments