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

Fix(state): state reset --plugins|--platforms was resetting both #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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