mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Update installer tests for spawn
This commit is contained in:
parent
4b129d94e4
commit
92a65dcda5
@ -19,6 +19,7 @@ var sinon = require("sinon");
|
|||||||
var when = require("when");
|
var when = require("when");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var EventEmitter = require('events');
|
||||||
|
|
||||||
var child_process = require('child_process');
|
var child_process = require('child_process');
|
||||||
var installer = require("../../../../../red/runtime/nodes/registry/installer");
|
var installer = require("../../../../../red/runtime/nodes/registry/installer");
|
||||||
@ -31,6 +32,9 @@ describe('nodes/registry/installer', function() {
|
|||||||
installer.init({});
|
installer.init({});
|
||||||
});
|
});
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
|
if (child_process.spawn.restore) {
|
||||||
|
child_process.spawn.restore();
|
||||||
|
}
|
||||||
if (child_process.execFile.restore) {
|
if (child_process.execFile.restore) {
|
||||||
child_process.execFile.restore();
|
child_process.execFile.restore();
|
||||||
}
|
}
|
||||||
@ -58,8 +62,15 @@ describe('nodes/registry/installer', function() {
|
|||||||
|
|
||||||
describe("installs module", function() {
|
describe("installs module", function() {
|
||||||
it("rejects when npm returns a 404", function(done) {
|
it("rejects when npm returns a 404", function(done) {
|
||||||
sinon.stub(child_process,"execFile",function(cmd,args,opt,cb) {
|
sinon.stub(child_process,"spawn",function(cmd,args,opt) {
|
||||||
cb(new Error(),""," 404 this_wont_exist");
|
var ee = new EventEmitter();
|
||||||
|
ee.stdout = new EventEmitter();
|
||||||
|
ee.stderr = new EventEmitter();
|
||||||
|
setTimeout(function() {
|
||||||
|
ee.stderr.emit('data'," 404 this_wont_exist");
|
||||||
|
ee.emit('close',1);
|
||||||
|
},10)
|
||||||
|
return ee;
|
||||||
});
|
});
|
||||||
|
|
||||||
installer.installModule("this_wont_exist").otherwise(function(err) {
|
installer.installModule("this_wont_exist").otherwise(function(err) {
|
||||||
@ -68,8 +79,15 @@ describe('nodes/registry/installer', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("rejects when npm does not find specified version", function(done) {
|
it("rejects when npm does not find specified version", function(done) {
|
||||||
sinon.stub(child_process,"execFile",function(cmd,args,opt,cb) {
|
sinon.stub(child_process,"spawn",function(cmd,args,opt) {
|
||||||
cb(new Error(),""," version not found: this_wont_exist@0.1.2");
|
var ee = new EventEmitter();
|
||||||
|
ee.stdout = new EventEmitter();
|
||||||
|
ee.stderr = new EventEmitter();
|
||||||
|
setTimeout(function() {
|
||||||
|
ee.stderr.emit('data'," version not found: this_wont_exist@0.1.2");
|
||||||
|
ee.emit('close',1);
|
||||||
|
},10)
|
||||||
|
return ee;
|
||||||
});
|
});
|
||||||
sinon.stub(typeRegistry,"getModuleInfo", function() {
|
sinon.stub(typeRegistry,"getModuleInfo", function() {
|
||||||
return {
|
return {
|
||||||
@ -94,8 +112,15 @@ describe('nodes/registry/installer', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("rejects with generic error", function(done) {
|
it("rejects with generic error", function(done) {
|
||||||
sinon.stub(child_process,"execFile",function(cmd,args,opt,cb) {
|
sinon.stub(child_process,"spawn",function(cmd,args,opt,cb) {
|
||||||
cb(new Error("test_error"),"","");
|
var ee = new EventEmitter();
|
||||||
|
ee.stdout = new EventEmitter();
|
||||||
|
ee.stderr = new EventEmitter();
|
||||||
|
setTimeout(function() {
|
||||||
|
ee.stderr.emit('data'," kaboom!");
|
||||||
|
ee.emit('close',1);
|
||||||
|
},10)
|
||||||
|
return ee;
|
||||||
});
|
});
|
||||||
|
|
||||||
installer.installModule("this_wont_exist").then(function() {
|
installer.installModule("this_wont_exist").then(function() {
|
||||||
@ -106,8 +131,14 @@ describe('nodes/registry/installer', function() {
|
|||||||
});
|
});
|
||||||
it("succeeds when module is found", function(done) {
|
it("succeeds when module is found", function(done) {
|
||||||
var nodeInfo = {nodes:{module:"foo",types:["a"]}};
|
var nodeInfo = {nodes:{module:"foo",types:["a"]}};
|
||||||
sinon.stub(child_process,"execFile",function(cmd,args,opt,cb) {
|
sinon.stub(child_process,"spawn",function(cmd,args,opt) {
|
||||||
cb(null,"","");
|
var ee = new EventEmitter();
|
||||||
|
ee.stdout = new EventEmitter();
|
||||||
|
ee.stderr = new EventEmitter();
|
||||||
|
setTimeout(function() {
|
||||||
|
ee.emit('close',0);
|
||||||
|
},10)
|
||||||
|
return ee;
|
||||||
});
|
});
|
||||||
var addModule = sinon.stub(registry,"addModule",function(md) {
|
var addModule = sinon.stub(registry,"addModule",function(md) {
|
||||||
return when.resolve(nodeInfo);
|
return when.resolve(nodeInfo);
|
||||||
@ -146,8 +177,14 @@ describe('nodes/registry/installer', function() {
|
|||||||
return when.resolve(nodeInfo);
|
return when.resolve(nodeInfo);
|
||||||
});
|
});
|
||||||
var resourcesDir = path.resolve(path.join(__dirname,"..","resources","local","TestNodeModule","node_modules","TestNodeModule"));
|
var resourcesDir = path.resolve(path.join(__dirname,"..","resources","local","TestNodeModule","node_modules","TestNodeModule"));
|
||||||
sinon.stub(child_process,"execFile",function(cmd,args,opt,cb) {
|
sinon.stub(child_process,"spawn",function(cmd,args,opt) {
|
||||||
cb(null,"","");
|
var ee = new EventEmitter();
|
||||||
|
ee.stdout = new EventEmitter();
|
||||||
|
ee.stderr = new EventEmitter();
|
||||||
|
setTimeout(function() {
|
||||||
|
ee.emit('close',0);
|
||||||
|
},10)
|
||||||
|
return ee;
|
||||||
});
|
});
|
||||||
installer.installModule(resourcesDir).then(function(info) {
|
installer.installModule(resourcesDir).then(function(info) {
|
||||||
info.should.eql(nodeInfo);
|
info.should.eql(nodeInfo);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user