-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathivy-localize-basehref.ts
More file actions
95 lines (81 loc) · 2.85 KB
/
ivy-localize-basehref.ts
File metadata and controls
95 lines (81 loc) · 2.85 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { expectFileToMatch } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { executeBrowserTest } from '../../utils/puppeteer';
import {
baseHrefs,
browserCheck,
externalServer,
langTranslations,
setupI18nConfig,
} from './setup';
export default async function () {
// Setup i18n tests and config.
await setupI18nConfig();
// Update angular.json
await updateJsonFile('angular.json', (workspaceJson) => {
const appProject = workspaceJson.projects['test-project'];
// tslint:disable-next-line: no-any
const i18n: Record<string, any> = appProject.i18n;
i18n.sourceLocale = {
baseHref: baseHrefs['en-US'],
};
i18n.locales['fr'] = {
translation: i18n.locales['fr'],
baseHref: baseHrefs['fr'],
};
i18n.locales['de'] = {
translation: i18n.locales['de'],
baseHref: baseHrefs['de'],
};
});
// Build each locale and verify the output.
await ng('build');
for (const { lang, outputPath } of langTranslations) {
if (baseHrefs[lang] === undefined) {
throw new Error('Invalid E2E test setup: unexpected locale ' + lang);
}
// Verify the HTML lang attribute is present
await expectFileToMatch(`${outputPath}/index.html`, `lang="${lang}"`);
// Verify the HTML base HREF attribute is present
await expectFileToMatch(`${outputPath}/index.html`, `href="${baseHrefs[lang] || '/'}"`);
// Execute Application E2E tests for a production build without dev server
const { server, url } = await externalServer(outputPath, (baseHrefs[lang] as string) || '/');
try {
await executeBrowserTest({
baseUrl: url,
checkFn: (page) => browserCheck(page, lang),
});
} finally {
server.close();
}
}
// Update angular.json
await updateJsonFile('angular.json', (workspaceJson) => {
const appArchitect = workspaceJson.projects['test-project'].architect;
appArchitect['build'].options.baseHref = '/test/';
});
// Build each locale and verify the output.
await ng('build', '--configuration=development');
for (const { lang, outputPath } of langTranslations) {
// Verify the HTML base HREF attribute is present
await expectFileToMatch(`${outputPath}/index.html`, `href="/test${baseHrefs[lang] || '/'}"`);
// Execute Application E2E tests for a production build without dev server
const { server, url } = await externalServer(outputPath, '/test' + (baseHrefs[lang] || '/'));
try {
await executeBrowserTest({
baseUrl: url,
checkFn: (page) => browserCheck(page, lang),
});
} finally {
server.close();
}
}
}