Skip to content

Commit

Permalink
test: ensure i18n application E2E tests are executed
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin committed Nov 6, 2019
1 parent b200e13 commit 41e52ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
3 changes: 3 additions & 0 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
30 changes: 16 additions & 14 deletions tests/legacy-cli/e2e/tests/i18n/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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'],
],
},
Expand All @@ -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'],
],
},
Expand Down Expand Up @@ -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);
Expand All @@ -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}'));
Expand Down Expand Up @@ -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}`);
Expand Down

0 comments on commit 41e52ba

Please sign in to comment.