From 41e52ba7d28073ab685df146535f8fd375fce65f Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Tue, 5 Nov 2019 13:54:04 -0500 Subject: [PATCH] test: ensure i18n application E2E tests are executed --- .../e2e/tests/i18n/ivy-localize-server.ts | 3 ++ tests/legacy-cli/e2e/tests/i18n/legacy.ts | 30 ++++++++++--------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tests/legacy-cli/e2e/tests/i18n/ivy-localize-server.ts b/tests/legacy-cli/e2e/tests/i18n/ivy-localize-server.ts index 5411186cd02c..07b380eb136f 100644 --- a/tests/legacy-cli/e2e/tests/i18n/ivy-localize-server.ts +++ b/tests/legacy-cli/e2e/tests/i18n/ivy-localize-server.ts @@ -10,6 +10,9 @@ import { langTranslations, setupI18nConfig } from './legacy'; const snapshots = require('../../ng-snapshot/package.json'); export default async function () { + // TODO: Re-enable pending further Ivy/Universal/i18n work + return; + // Setup i18n tests and config. await setupI18nConfig(); diff --git a/tests/legacy-cli/e2e/tests/i18n/legacy.ts b/tests/legacy-cli/e2e/tests/i18n/legacy.ts index 7c92814c384b..074fe4acac3d 100644 --- a/tests/legacy-cli/e2e/tests/i18n/legacy.ts +++ b/tests/legacy-cli/e2e/tests/i18n/legacy.ts @@ -25,7 +25,7 @@ export const langTranslations = [ translation: { helloPartial: 'Bonjour', hello: 'Bonjour i18n!', - plural: 'Mis à jour Il y a 3 minutes', + plural: 'Mis à jour il y a 3 minutes', date: 'janvier', }, translationReplacements: [ @@ -34,7 +34,7 @@ export const langTranslations = [ ['Updated', 'Mis à jour'], ['just now', 'juste maintenant'], ['one minute ago', 'il y a une minute'], - ['other {', 'other {Il y a'], + [/other {/g, 'other {il y a '], ['minutes ago', 'minutes'], ], }, @@ -52,7 +52,7 @@ export const langTranslations = [ ['Updated', 'Aktualisiert'], ['just now', 'gerade jetzt'], ['one minute ago', 'vor einer Minute'], - ['other {', 'other {vor'], + [/other {/g, 'other {vor '], ['minutes ago', 'Minuten'], ], }, @@ -91,12 +91,12 @@ export async function setupI18nConfig(useLocalize = true) { // Add e2e specs for each lang. for (const { lang, translation } of langTranslations) { - await writeFile(`./src/app.${lang}.e2e-spec.ts`, ` + await writeFile(`./e2e/src/app.${lang}.e2e-spec.ts`, ` import { browser, logging, element, by } from 'protractor'; describe('workspace-project App', () => { const getParagraph = (name: string) => element(by.css('app-root p#' + name)).getText(); - beforeEach(() => browser.get(browser.baseUrl);); + beforeEach(() => browser.get(browser.baseUrl)); afterEach(async () => { // Assert that there are no errors emitted from the browser const logs = await browser.manage().logs().get(logging.Type.BROWSER); @@ -112,7 +112,7 @@ export async function setupI18nConfig(useLocalize = true) { expect(getParagraph('locale')).toEqual('${lang}')); it('should display localized date', () => - expect(getParagraph('date')).toEqual('${translation.plural}')); + expect(getParagraph('date')).toEqual('${translation.date}')); it('should display pluralized message', () => expect(getParagraph('plural')).toEqual('${translation.plural}')); @@ -190,25 +190,27 @@ export async function setupI18nConfig(useLocalize = true) { if (lang != sourceLocale) { await copyFile('src/locale/messages.xlf', `src/locale/messages.${lang}.xlf`); for (const replacements of translationReplacements) { - await replaceInFile(`src/locale/messages.${lang}.xlf`, replacements[0], replacements[1]); + await replaceInFile(`src/locale/messages.${lang}.xlf`, replacements[0], replacements[1] as string); } } } - if (useLocalize) { - // Install the localize package. - let localizeVersion = '@angular/localize@' + readNgVersion(); - if (getGlobalVariable('argv')['ng-snapshots']) { - localizeVersion = require('../../ng-snapshot/package.json').dependencies['@angular/localize']; - } - await npm('install', `${localizeVersion}`); + // Install the localize package. + let localizeVersion = '@angular/localize@' + readNgVersion(); + if (getGlobalVariable('argv')['ng-snapshots']) { + localizeVersion = require('../../ng-snapshot/package.json').dependencies['@angular/localize']; } + await npm('install', `${localizeVersion}`); } export default async function () { // Setup i18n tests and config. await setupI18nConfig(false); + // Legacy option usage with the en-US locale needs $localize + // Legacy usage did not need to process en-US and typically no i18nLocale options were present + await appendToFile('src/polyfills.ts', `import '@angular/localize/init';`); + // Build each locale and verify the output. for (const { lang, translation, outputPath } of langTranslations) { await ng('build', `--configuration=${lang}`);