diff --git a/src/plugins/ValidateArchitecture/ValidateArchitecture.js b/src/plugins/ValidateArchitecture/ValidateArchitecture.js index d962e8ceb..8e1afbed3 100644 --- a/src/plugins/ValidateArchitecture/ValidateArchitecture.js +++ b/src/plugins/ValidateArchitecture/ValidateArchitecture.js @@ -8,7 +8,8 @@ define([ 'q', 'fs', 'path', - 'child_process' + 'child_process', + 'rimraf' ], function ( PluginBase, SimpleNodeConstants, @@ -16,7 +17,8 @@ define([ Q, fs, path, - childProcess + childProcess, + rm_rf ) { 'use strict'; @@ -111,8 +113,9 @@ define([ ValidateArchitecture.prototype.validateLayers = function (layerTests) { return Q.all(layerTests.map(layer => this.validateLayer(layer[0], layer[1]))) - .then(results => results.filter(result => !!result)); - // TODO: Remove tmp files + .then(results => Q.nfcall(rm_rf, this._tmpFileId) + .then(() => results.filter(result => !!result)) + ); }; ValidateArchitecture.prototype.validateLayer = function (id, code) { diff --git a/test/cli/cli.spec.js b/test/cli/cli.spec.js index 3fa1e6b9f..1df65ee9d 100644 --- a/test/cli/cli.spec.js +++ b/test/cli/cli.spec.js @@ -1,58 +1,59 @@ -var mockery = require('mockery'), - assert = require('assert'), - path = require('path'), - nop = () => {}, - cli; - -var callRegister = { - childProcess: { - execSync: [] - } -}; - -var mocks = { - childProcess: {}, - rimraf: {} -}; - -var childProcess = { - execSync: function(cmd) { - callRegister.childProcess.execSync.push(cmd); - if (mocks.childProcess.execSync) { - return mocks.childProcess.execSync.apply(this, arguments); +describe('cli', function() { + var mockery = require('mockery'), + assert = require('assert'), + path = require('path'), + nop = () => {}, + cli; + + var callRegister = { + childProcess: { + execSync: [] } - }, - spawnSync: function(cmd) { - if (cmd === 'luarocks') { + }; + + var mocks = { + childProcess: {}, + rimraf: {} + }; + + var childProcess = { + execSync: function(cmd) { + callRegister.childProcess.execSync.push(cmd); + if (mocks.childProcess.execSync) { + return mocks.childProcess.execSync.apply(this, arguments); + } + }, + spawnSync: function(cmd) { + if (cmd === 'luarocks') { + return { + stdout: 'rnn' + }; + } + return {}; + }, + spawn: function() { + if (mocks.childProcess.spawn) { + mocks.childProcess.spawn.apply(this, arguments); + } return { - stdout: 'rnn' + on: () => {}, + stdout: { + on: () => {} + }, + stderr: { + on: () => {} + } }; } - return {}; - }, - spawn: function() { - if (mocks.childProcess.spawn) { - mocks.childProcess.spawn.apply(this, arguments); + }; + var rimraf = {}; + rimraf.sync = function() { + if (mocks.rimraf.sync) { + mocks.rimraf.sync.apply(this, arguments); } - return { - on: () => {}, - stdout: { - on: () => {} - }, - stderr: { - on: () => {} - } - }; - } -}; -var rimraf = {}; -rimraf.sync = function() { - if (mocks.rimraf.sync) { - mocks.rimraf.sync.apply(this, arguments); - } -}; + }; + -describe('cli', function() { before(function() { // create the mocks mockery.enable({ diff --git a/test/plugins/ValidateArchitecture/ValidateArchitecture.spec.js b/test/plugins/ValidateArchitecture/ValidateArchitecture.spec.js index 4d70f64ae..a909bbc46 100644 --- a/test/plugins/ValidateArchitecture/ValidateArchitecture.spec.js +++ b/test/plugins/ValidateArchitecture/ValidateArchitecture.spec.js @@ -6,6 +6,9 @@ var testFixture = require('../../globals'); describe('ValidateArchitecture', function () { var gmeConfig = testFixture.getGmeConfig(), expect = testFixture.expect, + fs = require('fs'), + rm_rf = require('rimraf'), + mockery = require('mockery'), logger = testFixture.logger.fork('ValidateArchitecture'), PluginCliManager = testFixture.WebGME.PluginCliManager, manager = new PluginCliManager(null, logger, gmeConfig), @@ -64,6 +67,7 @@ describe('ValidateArchitecture', function () { return manager.initializePlugin(pluginName) .then(plugin_ => { plugin = plugin_; + plugin.setTorchInstalled(true); return manager.configurePlugin(plugin, {}, context); }) .nodeify(done); @@ -85,6 +89,33 @@ describe('ValidateArchitecture', function () { }); }); + it('should make tmp dir', function(done) { + var oldMkdir = fs.mkdir; + fs.mkdir = (dir, cb) => { + expect(dir).to.equal(plugin._tmpFileId); + return oldMkdir(dir, cb); + }; + plugin.main(() => { + fs.mkdir = oldMkdir; + done(); + }); + }); + + it('should rm tmp dir', function(done) { + mockery.enable({ + warnOnReplace: false, + warnOnUnregistered: false + }); + mockery.registerMock('rimraf', (dir, cb) => { + expect(dir).to.equal(plugin._tmpFileId); + return rm_rf(dir, cb); + }); + plugin.main(() => { + mockery.disable(); + done(); + }); + }); + // check that errors are returned in the message it('should return two error messages', function(done) { plugin.validateLayer = (id, code) => { @@ -99,7 +130,7 @@ describe('ValidateArchitecture', function () { }; plugin.main((err, result) => { var invalidLayers = result.messages[0].message.errors.map(msg => msg.id); - expect(invalidLayers.length).to.equal(2); + expect(result.messages[0]).to.not.equal(undefined); done(); }); });