Skip to content

Commit 0ee20e1

Browse files
alan-agius4dgp1130
authored andcommitted
test: remove unnecessary extract-i18n command from i18n setup
This helps to cut down on the time taken i18n tests take to run.
1 parent ec854fc commit 0ee20e1

File tree

2 files changed

+47
-60
lines changed

2 files changed

+47
-60
lines changed

tests/legacy-cli/e2e/tests/i18n/ivy-localize-sourcemaps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default async function () {
66
// Setup i18n tests and config.
77
await setupI18nConfig();
88

9-
const { stderr } = await ng('build', '--source-map');
9+
await ng('build', '--source-map');
1010

1111
for (const { outputPath } of langTranslations) {
1212
// Ensure sourcemap for modified file contains content

tests/legacy-cli/e2e/tests/i18n/setup.ts

+46-59
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
import express from 'express';
2-
import { resolve } from 'path';
2+
import { dirname, resolve } from 'path';
33
import { getGlobalVariable } from '../../utils/env';
4-
import {
5-
appendToFile,
6-
copyFile,
7-
expectFileToExist,
8-
expectFileToMatch,
9-
replaceInFile,
10-
writeFile,
11-
} from '../../utils/fs';
4+
import { appendToFile, copyFile, createDir, replaceInFile, writeFile } from '../../utils/fs';
125
import { installPackage } from '../../utils/packages';
13-
import { ng } from '../../utils/process';
146
import { updateJsonFile } from '../../utils/project';
157
import { readNgVersion } from '../../utils/version';
168
import { Server } from 'http';
179
import { AddressInfo } from 'net';
1810

1911
// Configurations for each locale.
12+
const translationFile = 'src/locale/messages.xlf';
2013
export const baseDir = 'dist/test-project';
2114
export const langTranslations = [
2215
{
@@ -96,45 +89,13 @@ export async function externalServer(outputPath: string, baseUrl = '/'): Promise
9689
});
9790
}
9891

99-
export const formats = {
100-
'xlf': {
101-
ext: 'xlf',
102-
sourceCheck: 'source-language="en-US"',
103-
replacements: [[/source/g, 'target']],
104-
},
105-
'xlf2': {
106-
ext: 'xlf',
107-
sourceCheck: 'srcLang="en-US"',
108-
replacements: [[/source/g, 'target']],
109-
},
110-
'xmb': {
111-
ext: 'xmb',
112-
sourceCheck: '<!DOCTYPE messagebundle',
113-
replacements: [
114-
[/messagebundle/g, 'translationbundle'],
115-
[/msg/g, 'translation'],
116-
[/<source>.*?<\/source>/g, ''],
117-
],
118-
},
119-
'json': {
120-
ext: 'json',
121-
sourceCheck: '"locale": "en-US"',
122-
replacements: [] as RegExp[][],
123-
},
124-
'arb': {
125-
ext: 'arb',
126-
sourceCheck: '"@@locale": "en-US"',
127-
replacements: [] as RegExp[][],
128-
},
129-
};
130-
13192
export const baseHrefs: { [l: string]: string } = {
13293
'en-US': '/en/',
13394
fr: '/fr-FR/',
13495
de: '',
13596
};
13697

137-
export async function setupI18nConfig(format: keyof typeof formats = 'xlf') {
98+
export async function setupI18nConfig() {
13899
// Add component with i18n content, both translations and localeData (plural, dates).
139100
await writeFile(
140101
'src/app/app.component.ts',
@@ -162,6 +123,41 @@ export async function setupI18nConfig(format: keyof typeof formats = 'xlf') {
162123
`,
163124
);
164125

126+
await createDir(dirname(translationFile));
127+
await writeFile(
128+
translationFile,
129+
`
130+
<?xml version="1.0" encoding="UTF-8" ?>
131+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
132+
<file source-language="en-US" datatype="plaintext" original="ng2.template">
133+
<body>
134+
<trans-unit id="4286451273117902052" datatype="html">
135+
<source>Hello <x id="INTERPOLATION" equiv-text="{{ title }}"/>! </source>
136+
<context-group purpose="location">
137+
<context context-type="sourcefile">src/app/app.component.html</context>
138+
<context context-type="linenumber">2,3</context>
139+
</context-group>
140+
<note priority="1" from="description">An introduction header for this sample</note>
141+
</trans-unit>
142+
<trans-unit id="4606963464835766483" datatype="html">
143+
<source>Updated <x id="ICU" equiv-text="{minutes, plural, =0 {just now} =1 {one minute ago} other {{{minutes}} minutes ago}}" xid="1887283401472369100"/></source>
144+
<context-group purpose="location">
145+
<context context-type="sourcefile">src/app/app.component.html</context>
146+
<context context-type="linenumber">5,6</context>
147+
</context-group>
148+
</trans-unit>
149+
<trans-unit id="2002272803511843863" datatype="html">
150+
<source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION"/> minutes ago}}</source>
151+
<context-group purpose="location">
152+
<context context-type="sourcefile">src/app/app.component.html</context>
153+
<context context-type="linenumber">5,6</context>
154+
</context-group>
155+
</trans-unit>
156+
</body>
157+
</file>
158+
</xliff>`,
159+
);
160+
165161
// Add a dynamic import to ensure syntax is supported
166162
// ng serve support: https://github.com/angular/angular-cli/issues/16248
167163
await writeFile('src/app/dynamic.ts', `export const abc = 5;`);
@@ -241,11 +237,10 @@ export async function setupI18nConfig(format: keyof typeof formats = 'xlf') {
241237
if (lang === sourceLocale) {
242238
i18n.sourceLocale = lang;
243239
} else {
244-
i18n.locales[lang] = `src/locale/messages.${lang}.${formats[format].ext}`;
240+
i18n.locales[lang] = `src/locale/messages.${lang}.xlf`;
245241
}
246242

247243
buildConfigs[lang] = { localize: [lang] };
248-
249244
serveConfigs[lang] = { browserTarget: `test-project:build:${lang}` };
250245
e2eConfigs[lang] = {
251246
specs: [`./src/app.${lang}.e2e-spec.ts`],
@@ -259,32 +254,24 @@ export async function setupI18nConfig(format: keyof typeof formats = 'xlf') {
259254
if (getGlobalVariable('argv')['ng-snapshots']) {
260255
localizeVersion = require('../../ng-snapshot/package.json').dependencies['@angular/localize'];
261256
}
262-
await installPackage(localizeVersion);
263257

264-
// Extract the translation messages.
265-
await ng('extract-i18n', '--output-path=src/locale', `--format=${format}`);
266-
const translationFile = `src/locale/messages.${formats[format].ext}`;
267-
await expectFileToExist(translationFile);
268-
await expectFileToMatch(translationFile, formats[format].sourceCheck);
269-
270-
if (format !== 'json') {
271-
await expectFileToMatch(translationFile, `An introduction header for this sample`);
272-
}
258+
await installPackage(localizeVersion);
273259

274260
// Make translations for each language.
275261
for (const { lang, translationReplacements } of langTranslations) {
276262
if (lang != sourceLocale) {
277-
await copyFile(translationFile, `src/locale/messages.${lang}.${formats[format].ext}`);
263+
await copyFile(translationFile, `src/locale/messages.${lang}.xlf`);
278264
for (const replacements of translationReplacements!) {
279265
await replaceInFile(
280-
`src/locale/messages.${lang}.${formats[format].ext}`,
266+
`src/locale/messages.${lang}.xlf`,
281267
new RegExp(replacements[0], 'g'),
282268
replacements[1] as string,
283269
);
284270
}
285-
for (const replacement of formats[format].replacements) {
271+
272+
for (const replacement of [[/source/g, 'target']]) {
286273
await replaceInFile(
287-
`src/locale/messages.${lang}.${formats[format].ext}`,
274+
`src/locale/messages.${lang}.xlf`,
288275
new RegExp(replacement[0], 'g'),
289276
replacement[1] as string,
290277
);

0 commit comments

Comments
 (0)