11import { ng } from '../../../utils/process' ;
2- import { expectFileToMatch , writeFile , createDir , appendToFile } from '../../../utils/fs' ;
2+ import { expectFileToMatch , writeFile , createDir , appendToFile , readFile } from '../../../utils/fs' ;
33import { expectToFail } from '../../../utils/utils' ;
4+ import { Version } from '../../../../../packages/@angular/cli/upgrade/version' ;
5+ import { SemVer } from 'semver' ;
46
57export default function ( ) {
68 return Promise . resolve ( )
@@ -22,10 +24,35 @@ export default function() {
2224 '<h1 i18n="An introduction header for this sample">Hello i18n!</h1>' ) )
2325 . then ( ( ) => ng ( 'build' , '--aot' , '--i18n-file' , 'src/locale/messages.fr.xlf' , '--i18n-format' ,
2426 'xlf' , '--locale' , 'fr' ) )
25- . then ( ( ) => ng ( 'build' , '--aot' , '--i18nFile' , 'src/locale/messages.fr.xlf' , '--i18nFormat' ,
26- 'xlf' , '--locale' , 'fr' ) )
2727 . then ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' , / B o n j o u r i 1 8 n ! / ) )
2828 . then ( ( ) => ng ( 'build' , '--aot' ) )
2929 . then ( ( ) => expectToFail ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' , / B o n j o u r i 1 8 n ! / ) ) )
30- . then ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' , / H e l l o i 1 8 n ! / ) ) ;
30+ . then ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' , / H e l l o i 1 8 n ! / ) )
31+ . then ( ( ) => appendToFile ( 'src/app/app.component.html' ,
32+ '<p i18n>Other content</p>' ) )
33+ . then ( ( ) => readFile ( 'node_modules/@angular/compiler-cli/package.json' )
34+ . then ( ( compilerCliPackage ) : any => {
35+ const version = new Version ( JSON . parse ( compilerCliPackage ) . version ) ;
36+ if ( version . major === 2 ) {
37+ return expectToFail ( ( ) => ng ( 'build' , '--aot' , '--i18nFile' , 'src/locale/messages.fr.xlf' ,
38+ '--i18nFormat' , 'xlf' , '--locale' , 'fr' , '--missingTranslation' , 'ignore' ) ) ;
39+ } else {
40+ return ng ( 'build' , '--aot' , '--i18nFile' , 'src/locale/messages.fr.xlf' , '--i18nFormat' ,
41+ 'xlf' , '--locale' , 'fr' , '--missingTranslation' , 'ignore' )
42+ . then ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' , / O t h e r c o n t e n t / ) ) ;
43+ }
44+ } )
45+ )
46+ . then ( ( ) => readFile ( 'node_modules/@angular/compiler-cli/package.json' )
47+ . then ( ( compilerCliPackage ) : any => {
48+ const version = new Version ( JSON . parse ( compilerCliPackage ) . version ) ;
49+ if ( version . isGreaterThanOrEqualTo ( new SemVer ( '4.2.0-beta.0' ) ) || version . major === 2 ) {
50+ return expectToFail ( ( ) => ng ( 'build' , '--aot' , '--i18nFile' , 'src/locale/messages.fr.xlf' ,
51+ '--i18nFormat' , 'xlf' , '--locale' , 'fr' , '--missingTranslation' , 'error' ) ) ;
52+ } else {
53+ return ng ( 'build' , '--aot' , '--i18nFile' , 'src/locale/messages.fr.xlf' ,
54+ '--i18nFormat' , 'xlf' , '--locale' , 'fr' , '--missingTranslation' , 'error' ) ;
55+ }
56+ } )
57+ ) ;
3158}
0 commit comments