1
- var td = require ( 'testdouble' ) ;
1
+ const td = require ( 'testdouble' ) ;
2
+ const expect = require ( '../../helpers/expect' ) ;
3
+ const Promise = require ( 'rsvp' ) ;
4
+ const mockProject = require ( '../../fixtures/ember-cordova-mock/project' ) ;
5
+ const mockAnalytics = require ( '../../fixtures/ember-cordova-mock/analytics' ) ;
2
6
3
- var expect = require ( '../../helpers/expect' ) ;
4
- var Promise = require ( 'rsvp' ) ;
5
-
6
- var CdvTarget = require ( '../../../lib/targets/cordova/target' ) ;
7
- var HookTask = require ( '../../../lib/tasks/run-hook' ) ;
8
- var LintTask = require ( '../../../lib/tasks/lint-index' ) ;
9
-
10
- var mockProject = require ( '../../fixtures/ember-cordova-mock/project' ) ;
11
- var mockAnalytics = require ( '../../fixtures/ember-cordova-mock/analytics' ) ;
12
-
13
- var setupBuild = function ( ) {
14
- var BuildCmd = require ( '../../../lib/commands/build' ) ;
7
+ describe ( 'Build Command' , function ( ) {
8
+ let baseOpts , tasks ;
9
+ let AddCordovaJS , LintTask ;
15
10
16
- var project = mockProject . project ;
17
- project . config = function ( ) {
18
- return {
19
- locationType : 'hash '
11
+ beforeEach ( function ( ) {
12
+ baseOpts = {
13
+ cordovaOutputPath : 'ember-cordova/cordova/www' ,
14
+ platform : 'ios '
20
15
} ;
21
- }
22
-
23
- var build = new BuildCmd ( {
24
- project : project
25
16
} ) ;
26
- build . analytics = mockAnalytics ;
27
-
28
- return build ;
29
- } ;
30
17
31
- describe ( 'Build Command' , function ( ) {
32
18
afterEach ( function ( ) {
33
19
td . reset ( ) ;
34
20
} ) ;
35
21
36
- var tasks ;
37
-
38
- beforeEach ( function ( ) {
39
- mockTasks ( ) ;
40
- } ) ;
41
-
42
- function mockTasks ( ) {
22
+ function setupBuild ( ) {
23
+ let CdvTarget , HookTask ;
43
24
tasks = [ ] ;
44
25
26
+ CdvTarget = require ( '../../../lib/targets/cordova/target' ) ;
27
+ HookTask = require ( '../../../lib/tasks/run-hook' ) ;
28
+ AddCordovaJS = td . replace ( '../../../lib/tasks/add-cordova-js' ) ;
29
+ LintTask = td . replace ( '../../../lib/tasks/lint-index' ) ;
30
+
45
31
td . replace ( '../../../lib/utils/require-framework' , function ( ) {
46
32
return {
47
33
validateBuild : function ( ) {
@@ -75,27 +61,48 @@ describe('Build Command', function() {
75
61
tasks . push ( 'cordova-target-build' ) ;
76
62
return Promise . resolve ( ) ;
77
63
} ) ;
64
+
65
+ td . replace ( AddCordovaJS . prototype , 'run' , function ( ) {
66
+ tasks . push ( 'add-cordova-js' ) ;
67
+ return Promise . resolve ( ) ;
68
+ } ) ;
69
+
70
+ let BuildCmd = require ( '../../../lib/commands/build' ) ;
71
+ let project = mockProject . project ;
72
+ project . config = function ( ) {
73
+ return {
74
+ locationType : 'hash'
75
+ } ;
76
+ } ;
77
+
78
+ let build = new BuildCmd ( {
79
+ project : project
80
+ } ) ;
81
+ build . analytics = mockAnalytics ;
82
+
83
+ return build ;
78
84
}
79
85
80
86
it ( 'exits cleanly' , function ( ) {
81
- var build = setupBuild ( ) ;
87
+ let build = setupBuild ( ) ;
82
88
83
89
return expect ( function ( ) {
84
- build . run ( { } ) ;
90
+ build . run ( baseOpts ) ;
85
91
} ) . not . to . throw ( Error ) ;
86
92
} ) ;
87
93
88
94
it ( 'runs tasks in the correct order' , function ( ) {
89
- var build = setupBuild ( ) ;
95
+ let build = setupBuild ( ) ;
90
96
91
- return build . run ( { } )
97
+ return build . run ( baseOpts )
92
98
. then ( function ( ) {
93
99
//h-t ember-electron for the pattern
94
100
expect ( tasks ) . to . deep . equal ( [
95
101
'hook beforeBuild' ,
96
102
'framework-validate-build' ,
97
103
'cordova-target-validate-build' ,
98
104
'framework-build' ,
105
+ 'add-cordova-js' ,
99
106
'cordova-target-build' ,
100
107
'hook afterBuild' ,
101
108
'lint-index'
@@ -104,9 +111,10 @@ describe('Build Command', function() {
104
111
} ) ;
105
112
106
113
it ( 'skips ember-build with the --skip-ember-build flag' , function ( ) {
107
- var build = setupBuild ( ) ;
114
+ let build = setupBuild ( ) ;
115
+ baseOpts . skipEmberBuild = true ;
108
116
109
- return build . run ( { skipEmberBuild : true } )
117
+ return build . run ( baseOpts )
110
118
. then ( function ( ) {
111
119
//h-t ember-electron for the pattern
112
120
expect ( tasks ) . to . deep . equal ( [
@@ -121,19 +129,40 @@ describe('Build Command', function() {
121
129
} ) ;
122
130
123
131
it ( 'skips cordova-build with the --skip-cordova-build flag' , function ( ) {
124
- var build = setupBuild ( ) ;
132
+ let build = setupBuild ( ) ;
133
+ baseOpts . skipCordovaBuild = true ;
125
134
126
- return build . run ( { skipCordovaBuild : true } )
135
+ return build . run ( baseOpts )
127
136
. then ( function ( ) {
128
137
//h-t ember-electron for the pattern
129
138
expect ( tasks ) . to . deep . equal ( [
130
139
'hook beforeBuild' ,
131
140
'framework-validate-build' ,
132
141
'cordova-target-validate-build' ,
133
142
'framework-build' ,
143
+ 'add-cordova-js' ,
134
144
'hook afterBuild' ,
135
145
'lint-index'
136
146
] ) ;
137
147
} ) ;
138
148
} ) ;
149
+
150
+ it ( 'constructs AddCordovaJS as expected' , function ( ) {
151
+ let build = setupBuild ( ) ;
152
+ return build . run ( baseOpts ) . then ( function ( ) {
153
+ td . verify ( new AddCordovaJS ( {
154
+ source : 'ember-cordova/cordova/www/index.html'
155
+ } ) ) ;
156
+ } ) ;
157
+ } ) ;
158
+
159
+ it ( 'constructs lint index as expected' , function ( ) {
160
+ let build = setupBuild ( ) ;
161
+ return build . run ( baseOpts ) . then ( function ( ) {
162
+ td . verify ( new LintTask ( {
163
+ source : 'www/index.html' ,
164
+ project : mockProject . project
165
+ } ) ) ;
166
+ } ) ;
167
+ } ) ;
139
168
} ) ;
0 commit comments