test(compiler-cli): add test for missingTranslation parameter
This commit is contained in:
parent
5856298798
commit
109229246c
|
@ -29,6 +29,7 @@ function main() {
|
||||||
|
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(() => codeGenTest())
|
.then(() => codeGenTest())
|
||||||
|
.then(() => codeGenTest(true))
|
||||||
.then(() => i18nTest())
|
.then(() => i18nTest())
|
||||||
.then(() => lazyRoutesTest())
|
.then(() => lazyRoutesTest())
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
@ -42,8 +43,9 @@ function main() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function codeGenTest() {
|
function codeGenTest(forceError = false) {
|
||||||
const basePath = path.join(__dirname, '../ngtools_src');
|
const basePath = path.join(__dirname, '../ngtools_src');
|
||||||
|
const srcPath = path.join(__dirname, '../src');
|
||||||
const project = path.join(basePath, 'tsconfig-build.json');
|
const project = path.join(basePath, 'tsconfig-build.json');
|
||||||
const readResources: string[] = [];
|
const readResources: string[] = [];
|
||||||
const wroteFiles: string[] = [];
|
const wroteFiles: string[] = [];
|
||||||
|
@ -59,6 +61,9 @@ function codeGenTest() {
|
||||||
config.ngOptions.basePath = basePath;
|
config.ngOptions.basePath = basePath;
|
||||||
|
|
||||||
console.log(`>>> running codegen for ${project}`);
|
console.log(`>>> running codegen for ${project}`);
|
||||||
|
if (forceError) {
|
||||||
|
console.log(`>>> asserting that missingTranslation param with error value throws`);
|
||||||
|
}
|
||||||
return __NGTOOLS_PRIVATE_API_2
|
return __NGTOOLS_PRIVATE_API_2
|
||||||
.codeGen({
|
.codeGen({
|
||||||
basePath,
|
basePath,
|
||||||
|
@ -67,9 +72,10 @@ function codeGenTest() {
|
||||||
angularCompilerOptions: config.ngOptions,
|
angularCompilerOptions: config.ngOptions,
|
||||||
|
|
||||||
// i18n options.
|
// i18n options.
|
||||||
i18nFormat: undefined,
|
i18nFormat: 'xlf',
|
||||||
i18nFile: undefined,
|
i18nFile: path.join(srcPath, 'messages.fi.xlf'),
|
||||||
locale: undefined,
|
locale: 'fi',
|
||||||
|
missingTranslation: forceError ? 'error' : 'ignore',
|
||||||
|
|
||||||
readResource: (fileName: string) => {
|
readResource: (fileName: string) => {
|
||||||
readResources.push(fileName);
|
readResources.push(fileName);
|
||||||
|
@ -101,10 +107,17 @@ function codeGenTest() {
|
||||||
|
|
||||||
console.log(`done, no errors.`);
|
console.log(`done, no errors.`);
|
||||||
})
|
})
|
||||||
.catch((e: any) => {
|
.catch((e: Error) => {
|
||||||
console.error(e.stack);
|
if (forceError) {
|
||||||
console.error('Compilation failed');
|
assert(
|
||||||
throw e;
|
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.`);
|
console.log(`done, no errors.`);
|
||||||
})
|
})
|
||||||
.catch((e: any) => {
|
.catch((e: Error) => {
|
||||||
console.error(e.stack);
|
console.error(e.stack);
|
||||||
console.error('Extraction failed');
|
console.error('Extraction failed');
|
||||||
throw e;
|
throw e;
|
||||||
|
|
Loading…
Reference in New Issue