/**
* @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.io/license
*/
import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing';
import {loadStandardTestFiles} from '@angular/compiler-cli/src/ngtsc/testing';
import {platform} from 'os';
import {NgtscTestEnvironment} from './env';
const testFiles = loadStandardTestFiles({fakeCore: true, fakeCommon: true});
runInEachFileSystem(os => {
let env!: NgtscTestEnvironment;
if (os === 'Windows' || platform() === 'win32') {
// xi18n tests are skipped on Windows as the paths in the expected message files are platform-
// sensitive. These tests will be deleted when xi18n is removed, so it's not a major priority
// to make them work with Windows.
return;
}
describe('ngtsc xi18n', () => {
beforeEach(() => {
env = NgtscTestEnvironment.setup(testFiles);
env.tsconfig();
writeTestCode(env);
});
it('should extract xmb', () => {
env.driveXi18n('xmb', 'messages.xmb');
expect(env.getContents('messages.xmb')).toEqual(EXPECTED_XMB);
});
it('should extract xlf', () => {
// Note that only in XLF mode do we pass a locale into the extraction.
env.driveXi18n('xlf', 'messages.xlf', 'fr');
expect(env.getContents('messages.xlf')).toEqual(EXPECTED_XLIFF);
});
it('should extract xlf', () => {
env.driveXi18n('xlf2', 'messages.xliff2.xlf');
expect(env.getContents('messages.xliff2.xlf')).toEqual(EXPECTED_XLIFF2);
});
it('should not emit js', () => {
env.driveXi18n('xlf2', 'messages.xliff2.xlf');
env.assertDoesNotExist('src/module.js');
});
});
});
const EXPECTED_XMB = `
]>
${welcomeMessage}
`); env.write('src/comp1.ts', ` import {Component} from '@angular/core'; @Component({ selector: 'basic', templateUrl: './basic.html', }) export class BasicCmp1 {}`); env.write('src/comp2.ts', ` import {Component} from '@angular/core'; @Component({ selector: 'basic2', template: \`${welcomeMessage}
\`, }) export class BasicCmp2 {} @Component({ selector: 'basic4', template: \`${welcomeMessage}
\`, }) export class BasicCmp4 {}`); env.write('src/comp3.ts', ` import {Component} from '@angular/core'; @Component({ selector: 'basic3', templateUrl: './basic.html', }) export class BasicCmp3 {}`); env.write('src/placeholders.html', `