-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathworks_spec.ts
166 lines (117 loc) · 5.8 KB
/
works_spec.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
* @license
* Copyright Google Inc. 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.io/license
*/
import { Architect } from '@angular-devkit/architect';
import { join, logging, normalize, virtualFs } from '@angular-devkit/core';
import { createArchitect, extractI18nTargetSpec, host, veEnabled } from '../test-utils';
describe('Extract i18n Target', () => {
const extractionFile = join(normalize('src'), 'messages.xlf');
let architect: Architect;
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
});
afterEach(() => host.restore().toPromise());
it('generates an extraction file', async () => {
host.appendToFile('src/app/app.component.html', '<p i18n>i18n test</p>');
const run = await architect.scheduleTarget(extractI18nTargetSpec);
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
await run.stop();
const exists = host.scopedSync().exists(extractionFile);
expect(exists).toBe(true);
if (exists) {
const content = virtualFs.fileBufferToString(host.scopedSync().read(extractionFile));
expect(content).toContain('i18n test');
}
}, 30000);
it('does not emit the application files', async () => {
host.appendToFile('src/app/app.component.html', '<p i18n>i18n test</p>');
const run = await architect.scheduleTarget(extractI18nTargetSpec);
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
await run.stop();
expect(host.scopedSync().exists(normalize('dist/app/main.js'))).toBeFalse();
}, 30000);
it('shows errors', async () => {
const logger = new logging.Logger('');
const logs: string[] = [];
logger.subscribe(e => logs.push(e.message));
host.appendToFile('src/app/app.component.html',
'<p i18n>Hello world <span i18n>inner</span></p>');
const run = await architect.scheduleTarget(extractI18nTargetSpec, undefined, { logger });
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: false }));
await run.stop();
const msg = veEnabled
? 'Could not mark an element as translatable inside a translatable section'
: 'Cannot mark an element as translatable inside of a translatable section';
expect(logs.join()).toMatch(msg);
}, 30000);
// DISABLED_FOR_IVY
(veEnabled ? it : xit)('supports locale', async () => {
host.appendToFile('src/app/app.component.html', '<p i18n>i18n test</p>');
const overrides = { i18nLocale: 'fr' };
const run = await architect.scheduleTarget(extractI18nTargetSpec, overrides);
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
await run.stop();
expect(host.scopedSync().exists((extractionFile))).toBe(true);
expect(virtualFs.fileBufferToString(host.scopedSync().read(extractionFile)))
.toContain('source-language="fr"');
}, 30000);
it('supports out file', async () => {
host.appendToFile('src/app/app.component.html', '<p i18n>i18n test</p>');
const outFile = 'messages.fr.xlf';
const extractionFile = join(normalize('src'), outFile);
const overrides = { outFile };
const run = await architect.scheduleTarget(extractI18nTargetSpec, overrides);
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
await run.stop();
expect(host.scopedSync().exists(extractionFile)).toBe(true);
expect(virtualFs.fileBufferToString(host.scopedSync().read(extractionFile)))
.toMatch(/i18n test/);
}, 30000);
it('supports output path', async () => {
host.appendToFile('src/app/app.component.html', '<p i18n>i18n test</p>');
// Note: this folder will not be created automatically. It must exist beforehand.
const outputPath = 'src/i18n';
const extractionFile = join(normalize('src'), 'i18n', 'messages.xlf');
const overrides = { outputPath };
const run = await architect.scheduleTarget(extractI18nTargetSpec, overrides);
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
await run.stop();
expect(host.scopedSync().exists(extractionFile)).toBe(true);
expect(virtualFs.fileBufferToString(host.scopedSync().read(extractionFile)))
.toMatch(/i18n test/);
}, 30000);
it('supports i18n format', async () => {
host.appendToFile('src/app/app.component.html', '<p i18n>i18n test</p>');
const extractionFile = join(normalize('src'), 'messages.xmb');
const overrides = { format: 'xmb' };
const run = await architect.scheduleTarget(extractI18nTargetSpec, overrides);
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
await run.stop();
expect(host.scopedSync().exists(extractionFile)).toBe(true);
expect(virtualFs.fileBufferToString(host.scopedSync().read(extractionFile)))
.toMatch(/i18n test/);
}, 30000);
// DISABLED_FOR_VE
(veEnabled ? xit : it)('issues warnings for duplicate message identifiers', async () => {
host.appendToFile(
'src/app/app.component.ts',
'const c = $localize`:@@message-2:message contents`; const d = $localize`:@@message-2:different message contents`;',
);
const logger = new logging.Logger('');
const logs: string[] = [];
logger.subscribe((e) => logs.push(e.message));
const run = await architect.scheduleTarget(extractI18nTargetSpec, undefined, { logger });
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
await run.stop();
expect(host.scopedSync().exists(extractionFile)).toBe(true);
const fullLog = logs.join();
expect(fullLog).toContain(
'Duplicate messages with id',
);
}, 30000);
});