@@ -9,8 +9,6 @@ var conf = require('ember-cli/tests/helpers/conf');
9
9
var sh = require ( 'shelljs' ) ;
10
10
var treeKill = require ( 'tree-kill' ) ;
11
11
var child_process = require ( 'child_process' ) ;
12
- var Promise = require ( 'ember-cli/lib/ext/promise' ) ;
13
- var execPromise = Promise . denodeify ( child_process . exec ) ;
14
12
var ng = require ( '../helpers/ng' ) ;
15
13
var root = path . join ( process . cwd ( ) , 'tmp' ) ;
16
14
@@ -64,12 +62,12 @@ describe('Basic end-to-end Workflow', function () {
64
62
sh . exec ( 'npm install' ) ;
65
63
} ) ;
66
64
67
- it ( 'Supports production builds via `ng build --environment=production `' , function ( ) {
65
+ it ( 'Supports production builds via `ng build -prod `' , function ( ) {
68
66
this . timeout ( 420000 ) ;
69
67
70
- // Can't user the `ng` helper because somewhere the environment gets
68
+ // Can't use the `ng` helper because somewhere the environment gets
71
69
// stuck to the first build done
72
- sh . exec ( `${ ngBin } build --environment=production ` ) ;
70
+ sh . exec ( `${ ngBin } build -prod ` ) ;
73
71
expect ( existsSync ( path . join ( process . cwd ( ) , 'dist' ) ) ) . to . be . equal ( true ) ;
74
72
var appBundlePath = path . join ( process . cwd ( ) , 'dist' , 'app' , 'index.js' ) ;
75
73
var appBundleContent = fs . readFileSync ( appBundlePath , { encoding : 'utf8' } ) ;
@@ -120,26 +118,36 @@ describe('Basic end-to-end Workflow', function () {
120
118
} ) ;
121
119
122
120
it ( 'Serve and run e2e tests after initial build' , function ( ) {
123
- this . timeout ( 420000 ) ;
121
+ this . timeout ( 240000 ) ;
124
122
125
123
var ngServePid ;
126
124
127
125
function executor ( resolve , reject ) {
128
- var serveFailedMsg = 'ng serve command failed' ;
129
- var e2eFailedMsg = 'ng serve command failed' ;
130
- var child = child_process . exec ( 'ng serve' ) ;
131
- ngServePid = child . pid ;
132
-
133
- child . stdout . on ( 'data' , ( data ) => {
134
- if ( / ^ B u i l d s u c c e s s f u l / . test ( data ) ) {
135
- resolve ( execPromise ( 'ng e2e' ) . catch ( ( ) => Promise . reject ( e2eFailedMsg ) ) ) ;
126
+ var serveProcess = child_process . exec ( `${ ngBin } serve` ) ;
127
+ var startedProtractor = false ;
128
+ ngServePid = serveProcess . pid ;
129
+
130
+ serveProcess . stdout . on ( 'data' , ( data ) => {
131
+ if ( / B u i l d s u c c e s s f u l / . test ( data ) && ! startedProtractor ) {
132
+ startedProtractor = true ;
133
+ child_process . exec ( `${ ngBin } e2e` , ( error , stdout , stderr ) => {
134
+ if ( error !== null ) {
135
+ reject ( stderr )
136
+ } else {
137
+ resolve ( ) ;
138
+ }
139
+ } ) ;
136
140
} else if ( / f a i l e d w i t h : / . test ( data ) ) {
137
- reject ( serveFailedMsg ) ;
141
+ reject ( data ) ;
138
142
}
139
143
} ) ;
140
144
141
- child . stderr . on ( 'data' , ( ) => reject ( serveFailedMsg ) ) ;
142
- child . on ( 'close' , ( code ) => code === 0 ? resolve ( ) : reject ( serveFailedMsg ) ) ;
145
+ serveProcess . stderr . on ( 'data' , ( data ) => {
146
+ reject ( data ) ;
147
+ } ) ;
148
+ serveProcess . on ( 'close' , ( code ) => {
149
+ code === 0 ? resolve ( ) : reject ( 'ng serve command closed with error' )
150
+ } ) ;
143
151
}
144
152
145
153
return new Promise ( executor )
@@ -410,28 +418,38 @@ describe('Basic end-to-end Workflow', function () {
410
418
expect ( 'build failed where it should have succeeded' ) . to . equal ( '' ) ;
411
419
} ) ;
412
420
} ) ;
413
-
414
- it ( 'Serve and run e2e tests after final build ' , function ( ) {
415
- this . timeout ( 420000 ) ;
421
+
422
+ it ( 'Serve and run e2e tests after all other commands ' , function ( ) {
423
+ this . timeout ( 240000 ) ;
416
424
417
425
var ngServePid ;
418
426
419
427
function executor ( resolve , reject ) {
420
- var serveFailedMsg = 'ng serve command failed' ;
421
- var e2eFailedMsg = 'ng serve command failed' ;
422
- var child = child_process . exec ( `${ ngBin } serve` ) ;
423
- ngServePid = child . pid ;
424
-
425
- child . stdout . on ( 'data' , ( data ) => {
426
- if ( / ^ B u i l d s u c c e s s f u l / . test ( data ) ) {
427
- resolve ( execPromise ( `${ ngBin } e2e` ) . catch ( ( ) => Promise . reject ( e2eFailedMsg ) ) ) ;
428
+ var serveProcess = child_process . exec ( `${ ngBin } serve` ) ;
429
+ var startedProtractor = false ;
430
+ ngServePid = serveProcess . pid ;
431
+
432
+ serveProcess . stdout . on ( 'data' , ( data ) => {
433
+ if ( / B u i l d s u c c e s s f u l / . test ( data ) && ! startedProtractor ) {
434
+ startedProtractor = true ;
435
+ child_process . exec ( `${ ngBin } e2e` , ( error , stdout , stderr ) => {
436
+ if ( error !== null ) {
437
+ reject ( stderr )
438
+ } else {
439
+ resolve ( ) ;
440
+ }
441
+ } ) ;
428
442
} else if ( / f a i l e d w i t h : / . test ( data ) ) {
429
- reject ( serveFailedMsg ) ;
443
+ reject ( data ) ;
430
444
}
431
445
} ) ;
432
446
433
- child . stderr . on ( 'data' , ( ) => reject ( serveFailedMsg ) ) ;
434
- child . on ( 'close' , ( code ) => code === 0 ? resolve ( ) : reject ( serveFailedMsg ) ) ;
447
+ serveProcess . stderr . on ( 'data' , ( data ) => {
448
+ reject ( data ) ;
449
+ } ) ;
450
+ serveProcess . on ( 'close' , ( code ) => {
451
+ code === 0 ? resolve ( ) : reject ( 'ng serve command closed with error' )
452
+ } ) ;
435
453
}
436
454
437
455
return new Promise ( executor )
@@ -443,4 +461,15 @@ describe('Basic end-to-end Workflow', function () {
443
461
throw new Error ( msg ) ;
444
462
} ) ;
445
463
} ) ;
464
+
465
+ it ( 'Still Supports production builds after all other commands`' , function ( ) {
466
+ this . timeout ( 420000 ) ;
467
+
468
+ sh . exec ( `${ ngBin } build -prod` ) ;
469
+ expect ( existsSync ( path . join ( process . cwd ( ) , 'dist' ) ) ) . to . be . equal ( true ) ;
470
+ var appBundlePath = path . join ( process . cwd ( ) , 'dist' , 'app' , 'index.js' ) ;
471
+ var appBundleContent = fs . readFileSync ( appBundlePath , { encoding : 'utf8' } ) ;
472
+ expect ( appBundleContent ) . to . include ( 'production:!0' ) ;
473
+ expect ( sh . exec ( 'git status --porcelain' ) . output ) . to . be . equal ( undefined ) ;
474
+ } ) ;
446
475
} ) ;
0 commit comments