22
33var IonicAppLib = require ( 'ionic-app-lib' ) ;
44var semver = require ( 'semver' ) ;
5+ var optimist = require ( 'optimist' ) ;
56var Ionitron = require ( '../lib/utils/ionitron' ) ;
67var Q = require ( 'q' ) ;
78var helpUtils = require ( '../lib/utils/help' ) ;
@@ -162,6 +163,10 @@ describe('Cli', function() {
162163 } ) ;
163164
164165 it ( 'should change cwd to project root for project tasks' , function ( done ) {
166+ var processArguments = [ 'node' , 'bin/ionic' , 'fake' ] ;
167+ var rawCliArguments = processArguments . slice ( 2 ) ;
168+ var argv = optimist ( rawCliArguments ) . argv ;
169+
165170 var FakeTask = {
166171 name : 'fake' ,
167172 title : 'fake' ,
@@ -171,15 +176,77 @@ describe('Cli', function() {
171176 isProjectTask : true
172177 } ;
173178 spyOn ( IonicCli , 'getTaskSettingsByName' ) . andReturn ( FakeTask ) ;
179+ spyOn ( FakeTask , 'run' ) . andReturn ( Q ( true ) ) ;
174180
175- IonicCli . run ( [ 'node' , 'bin/ionic' , 'fake' ] )
181+ IonicCli . run ( processArguments )
176182 . then ( function ( ) {
177183 expect ( Utils . cdIonicRoot ) . toHaveBeenCalled ( ) ;
184+ expect ( FakeTask . run ) . toHaveBeenCalledWith ( IonicCli , argv , rawCliArguments ) ;
185+ done ( ) ;
186+ } ) ;
187+ } ) ;
188+
189+ it ( 'should skip loading gulpfile if node_modules does not exist' , function ( done ) {
190+ var processArguments = [ 'node' , 'bin/ionic' , 'fake' ] ;
191+ var rawCliArguments = processArguments . slice ( 2 ) ;
192+ var argv = optimist ( rawCliArguments ) . argv ;
193+
194+ var FakeTask = {
195+ name : 'fake' ,
196+ title : 'fake' ,
197+ run : function ( ) {
198+ return Q ( true ) ;
199+ } ,
200+ isProjectTask : true
201+ } ;
202+ spyOn ( IonicCli , 'getTaskSettingsByName' ) . andReturn ( FakeTask ) ;
203+ spyOn ( fs , 'existsSync' ) . andReturn ( false ) ;
204+ spyOn ( FakeTask , 'run' ) . andReturn ( Q ( true ) ) ;
205+ spyOn ( IonicCli , 'loadGulpfile' ) ;
206+ spyOn ( IonicCli , 'runWithGulp' ) ;
207+
208+ IonicCli . run ( processArguments )
209+ . then ( function ( ) {
210+ expect ( IonicCli . loadGulpfile ) . not . toHaveBeenCalled ( ) ;
211+ expect ( IonicCli . runWithGulp ) . not . toHaveBeenCalled ( ) ;
212+ expect ( FakeTask . run ) . toHaveBeenCalledWith ( IonicCli , argv , rawCliArguments ) ;
213+ done ( ) ;
214+ } ) ;
215+ } ) ;
216+
217+ it ( 'should skip runWithGulp if a gulpfile does not exist' , function ( done ) {
218+ var processArguments = [ 'node' , 'bin/ionic' , 'fake' ] ;
219+ var rawCliArguments = processArguments . slice ( 2 ) ;
220+ var argv = optimist ( rawCliArguments ) . argv ;
221+
222+ var FakeTask = {
223+ name : 'fake' ,
224+ title : 'fake' ,
225+ run : function ( ) {
226+ return Q ( true ) ;
227+ } ,
228+ isProjectTask : true
229+ } ;
230+ spyOn ( IonicCli , 'getTaskSettingsByName' ) . andReturn ( FakeTask ) ;
231+ spyOn ( fs , 'existsSync' ) . andReturn ( true ) ;
232+ spyOn ( IonicCli , 'loadGulpfile' ) . andReturn ( false ) ;
233+ spyOn ( FakeTask , 'run' ) . andReturn ( Q ( true ) ) ;
234+ spyOn ( IonicCli , 'runWithGulp' ) ;
235+
236+ IonicCli . run ( processArguments )
237+ . then ( function ( ) {
238+ expect ( IonicCli . loadGulpfile ) . toHaveBeenCalled ( ) ;
239+ expect ( IonicCli . runWithGulp ) . not . toHaveBeenCalled ( ) ;
240+ expect ( FakeTask . run ) . toHaveBeenCalledWith ( IonicCli , argv , rawCliArguments ) ;
178241 done ( ) ;
179242 } ) ;
180243 } ) ;
181244
182245 it ( 'should not change cwd to project root for non project tasks' , function ( done ) {
246+ var processArguments = [ 'node' , 'bin/ionic' , 'fake' ] ;
247+ var rawCliArguments = processArguments . slice ( 2 ) ;
248+ var argv = optimist ( rawCliArguments ) . argv ;
249+
183250 var FakeTask = {
184251 name : 'fake' ,
185252 title : 'fake' ,
@@ -189,10 +256,12 @@ describe('Cli', function() {
189256 isProjectTask : false
190257 } ;
191258 spyOn ( IonicCli , 'getTaskSettingsByName' ) . andReturn ( FakeTask ) ;
259+ spyOn ( FakeTask , 'run' ) . andReturn ( Q ( true ) ) ;
192260
193- IonicCli . run ( [ 'node' , 'bin/ionic' , 'fake' ] )
261+ IonicCli . run ( processArguments )
194262 . then ( function ( ) {
195263 expect ( Utils . cdIonicRoot ) . not . toHaveBeenCalled ( ) ;
264+ expect ( FakeTask . run ) . toHaveBeenCalledWith ( IonicCli , argv , rawCliArguments ) ;
196265 done ( ) ;
197266 } ) ;
198267 } ) ;
@@ -267,7 +336,6 @@ describe('Cli', function() {
267336 IonicCli . run ( [ 'node' , 'bin/ionic' , 'fake' ] )
268337 . then ( function ( ) {
269338 expect ( IonicCli . loadGulpfile ) . toHaveBeenCalled ( ) ;
270- expect ( FakeTask . run ) . toHaveBeenCalled ( ) ;
271339 expect ( IonicCli . runWithGulp ) . not . toHaveBeenCalled ( ) ;
272340 done ( ) ;
273341 } ) ;
@@ -557,6 +625,7 @@ describe('Cli', function() {
557625 describe ( 'runWithGulp function' , function ( ) {
558626 var fakeTask ;
559627 var argv ;
628+ var rawCliArguments ;
560629 var qCallbacks ;
561630
562631 beforeEach ( function ( ) {
@@ -572,6 +641,7 @@ describe('Cli', function() {
572641 _ : [ 'fake' ] ,
573642 v2 : true
574643 } ;
644+ rawCliArguments = [ 'fake' , '--v2' ] ;
575645 gulp . tasks = {
576646 'fake:before' : function ( ) { } ,
577647 'fake:after' : function ( ) { }
@@ -598,7 +668,7 @@ describe('Cli', function() {
598668 it ( 'should try to load gulp, exit if it fails' , function ( ) {
599669 spyOn ( path , 'resolve' ) . andReturn ( './wrong_path' ) ;
600670
601- IonicCli . runWithGulp ( argv , fakeTask ) ;
671+ IonicCli . runWithGulp ( argv , fakeTask , rawCliArguments ) ;
602672
603673 expect ( log . error ) . toHaveBeenCalledWith ( '\nGulpfile detected, but gulp is not installed' . red ) ;
604674 expect ( log . error ) . toHaveBeenCalledWith ( 'Do you need to run `npm install`?\n' . red ) ;
@@ -611,12 +681,12 @@ describe('Cli', function() {
611681
612682
613683 it ( 'should run logEvents, the command and the gulp hooks' , function ( done ) {
614- IonicCli . runWithGulp ( argv , fakeTask ) . then ( function ( ) {
684+ IonicCli . runWithGulp ( argv , fakeTask , rawCliArguments ) . then ( function ( ) {
615685
616686 expect ( IonicCli . logEvents ) . toHaveBeenCalled ( ) ;
617687 expect ( gulp . start ) . toHaveBeenCalledWith ( 'fake:before' , qCallbacks [ 0 ] ) ;
618688 expect ( gulp . start ) . toHaveBeenCalledWith ( 'fake:after' , qCallbacks [ 1 ] ) ;
619- expect ( fakeTask . run ) . toHaveBeenCalledWith ( IonicCli , argv ) ;
689+ expect ( fakeTask . run ) . toHaveBeenCalledWith ( IonicCli , argv , rawCliArguments ) ;
620690
621691 expect ( log . error ) . not . toHaveBeenCalled ( ) ;
622692 expect ( process . exit ) . not . toHaveBeenCalled ( ) ;
0 commit comments