-
Notifications
You must be signed in to change notification settings - Fork 12k
/
ivy-localize-es2015.ts
55 lines (47 loc) · 2.04 KB
/
ivy-localize-es2015.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { expectFileNotToExist, expectFileToMatch, readFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { expectToFail } from '../../utils/utils';
import { externalServer, langTranslations, setupI18nConfig } from './setup';
export default async function () {
// Setup i18n tests and config.
await setupI18nConfig();
const { stderr } = await ng('build', '--source-map');
if (/Locale data for .+ cannot be found/.test(stderr)) {
throw new Error(
`A warning for a locale not found was shown. This should not happen.\n\nSTDERR:\n${stderr}\n`,
);
}
for (const { lang, outputPath, translation } of langTranslations) {
await expectFileToMatch(`${outputPath}/main.js`, translation.helloPartial);
await expectToFail(() => expectFileToMatch(`${outputPath}/main.js`, '$localize`'));
await expectFileNotToExist(`${outputPath}/main-es5.js`);
// Ensure sourcemap for modified file contains content
const mainSourceMap = JSON.parse(await readFile(`${outputPath}/main.js.map`));
if (
mainSourceMap.version !== 3 ||
!Array.isArray(mainSourceMap.sources) ||
typeof mainSourceMap.mappings !== 'string'
) {
throw new Error('invalid localized sourcemap for main.js');
}
// Ensure locale is inlined (@angular/localize plugin inlines `$localize.locale` references)
// The only reference in a new application is in @angular/core
await expectFileToMatch(`${outputPath}/vendor.js`, lang);
// Verify the HTML lang attribute is present
await expectFileToMatch(`${outputPath}/index.html`, `lang="${lang}"`);
// Execute Application E2E tests with dev server
await ng('e2e', `--configuration=${lang}`, '--port=0');
// Execute Application E2E tests for a production build without dev server
const server = externalServer(outputPath, `/${lang}/`);
try {
await ng(
'e2e',
`--configuration=${lang}`,
'--dev-server-target=',
`--base-url=http://localhost:4200/${lang}/`,
);
} finally {
server.close();
}
}
}