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