我正在尝试使用节点child_process执行curl以从本地网络中的共享文件夹获取JSON文件(大约220Ko).但它实际上返回了一个我无法解决的缓冲问题.这是我的代码:
var exec = require('child_process').exec;
var execute = function(command, callback){
exec(command, function(error, stdout, stderr){ callback(error, stdout); });
};
execute("curl http://" + ip + "/file.json", function(err, json, outerr) {
if(err) throw err;
console.log(json);
})
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
if(err) throw err;
^
Error: stdout maxBuffer exceeded.
at Socket.<anonymous> (child_process.js:678:13)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at Pipe.onread (net.js:526:21)
Run Code Online (Sandbox Code Playgroud) 我正在使用Jasmine来测试我的角度应用程序,并希望监视一个匿名函数.使用angular-notify服务https://github.com/cgross/angular-notify,我想知道是否已经调用了通知功能.
这是我的控制器:
angular.module('module').controller('MyCtrl', function($scope, MyService, notify) {
$scope.isValid = function(obj) {
if (!MyService.isNameValid(obj.name)) {
notify({ message:'Name not valid', classes: ['alert'] });
return false;
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的测试:
'use strict';
describe('Test MyCtrl', function () {
var scope, $location, createController, controller, notify;
beforeEach(module('module'));
beforeEach(inject(function ($rootScope, $controller, _$location_, _notify_) {
$location = _$location_;
scope = $rootScope.$new();
notify = _notify_;
notify = jasmine.createSpy('spy').andReturn('test');
createController = function() {
return $controller('MyCtrl', {
'$scope': scope
});
};
}));
it('should call notify', function() {
spyOn(notify);
controller …Run Code Online (Sandbox Code Playgroud)