test(compiler-cli): add test for missingTranslation parameter

This commit is contained in:
Olivier Combe 2017-05-03 21:49:14 +02:00 committed by Matias Niemelä
parent 5856298798
commit 109229246c
1 changed files with 22 additions and 9 deletions

View File

@ -29,6 +29,7 @@ function main() {
Promise.resolve()
.then(() => codeGenTest())
.then(() => codeGenTest(true))
.then(() => i18nTest())
.then(() => lazyRoutesTest())
.then(() => {
@ -42,8 +43,9 @@ function main() {
});
}
function codeGenTest() {
function codeGenTest(forceError = false) {
const basePath = path.join(__dirname, '../ngtools_src');
const srcPath = path.join(__dirname, '../src');
const project = path.join(basePath, 'tsconfig-build.json');
const readResources: string[] = [];
const wroteFiles: string[] = [];
@ -59,6 +61,9 @@ function codeGenTest() {
config.ngOptions.basePath = basePath;
console.log(`>>> running codegen for ${project}`);
if (forceError) {
console.log(`>>> asserting that missingTranslation param with error value throws`);
}
return __NGTOOLS_PRIVATE_API_2
.codeGen({
basePath,
@ -67,9 +72,10 @@ function codeGenTest() {
angularCompilerOptions: config.ngOptions,
// i18n options.
i18nFormat: undefined,
i18nFile: undefined,
locale: undefined,
i18nFormat: 'xlf',
i18nFile: path.join(srcPath, 'messages.fi.xlf'),
locale: 'fi',
missingTranslation: forceError ? 'error' : 'ignore',
readResource: (fileName: string) => {
readResources.push(fileName);
@ -101,10 +107,17 @@ function codeGenTest() {
console.log(`done, no errors.`);
})
.catch((e: any) => {
.catch((e: Error) => {
if (forceError) {
assert(
e.message.match(`Missing translation for message`),
`Expected error message for missing translations`);
console.log(`done, error catched`);
} else {
console.error(e.stack);
console.error('Compilation failed');
throw e;
}
});
}
@ -165,7 +178,7 @@ function i18nTest() {
console.log(`done, no errors.`);
})
.catch((e: any) => {
.catch((e: Error) => {
console.error(e.stack);
console.error('Extraction failed');
throw e;