From a92a7419327dbc0a73adff7ae6acd6ae30c34984 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sat, 14 Nov 2015 20:27:04 +0000 Subject: [PATCH] Fix incorrect async test completion --- test/nodes/core/parsers/70-JSON_spec.js | 2 -- test/red/runtime/nodes/index_spec.js | 15 +++++---- .../runtime/nodes/registry/installer_spec.js | 32 ++++++++++++------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/test/nodes/core/parsers/70-JSON_spec.js b/test/nodes/core/parsers/70-JSON_spec.js index f49e232f1..43b9904a6 100644 --- a/test/nodes/core/parsers/70-JSON_spec.js +++ b/test/nodes/core/parsers/70-JSON_spec.js @@ -77,7 +77,6 @@ describe('JSON node', function() { var jn1 = helper.getNode("jn1"); var jn2 = helper.getNode("jn2"); jn2.on("input", function(msg) { - console.log(msg); should.equal(msg.payload, '[1,2,3]'); done(); }); @@ -118,7 +117,6 @@ describe('JSON node', function() { var logEvents = helper.log().args.filter(function(evt) { return evt[0].type == "json"; }); - console.log(logEvents); logEvents.should.have.length(3); logEvents[0][0].should.have.a.property('msg'); logEvents[0][0].msg.toString().should.eql('json.errors.dropped'); diff --git a/test/red/runtime/nodes/index_spec.js b/test/red/runtime/nodes/index_spec.js index a0437cfbc..3167c86a8 100644 --- a/test/red/runtime/nodes/index_spec.js +++ b/test/red/runtime/nodes/index_spec.js @@ -124,13 +124,16 @@ describe("red/nodes/index", function() { }); after(function(done) { - fs.remove(userDir,done); - runtime.stop(); - index.load.restore(); - localfilesystem.getCredentials.restore(); + fs.remove(userDir,function() {; + runtime.stop().then(function() { + index.load.restore(); + localfilesystem.getCredentials.restore(); + done(); + }); + }); }); - it(': definition defined',function(done) { + it(': definition defined',function() { index.registerType('test', TestNode, { credentials: { foo: {type:"test"} @@ -138,13 +141,11 @@ describe("red/nodes/index", function() { }); var testnode = new TestNode({id:'tab1',type:'test',name:'barney', '_alias':'tab1'}); index.getCredentialDefinition("test").should.have.property('foo'); - done(); }); }); describe('allows nodes to be added/removed/enabled/disabled from the registry', function() { - var registry = require("../../../../red/runtime/nodes/registry"); var randomNodeInfo = {id:"5678",types:["random"]}; beforeEach(function() { diff --git a/test/red/runtime/nodes/registry/installer_spec.js b/test/red/runtime/nodes/registry/installer_spec.js index 1c6fb9408..a458f7414 100644 --- a/test/red/runtime/nodes/registry/installer_spec.js +++ b/test/red/runtime/nodes/registry/installer_spec.js @@ -18,6 +18,7 @@ var should = require("should"); var sinon = require("sinon"); var when = require("when"); var path = require("path"); +var fs = require('fs'); var child_process = require('child_process'); var installer = require("../../../../../red/runtime/nodes/registry/installer"); @@ -33,7 +34,24 @@ describe('nodes/registry/installer', function() { if (child_process.execFile.restore) { child_process.execFile.restore(); } - }) + if (registry.addModule.restore) { + registry.addModule.restore(); + } + if (registry.removeModule.restore) { + registry.removeModule.restore(); + } + if (typeRegistry.removeModule.restore) { + typeRegistry.removeModule.restore(); + } + if (registry.getModuleInfo.restore) { + registry.getModuleInfo.restore(); + } + + if (require('fs').existsSync.restore) { + require('fs').existsSync.restore(); + } + + }); describe("installs module", function() { it("rejects when npm returns a 404", function(done) { @@ -74,8 +92,6 @@ describe('nodes/registry/installer', function() { done(); }).otherwise(function(err) { done(err); - }).finally(function() { - addModule.restore(); }); }); it("rejects when non-existant path is provided", function(done) { @@ -101,8 +117,6 @@ describe('nodes/registry/installer', function() { done(); }).otherwise(function(err) { done(err); - }).finally(function() { - addModule.restore(); }); }); @@ -132,8 +146,6 @@ describe('nodes/registry/installer', function() { done(new Error("Unexpected success")); }).otherwise(function(err) { done(); - }).finally(function() { - removeModule.restore(); }); }); it("succeeds when module is found", function(done) { @@ -148,7 +160,7 @@ describe('nodes/registry/installer', function() { cb(null,"",""); }); - var exists = sinon.stub(require('fs'),"existsSync", function(fn) { return true; }); + var exists = sinon.stub(fs,"existsSync", function(fn) { return true; }); installer.uninstallModule("this_wont_exist").then(function(info) { info.should.eql(nodeInfo); @@ -158,10 +170,6 @@ describe('nodes/registry/installer', function() { done(); }).otherwise(function(err) { done(err); - }).finally(function() { - removeModule.restore(); - exists.restore(); - getModuleInfo.restore(); }); }); });