Skip to content

Commit

Permalink
Replaced unlink w/ rimraf. Fixes #549 (#550)
Browse files Browse the repository at this point in the history
WIP #549 Fixed bug in tests
  • Loading branch information
brollb authored Jul 25, 2016
1 parent bf3fe1f commit b0679ae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
7 changes: 4 additions & 3 deletions bin/deepforge
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var Command = require('commander').Command,
dataPath = path.join(configDir, 'data'),

localConfig,
rm_rf = require('rimraf'),
p = dir => dir.replace(/^~/, process.env.HOME); // resolve '~' to '$HOME'

// Check for any commands
Expand Down Expand Up @@ -333,13 +334,13 @@ program
if (opts.torch) {
console.log(`uninstalling torch at ${p(config.torch.dir)}`);
}
fs.unlinkSync(p(config.torch.dir));
rm_rf.sync(p(config.torch.dir));
}

if (opts.clean) { // remove the .deepforge directory
console.log('removing config and data files...');
fs.unlinkSync(p(config.mongo.dir));
fs.unlinkSync(p(configDir));
rm_rf.sync(p(config.mongo.dir));
rm_rf.sync(p(configDir));
}

if (!opts.torch || opts.clean) { // uninstall deepforge
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
"webgme-chflayout": "^2.0.0",
"webgme-easydag": "dfst/webgme-easydag",
"webgme-fab": "dfst/webgme-fab",
"webgme-simple-nodes": "^2.0.0"
"webgme-simple-nodes": "^2.0.0",
"rimraf": "^2.4.0"
},
"devDependencies": {
"chai": "^3.0.0",
"jszip": "^2.5.0",
"mocha": "^2.2.5",
"mockery": "^1.7.0",
"rimraf": "^2.4.0"
"mockery": "^1.7.0"
}
}
23 changes: 12 additions & 11 deletions test/cli/cli.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var mockery = require('mockery'),
fs = require('fs'),
assert = require('assert'),
path = require('path'),
nop = () => {},
Expand All @@ -13,6 +12,7 @@ var callRegister = {

var mocks = {
childProcess: {},
rimraf: {},
forever: {}
};

Expand All @@ -23,7 +23,7 @@ var childProcess = {
return mocks.childProcess.execSync.apply(this, arguments);
}
},
spawn: function(cmd) {
spawn: function() {
if (mocks.childProcess.spawn) {
mocks.childProcess.spawn.apply(this, arguments);
}
Expand All @@ -48,6 +48,12 @@ forever.Monitor = function() {
}
return res;
};
var rimraf = {};
rimraf.sync = function() {
if (mocks.rimraf.sync) {
mocks.rimraf.sync.apply(this, arguments);
}
};

describe('cli', function() {
before(function() {
Expand All @@ -58,6 +64,7 @@ describe('cli', function() {
});
mockery.registerMock('child_process', childProcess);
mockery.registerMock('forever-monitor', forever);
mockery.registerMock('rimraf', rimraf);
cli = require('../../bin/deepforge');
});

Expand All @@ -71,6 +78,7 @@ describe('cli', function() {
mocks.childProcess.execSync = nop;
mocks.childProcess.spawn = nop;
mocks.forever.Monitor = nop;
mocks.rimraf.sync = nop;
});

it('should check for running mongo', function() {
Expand Down Expand Up @@ -129,10 +137,8 @@ describe('cli', function() {

describe('uninstall', function() {
it('should only remove \'torch\' if --torch option set', function() {
var oldUnlink = fs.unlinkSync;
fs.unlinkSync = path => assert.notEqual(path.indexOf('torch'), -1);
mocks.rimraf.sync = path => assert.notEqual(path.indexOf('torch'), -1);
cli('uninstall --torch');
fs.unlinkSync = oldUnlink;
});

it('should uninstall deepforge w/ npm', function() {
Expand All @@ -141,21 +147,16 @@ describe('cli', function() {
assert.equal(args[0], 'uninstall');
assert.notEqual(args.indexOf('deepforge'), -1);
};
var oldUnlink = fs.unlinkSync;
fs.unlinkSync = nop;
cli('uninstall');
fs.unlinkSync = oldUnlink;
});

it('should remove ~/.deepforge if --clean option set', function(done) {
var oldUnlink = fs.unlinkSync;
fs.unlinkSync = dir => {
mocks.rimraf.sync = dir => {
if (dir === path.join(process.env.HOME, '.deepforge')) {
done();
}
};
cli('uninstall --clean');
fs.unlinkSync = oldUnlink;
});
});

Expand Down

0 comments on commit b0679ae

Please sign in to comment.