@@ -11,6 +11,7 @@ var treeKill = require('tree-kill');
11
11
var child_process = require ( 'child_process' ) ;
12
12
var ng = require ( '../helpers/ng' ) ;
13
13
var root = path . join ( process . cwd ( ) , 'tmp' ) ;
14
+ var repoPkgJson = require ( '../../package.json' ) ;
14
15
15
16
function existsSync ( path ) {
16
17
try {
@@ -22,6 +23,8 @@ function existsSync(path) {
22
23
}
23
24
24
25
const ngBin = `node ${ path . join ( process . cwd ( ) , 'bin' , 'ng' ) } ` ;
26
+ const it_mobile = isMobileTest ( ) ? it : function ( ) { } ;
27
+ const it_not_mobile = isMobileTest ( ) ? function ( ) { } : it ;
25
28
26
29
describe ( 'Basic end-to-end Workflow' , function ( ) {
27
30
before ( conf . setup ) ;
@@ -36,20 +39,35 @@ describe('Basic end-to-end Workflow', function () {
36
39
testArgs . push ( 'Chrome_travis_ci' ) ;
37
40
}
38
41
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
39
48
it ( 'Installs angular-cli correctly' , function ( ) {
40
49
this . timeout ( 300000 ) ;
41
50
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` ) ) ) ;
43
53
return tmp . setup ( './tmp' ) . then ( function ( ) {
44
54
process . chdir ( './tmp' ) ;
45
- expect ( existsSync ( path . join ( process . cwd ( ) , 'bin' , 'ng' ) ) ) ;
46
55
} ) ;
47
56
} ) ;
48
57
58
+
49
59
it ( 'Can create new project using `ng new test-project`' , function ( ) {
50
60
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 } ` ) ;
53
71
expect ( existsSync ( path . join ( root , 'test-project' ) ) ) ;
54
72
} ) ;
55
73
} ) ;
@@ -66,14 +84,32 @@ describe('Basic end-to-end Workflow', function () {
66
84
// stuck to the first build done
67
85
sh . exec ( `${ ngBin } build -prod` ) ;
68
86
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
+
73
94
// Also does not create new things in GIT.
74
95
expect ( sh . exec ( 'git status --porcelain' ) . output ) . to . be . equal ( undefined ) ;
75
96
} ) ;
76
97
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
+
77
113
it ( 'Can run `ng build` in created project' , function ( ) {
78
114
this . timeout ( 420000 ) ;
79
115
@@ -95,6 +131,17 @@ describe('Basic end-to-end Workflow', function () {
95
131
} ) ;
96
132
} ) ;
97
133
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
+
98
145
it ( 'lints' , ( ) => {
99
146
this . timeout ( 420000 ) ;
100
147
@@ -393,7 +440,9 @@ describe('Basic end-to-end Workflow', function () {
393
440
} ) ;
394
441
} ) ;
395
442
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 ( ) {
397
446
this . timeout ( 420000 ) ;
398
447
399
448
const configFilePath = path . join ( process . cwd ( ) , 'src' , 'tsconfig.json' ) ;
@@ -410,7 +459,7 @@ describe('Basic end-to-end Workflow', function () {
410
459
} ) ;
411
460
} ) ;
412
461
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 ( ) {
414
463
this . timeout ( 420000 ) ;
415
464
416
465
const configFilePath = path . join ( process . cwd ( ) , 'src' , 'tsconfig.json' ) ;
@@ -485,3 +534,7 @@ describe('Basic end-to-end Workflow', function () {
485
534
} ) ;
486
535
} ) ;
487
536
} ) ;
537
+
538
+ function isMobileTest ( ) {
539
+ return ! ! process . env [ 'MOBILE_TEST' ] ;
540
+ }
0 commit comments