mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add event log to editor
Shows output from git pull/push and npm install in the editor
This commit is contained in:
@@ -21,9 +21,6 @@ var path = require("path");
|
||||
var fs = require('fs');
|
||||
var EventEmitter = require('events');
|
||||
|
||||
var child_process = require('child_process');
|
||||
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
var installer = NR_TEST_UTILS.require("@node-red/registry/lib/installer");
|
||||
@@ -42,16 +39,21 @@ describe('nodes/registry/installer', function() {
|
||||
_: function() { return "abc"}
|
||||
}
|
||||
|
||||
before(function() {
|
||||
installer.init({log:mockLog, settings:{}, events: new EventEmitter()});
|
||||
beforeEach(function() {
|
||||
installer.init({log:mockLog, settings:{}, events: new EventEmitter(), exec: {
|
||||
run: function() {
|
||||
return Promise.resolve("");
|
||||
}
|
||||
}});
|
||||
});
|
||||
function initInstaller(execResult) {
|
||||
installer.init({log:mockLog, settings:{}, events: new EventEmitter(), exec: {
|
||||
run: function() {
|
||||
return execResult;
|
||||
}
|
||||
}});
|
||||
}
|
||||
afterEach(function() {
|
||||
if (child_process.spawn.restore) {
|
||||
child_process.spawn.restore();
|
||||
}
|
||||
if (child_process.execFile.restore) {
|
||||
child_process.execFile.restore();
|
||||
}
|
||||
if (registry.addModule.restore) {
|
||||
registry.addModule.restore();
|
||||
}
|
||||
@@ -76,39 +78,33 @@ describe('nodes/registry/installer', function() {
|
||||
|
||||
describe("installs module", function() {
|
||||
it("rejects when npm returns a 404", function(done) {
|
||||
sinon.stub(child_process,"spawn",function(cmd,args,opt) {
|
||||
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;
|
||||
});
|
||||
|
||||
var res = {
|
||||
code: 1,
|
||||
stdout:"",
|
||||
stderr:" 404 this_wont_exist"
|
||||
}
|
||||
var p = Promise.reject(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
installer.installModule("this_wont_exist").catch(function(err) {
|
||||
err.should.have.property("code",404);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("rejects when npm does not find specified version", function(done) {
|
||||
sinon.stub(child_process,"spawn",function(cmd,args,opt) {
|
||||
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;
|
||||
});
|
||||
var res = {
|
||||
code: 1,
|
||||
stdout:"",
|
||||
stderr:" version not found: this_wont_exist@0.1.2"
|
||||
}
|
||||
var p = Promise.reject(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
sinon.stub(typeRegistry,"getModuleInfo", function() {
|
||||
return {
|
||||
version: "0.1.1"
|
||||
}
|
||||
});
|
||||
|
||||
installer.installModule("this_wont_exist","0.1.2").catch(function(err) {
|
||||
err.code.should.be.eql(404);
|
||||
done();
|
||||
@@ -126,17 +122,14 @@ describe('nodes/registry/installer', function() {
|
||||
});
|
||||
});
|
||||
it("rejects with generic error", function(done) {
|
||||
sinon.stub(child_process,"spawn",function(cmd,args,opt,cb) {
|
||||
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;
|
||||
});
|
||||
|
||||
var res = {
|
||||
code: 1,
|
||||
stdout:"",
|
||||
stderr:" kaboom!"
|
||||
}
|
||||
var p = Promise.reject(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
installer.installModule("this_wont_exist").then(function() {
|
||||
done(new Error("Unexpected success"));
|
||||
}).catch(function(err) {
|
||||
@@ -145,15 +138,16 @@ describe('nodes/registry/installer', function() {
|
||||
});
|
||||
it("succeeds when module is found", function(done) {
|
||||
var nodeInfo = {nodes:{module:"foo",types:["a"]}};
|
||||
sinon.stub(child_process,"spawn",function(cmd,args,opt) {
|
||||
var ee = new EventEmitter();
|
||||
ee.stdout = new EventEmitter();
|
||||
ee.stderr = new EventEmitter();
|
||||
setTimeout(function() {
|
||||
ee.emit('close',0);
|
||||
},10)
|
||||
return ee;
|
||||
});
|
||||
|
||||
var res = {
|
||||
code: 0,
|
||||
stdout:"",
|
||||
stderr:""
|
||||
}
|
||||
var p = Promise.resolve(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
|
||||
var addModule = sinon.stub(registry,"addModule",function(md) {
|
||||
return when.resolve(nodeInfo);
|
||||
});
|
||||
@@ -191,15 +185,15 @@ describe('nodes/registry/installer', function() {
|
||||
return when.resolve(nodeInfo);
|
||||
});
|
||||
var resourcesDir = path.resolve(path.join(__dirname,"resources","local","TestNodeModule","node_modules","TestNodeModule"));
|
||||
sinon.stub(child_process,"spawn",function(cmd,args,opt) {
|
||||
var ee = new EventEmitter();
|
||||
ee.stdout = new EventEmitter();
|
||||
ee.stderr = new EventEmitter();
|
||||
setTimeout(function() {
|
||||
ee.emit('close',0);
|
||||
},10)
|
||||
return ee;
|
||||
});
|
||||
|
||||
var res = {
|
||||
code: 0,
|
||||
stdout:"",
|
||||
stderr:""
|
||||
}
|
||||
var p = Promise.resolve(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
installer.installModule(resourcesDir).then(function(info) {
|
||||
info.should.eql(nodeInfo);
|
||||
done();
|
||||
@@ -226,9 +220,14 @@ describe('nodes/registry/installer', function() {
|
||||
var removeModule = sinon.stub(registry,"removeModule",function(md) {
|
||||
return when.resolve(nodeInfo);
|
||||
});
|
||||
sinon.stub(child_process,"execFile",function(cmd,args,opt,cb) {
|
||||
cb(new Error("test_error"),"","");
|
||||
});
|
||||
var res = {
|
||||
code: 1,
|
||||
stdout:"",
|
||||
stderr:"error"
|
||||
}
|
||||
var p = Promise.reject(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
|
||||
installer.uninstallModule("this_wont_exist").then(function() {
|
||||
done(new Error("Unexpected success"));
|
||||
@@ -244,9 +243,14 @@ describe('nodes/registry/installer', function() {
|
||||
var getModuleInfo = sinon.stub(registry,"getModuleInfo",function(md) {
|
||||
return {nodes:[]};
|
||||
});
|
||||
sinon.stub(child_process,"execFile",function(cmd,args,opt,cb) {
|
||||
cb(null,"","");
|
||||
});
|
||||
var res = {
|
||||
code: 0,
|
||||
stdout:"",
|
||||
stderr:""
|
||||
}
|
||||
var p = Promise.resolve(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
|
||||
sinon.stub(fs,"statSync", function(fn) { return {}; });
|
||||
|
||||
|
22
test/unit/@node-red/runtime/lib/exec_spec.js
Normal file
22
test/unit/@node-red/runtime/lib/exec_spec.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
var exec = NR_TEST_UTILS.require("@node-red/runtime/lib/exec");
|
Reference in New Issue
Block a user