Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Fix(state): state reset --plugins|--platforms was resetting both
Browse files Browse the repository at this point in the history
  • Loading branch information
jakub-g committed Feb 19, 2016
1 parent 0d24e15 commit 308e4cd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,15 @@ State.checkAndSaveConfigXml = function checkAndSaveConfigXml(appDirectory, plugi
State.resetState = function resetState(appDirectory, options) {
var platformPath = path.join(appDirectory, 'platforms');
var pluginPath = path.join(appDirectory, 'plugins');
shelljs.rm('-rf', [platformPath, pluginPath]);
logging.logger.info('Removed platforms and plugins'.blue.bold);
var noOptions = !options.platforms && !options.plugins;
if (options.platforms || noOptions) {
shelljs.rm('-rf', [platformPath]);
logging.logger.info('Removed platforms'.blue.bold);
}
if (options.plugins || noOptions) {
shelljs.rm('-rf', [pluginPath]);
logging.logger.info('Removed plugins'.blue.bold);
}
State.restoreState(appDirectory, options)
.then(function() {
logging.logger.info('Ionic reset state complete'.green.bold);
Expand Down
51 changes: 49 additions & 2 deletions spec/state.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,63 @@ describe('State', function() {
});

describe('#resetState', function() {
it('should call call rm on the platforms path', function() {
it('should call call rm on the platforms ands plugins paths by default', function() {
spyOn(shelljs, 'rm');
spyOn(State, 'restoreState').andReturn(Q());
State.resetState(tempDirectory, {});

var platformPath = path.join(tempDirectory, 'platforms');
var pluginPath = path.join(tempDirectory, 'plugins');
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [platformPath, pluginPath]);
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [platformPath]);
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [pluginPath]);
expect(State.restoreState).toHaveBeenCalledWith(tempDirectory, {});
});

it('should call call rm on the platforms ands plugins path if both passed', function() {
spyOn(shelljs, 'rm');
spyOn(State, 'restoreState').andReturn(Q());
State.resetState(tempDirectory, {
platforms: true,
plugins: true
});

var platformPath = path.join(tempDirectory, 'platforms');
var pluginPath = path.join(tempDirectory, 'plugins');
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [platformPath]);
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [pluginPath]);
expect(State.restoreState).toHaveBeenCalledWith(tempDirectory, {
platforms: true,
plugins: true
});
});

it('should call call rm only on the platforms path if passed explicitly', function() {
spyOn(shelljs, 'rm');
spyOn(State, 'restoreState').andReturn(Q());
State.resetState(tempDirectory, {
platforms: true
});

var platformPath = path.join(tempDirectory, 'platforms');
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [platformPath]);
expect(State.restoreState).toHaveBeenCalledWith(tempDirectory, {
platforms: true
});
});

it('should call call rm only on the plugins path if passed explicitly', function() {
spyOn(shelljs, 'rm');
spyOn(State, 'restoreState').andReturn(Q());
State.resetState(tempDirectory, {
plugins: true
});

var pluginPath = path.join(tempDirectory, 'plugins');
expect(shelljs.rm).toHaveBeenCalledWith('-rf', [pluginPath]);
expect(State.restoreState).toHaveBeenCalledWith(tempDirectory, {
plugins: true
});
});
});

describe('#restorePlugins', function(){
Expand Down

0 comments on commit 308e4cd

Please sign in to comment.