Skip to content

Commit c1c55ef

Browse files
committed
test(cli): fix tests with gulpfile, add tests for npm scripts
1 parent bf52436 commit c1c55ef

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

spec/cli.spec.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,12 @@ describe('Cli', function() {
320320
spyOn(FakeTask, 'run').andReturn(Q(true));
321321
spyOn(fs, 'existsSync').andReturn(true);
322322
spyOn(IonicCli, 'loadGulpfile').andReturn(false);
323+
spyOn(IonicCli, 'loadNpmScripts').andReturn(false);
323324
spyOn(log, 'warn');
324325

325326
IonicCli.run(['node', 'bin/ionic', 'build'])
326327
.then(function() {
327-
expect(log.warn).toHaveBeenCalledWith('WARN: No gulpfile found!');
328+
expect(log.warn).toHaveBeenCalledWith('WARN: No build file found!');
328329
done();
329330
});
330331
});
@@ -341,6 +342,29 @@ describe('Cli', function() {
341342
spyOn(FakeTask, 'run').andReturn(Q(true));
342343
spyOn(fs, 'existsSync').andReturn(true);
343344
spyOn(IonicCli, 'loadGulpfile').andReturn(false);
345+
spyOn(IonicCli, 'loadNpmScripts').andReturn(false);
346+
347+
IonicCli.run(['node', 'bin/ionic', 'fake'])
348+
.then(function() {
349+
expect(IonicCli.loadGulpfile).toHaveBeenCalled();
350+
expect(IonicCli.runWithGulp).not.toHaveBeenCalled();
351+
done();
352+
});
353+
});
354+
355+
it('should not runWithGulp if npmScripts exist', function(done) {
356+
var FakeTask = {
357+
name: 'fake',
358+
title: 'fake',
359+
run: function() {},
360+
isProjectTask: true
361+
};
362+
spyOn(IonicCli, 'getTaskSettingsByName').andReturn(FakeTask);
363+
spyOn(IonicCli, 'runWithGulp');
364+
spyOn(FakeTask, 'run').andReturn(Q(true));
365+
spyOn(fs, 'existsSync').andReturn(true);
366+
spyOn(IonicCli, 'loadGulpfile').andReturn(false);
367+
spyOn(IonicCli, 'loadNpmScripts').andReturn(true);
344368

345369
IonicCli.run(['node', 'bin/ionic', 'fake'])
346370
.then(function() {
@@ -357,12 +381,55 @@ describe('Cli', function() {
357381
};
358382
spyOn(IonicCli, 'getTaskSettingsByName').andReturn(FakeTask);
359383
spyOn(IonicCli, 'runWithGulp').andReturn(Q(true));
384+
spyOn(IonicCli, 'runWithNpmScripts').andReturn(Q(true));
360385
spyOn(fs, 'existsSync').andReturn(true);
361386
spyOn(IonicCli, 'loadGulpfile').andReturn(true);
387+
spyOn(IonicCli, 'loadNpmScripts').andReturn(false);
362388

363389
IonicCli.run(['node', 'bin/ionic', 'fake'])
364390
.then(function() {
365391
expect(IonicCli.runWithGulp).toHaveBeenCalled();
392+
expect(IonicCli.runWithNpmScripts).not.toHaveBeenCalled();
393+
done();
394+
});
395+
});
396+
397+
it('should runWithNpmScripts without Gulpfile', function(done) {
398+
var FakeTask = {
399+
name: 'fake',
400+
isProjectTask: true
401+
};
402+
spyOn(IonicCli, 'getTaskSettingsByName').andReturn(FakeTask);
403+
spyOn(IonicCli, 'runWithGulp').andReturn(Q(true));
404+
spyOn(IonicCli, 'runWithNpmScripts').andReturn(Q(true));
405+
spyOn(fs, 'existsSync').andReturn(true);
406+
spyOn(IonicCli, 'loadGulpfile').andReturn(false);
407+
spyOn(IonicCli, 'loadNpmScripts').andReturn(true);
408+
409+
IonicCli.run(['node', 'bin/ionic', 'fake'])
410+
.then(function() {
411+
expect(IonicCli.runWithGulp).not.toHaveBeenCalled();
412+
expect(IonicCli.runWithNpmScripts).toHaveBeenCalled();
413+
done();
414+
});
415+
});
416+
417+
it('should runWithNpmScripts even with Gulpfile', function(done) {
418+
var FakeTask = {
419+
name: 'fake',
420+
isProjectTask: true
421+
};
422+
spyOn(IonicCli, 'getTaskSettingsByName').andReturn(FakeTask);
423+
spyOn(IonicCli, 'runWithGulp').andReturn(Q(true));
424+
spyOn(IonicCli, 'runWithNpmScripts').andReturn(Q(true));
425+
spyOn(fs, 'existsSync').andReturn(true);
426+
spyOn(IonicCli, 'loadGulpfile').andReturn(true);
427+
spyOn(IonicCli, 'loadNpmScripts').andReturn(true);
428+
429+
IonicCli.run(['node', 'bin/ionic', 'fake'])
430+
.then(function() {
431+
expect(IonicCli.runWithGulp).not.toHaveBeenCalled();
432+
expect(IonicCli.runWithNpmScripts).toHaveBeenCalled();
366433
done();
367434
});
368435
});

0 commit comments

Comments
 (0)