@@ -11,6 +11,7 @@ var treeKill = require('tree-kill');
1111var child_process = require ( 'child_process' ) ;
1212var ng = require ( '../helpers/ng' ) ;
1313var root = path . join ( process . cwd ( ) , 'tmp' ) ;
14+ var repoPkgJson = require ( '../../package.json' ) ;
1415
1516function existsSync ( path ) {
1617 try {
@@ -22,6 +23,8 @@ function existsSync(path) {
2223}
2324
2425const ngBin = `node ${ path . join ( process . cwd ( ) , 'bin' , 'ng' ) } ` ;
26+ const it_mobile = isMobileTest ( ) ? it : function ( ) { } ;
27+ const it_not_mobile = isMobileTest ( ) ? function ( ) { } : it ;
2528
2629describe ( 'Basic end-to-end Workflow' , function ( ) {
2730 before ( conf . setup ) ;
@@ -36,20 +39,35 @@ describe('Basic end-to-end Workflow', function () {
3639 testArgs . push ( 'Chrome_travis_ci' ) ;
3740 }
3841
42+
43+ // We don't want to use npm link because then npm dependencies
44+ // that only exist in the project will not be accessible to CLI
45+ // This is particularly problematic for --mobile, which uses Universal
46+ // libs as part of the build process.
47+ // Instead, we'll pack CLI as a tarball
3948 it ( 'Installs angular-cli correctly' , function ( ) {
4049 this . timeout ( 300000 ) ;
4150
42- sh . exec ( 'npm link' , { silent : true } ) ;
51+ sh . exec ( 'npm pack' , { silent : true } ) ;
52+ expect ( existsSync ( path . join ( process . cwd ( ) , `angular-cli-${ repoPkgJson . version } .tgz` ) ) ) ;
4353 return tmp . setup ( './tmp' ) . then ( function ( ) {
4454 process . chdir ( './tmp' ) ;
45- expect ( existsSync ( path . join ( process . cwd ( ) , 'bin' , 'ng' ) ) ) ;
4655 } ) ;
4756 } ) ;
4857
58+
4959 it ( 'Can create new project using `ng new test-project`' , function ( ) {
5060 this . timeout ( 4200000 ) ;
51-
52- return ng ( [ 'new' , 'test-project' , '--link-cli=true' ] ) . then ( function ( ) {
61+ let args = [ '--skip-npm' ] ;
62+ // If testing in the mobile matrix on Travis, create project with mobile flag
63+ if ( isMobileTest ( ) ) {
64+ args = args . concat ( [ '--mobile' ] ) ;
65+ }
66+ return ng ( [ 'new' , 'test-project' ] . concat ( args ) ) . then ( function ( ) {
67+ // Install Angular CLI from packed version
68+ let tarball = path . resolve ( root , `../angular-cli-${ repoPkgJson . version } .tgz` ) ;
69+ sh . exec ( `npm install && npm install ${ tarball } ` ) ;
70+ sh . exec ( `rm ${ tarball } ` ) ;
5371 expect ( existsSync ( path . join ( root , 'test-project' ) ) ) ;
5472 } ) ;
5573 } ) ;
@@ -66,14 +84,32 @@ describe('Basic end-to-end Workflow', function () {
6684 // stuck to the first build done
6785 sh . exec ( `${ ngBin } build -prod` ) ;
6886 expect ( existsSync ( path . join ( process . cwd ( ) , 'dist' ) ) ) . to . be . equal ( true ) ;
69- var mainBundlePath = path . join ( process . cwd ( ) , 'dist' , 'main.js' ) ;
70- var mainBundleContent = fs . readFileSync ( mainBundlePath , { encoding : 'utf8' } ) ;
71- // production: true minimized turns into production:!0
72- expect ( mainBundleContent ) . to . include ( 'production:!0' ) ;
87+ if ( ! isMobileTest ( ) ) {
88+ var mainBundlePath = path . join ( process . cwd ( ) , 'dist' , 'main.js' ) ;
89+ var mainBundleContent = fs . readFileSync ( mainBundlePath , { encoding : 'utf8' } ) ;
90+ // production: true minimized turns into production:!0
91+ expect ( mainBundleContent ) . to . include ( 'production:!0' ) ;
92+ }
93+
7394 // Also does not create new things in GIT.
7495 expect ( sh . exec ( 'git status --porcelain' ) . output ) . to . be . equal ( undefined ) ;
7596 } ) ;
7697
98+ it_mobile ( 'Enables mobile-specific production features' , ( ) => {
99+ let index = fs . readFileSync ( path . join ( process . cwd ( ) , 'dist/index.html' ) , 'utf-8' ) ;
100+ // Service Worker
101+ expect ( index . includes ( 'if (\'serviceWorker\' in navigator) {' ) ) . to . be . equal ( true ) ;
102+ expect ( existsSync ( path . join ( process . cwd ( ) , 'dist/worker.js' ) ) ) . to . be . equal ( true ) ;
103+
104+ // Asynchronous bundle
105+ expect ( index . includes ( '<script src="/app-concat.js" async=""></script>' ) ) . to . be . equal ( true ) ;
106+ expect ( existsSync ( path . join ( process . cwd ( ) , 'dist/app-concat.js' ) ) ) . to . be . equal ( true ) ;
107+
108+ // App Manifest
109+ expect ( index . includes ( '<link rel="manifest" href="/manifest.webapp">' ) ) . to . be . equal ( true ) ;
110+ expect ( existsSync ( path . join ( process . cwd ( ) , 'dist/manifest.webapp' ) ) ) . to . be . equal ( true ) ;
111+ } ) ;
112+
77113 it ( 'Can run `ng build` in created project' , function ( ) {
78114 this . timeout ( 420000 ) ;
79115
@@ -95,6 +131,17 @@ describe('Basic end-to-end Workflow', function () {
95131 } ) ;
96132 } ) ;
97133
134+ it_mobile ( 'Does not include mobile prod features' , ( ) => {
135+ let index = fs . readFileSync ( path . join ( process . cwd ( ) , 'dist/index.html' ) , 'utf-8' ) ;
136+ // Service Worker
137+ expect ( index . includes ( 'if (\'serviceWorker\' in navigator) {' ) ) . to . be . equal ( false ) ;
138+ expect ( existsSync ( path . join ( process . cwd ( ) , 'dist/worker.js' ) ) ) . to . be . equal ( false ) ;
139+
140+ // Asynchronous bundle
141+ expect ( index . includes ( '<script src="/app-concat.js" async></script>' ) ) . to . be . equal ( false ) ;
142+ expect ( existsSync ( path . join ( process . cwd ( ) , 'dist/app-concat.js' ) ) ) . to . be . equal ( false ) ;
143+ } ) ;
144+
98145 it ( 'lints' , ( ) => {
99146 this . timeout ( 420000 ) ;
100147
@@ -393,7 +440,9 @@ describe('Basic end-to-end Workflow', function () {
393440 } ) ;
394441 } ) ;
395442
396- it ( 'Turn on `noImplicitAny` in tsconfig.json and rebuild' , function ( ) {
443+ // This test causes complications with path resolution in TS broccoli plugin,
444+ // and isn't mobile specific
445+ it_not_mobile ( 'Turn on `noImplicitAny` in tsconfig.json and rebuild' , function ( ) {
397446 this . timeout ( 420000 ) ;
398447
399448 const configFilePath = path . join ( process . cwd ( ) , 'src' , 'tsconfig.json' ) ;
@@ -410,7 +459,7 @@ describe('Basic end-to-end Workflow', function () {
410459 } ) ;
411460 } ) ;
412461
413- it ( 'Turn on path mapping in tsconfig.json and rebuild' , function ( ) {
462+ it_not_mobile ( 'Turn on path mapping in tsconfig.json and rebuild' , function ( ) {
414463 this . timeout ( 420000 ) ;
415464
416465 const configFilePath = path . join ( process . cwd ( ) , 'src' , 'tsconfig.json' ) ;
@@ -485,3 +534,7 @@ describe('Basic end-to-end Workflow', function () {
485534 } ) ;
486535 } ) ;
487536} ) ;
537+
538+ function isMobileTest ( ) {
539+ return ! ! process . env [ 'MOBILE_TEST' ] ;
540+ }
0 commit comments