Tag: 摩卡

摩卡supertest ECONNRESET

我正在用Mocha和SupertesttestingNodejs服务器。 testing套件已经发展到1500多个testing。 突然之间,虽然所有的testing代码仍然有效,但是我的testing套件却失败了,并报错: { [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' } 如果我注释掉一些先前运行的testing,导致错误更改的testing。 什么导致这种精神错乱?

节点(Gulp)process.stdout.write到文件

我正在尝试为我进行unit testing,并将testing覆盖率输出到.lcov文件。 这是我迄今为止: gulp.task('test', function () { var test = fs.createWriteStream('./test.lcov', {flags: 'a'}); return gulp.src('./assets/js/test/test.js', {read: false}) .pipe(mocha({reporter: 'mocha-lcov-reporter'})) .pipe(test); }); mocha-lcov-reporter代码可以在这里find: https : //github.com/StevenLooman/mocha-lcov-reporter/blob/master/lib/lcov.js 它通过process.stdout.write()输出结果 但是,当我pipe这个到一个WriteStream我有以下错误: TypeError: Invalid non-string/buffer chunk at validChunk (_stream_writable.js:152:14) at WriteStream.Writable.write (_stream_writable.js:181:12) at Stream.ondata (stream.js:51:26) at Stream.emit (events.js:95:17) at drain (/Users/braunromain/Documents/dev/should-i-go/node_modules/gulp-mocha/node_modules/through/index.js:36:16) at Stream.stream.queue.stream.push (/Users/braunromain/Documents/dev/should-i-go/node_modules/gulp-mocha/node_modules/through/index.js:45:5) at Stream.stream (/Users/braunromain/Documents/dev/should-i-go/node_modules/gulp-mocha/index.js:27:8) at Stream.stream.write (/Users/braunromain/Documents/dev/should-i-go/node_modules/gulp-mocha/node_modules/through/index.js:26:11) […]

如何忽略伊斯坦布尔覆盖范围内node.js中的所需文件

在我的代码中,我有var es = require('event-stream'); 在我的package.json中,我有 "scripts": { "test": "istanbul cover ./node_modules/mocha/bin/_mocha — -R spec", } 我只想覆盖我的主文件,但它也涵盖事件stream的文件,所以我得到的东西 =============================== Coverage summary =============================== Statements : 24.74% ( 757/3060 ) Branches : 5.42% ( 88/1625 ) Functions : 15.56% ( 70/450 ) Lines : 25.37% ( 735/2897 ) ================================================================================ 有没有办法只覆盖我自己的代码?

如果testing失败,如何让Mocha在源文件中显示正确的行号?

我正在使用Mocha进行NodeJStesting,当由于源代码抛出错误而导致testing失败时(例如“ TypeError: Cannot read property 'prop' of null ”),显示的堆栈跟踪中的行号是错误的(它们与原始源文件不匹配,但是更大)。 1) MyApp should do something: TypeError: Cannot read property 'prop' of null at MyApp.<anonymous> (/path/to/my-project/lib/my-project.js:515:93) at MyApp.build (/path/to/my-project/lib/my-project.js:774:16) at Context.<anonymous> (/path/to/my-project/test/test.js:62:67) at Test.Runnable.run (/path/to/my-project/node_modules/mocha/lib/runnable.js:216:15) at Runner.runTest (/path/to/my-project/node_modules/mocha/lib/runner.js:373:10) at /path/to/my-project/node_modules/mocha/lib/runner.js:451:12 at next (/path/to/my-project/node_modules/mocha/lib/runner.js:298:14) at /path/to/my-project/node_modules/mocha/lib/runner.js:308:7 at next (/path/to/my-project/node_modules/mocha/lib/runner.js:246:23) at Object._onImmediate (/path/to/my-project/node_modules/mocha/lib/runner.js:275:5) at processImmediate [as _immediateCallback] (timers.js:330:15) (这里my-project.js只有279行!) […]

testing一个函数与Mocha调用另一个函数

我有一个关于在Mocha中testingNode.js的具体情况的问题。 假设我在我的应用程序中有以下代码… function a() { //… } function b() { //… } function c() { if(condition) { a(); } else { b(); } } 如果我正在testing函数c,我怎么能确认函数a或函数b被调用? 有没有办法做到这一点?

在Mocha中描述()是什么

我正在试着用摩卡弄脏我的双手,这里是我从文档中看到的例子: var assert = require("assert") describe('Array', function(){ describe('#indexOf()', function(){ it('should return -1 when the value is not present', function(){ assert.equal(-1, [1,2,3].indexOf(5)); assert.equal(-1, [1,2,3].indexOf(0)); }) }) }) 大多数例子显示了第二个描述语句 describe('#indexOf()', function(){ 从#indexOf() #开始。 这个#的意义是什么? 为什么这不能简单地写成indexOf ? 我在哪里可以得到对描述如何工作的基本理解? PS:我查看了http://visionmedia.github.io/mocha/#interfaces的文档,但无法弄清楚这些是如何进入画面的,以及这些接口是如何处理的。 谢谢

Sinon – 如何存根嵌套函数?

道歉,如果这是一个简单的问题,我是相对较新的节点和Sinon。 我努力想弄清楚如何断言在Nodejs中调用了一个嵌套的asynchronous函数。 我正在使用摩卡,柴,sinon和请求( https://github.com/request/request ),但认为我遗漏了一些基本的部分。 在my_app.js里面的例子 – var request = require('request'); function MyModule() { }; MyModule.prototype.getTicker = function(callback) { request('http://example.com/api/ticker', function(error, response) { if (error) { callback(error); } else { callback(null, response); } }); }; exports.mymodule = new MyModule(); 在testing里面。 我正在试图剔除请求并提供一些虚拟数据返回。 但我不断收到一个错误“请求未定义”在我创build存根的行上。 var myApp = require('../my_app.js') ,assert = require("assert") ,chai = require('chai') ,sinon = require('sinon') […]

航行js运行testing

我试图运行我的帆unit testing(使用摩卡和伊斯坦布尔) 运行时 grunt test 我得到的错误 1) "before all" hook 2) "after all" hook 0 passing (5s) 2 failing 1) "before all" hook: Error: timeout of 2000ms exceeded at null.<anonymous> (/vagrant/node_modules/mocha/lib/runnable.js:157:19) at Timer.listOnTimeout [as ontimeout] (timers.js:112:15) 2) "after all" hook: ReferenceError: sails is not defined 设置似乎没有find我的风帆,但是在做 which sails 我明白了 /usr/local/node/node-default/bin/sails 并运行sails lift工作正常 这是我的项目中的摩卡testing文件 //boostrap.test.js var […]

摩卡运行与NPMtesting,但不正常的摩卡CLI命令

我试图了解在这种情况下我做错了什么。 在我的package.json中有一个Node.js项目 "scripts": { "test": "mocha –recursive ./src/setup/*.js ./test/**/*.js" }, "dependencies": { "mocha": "^2.2.5" } 当我运行'npmtesting'时,摩卡testing正确运行: $ npm test (successful run) 但是,当我尝试只运行我的package.json在那里的摩卡指令 $ mocha –recursive ./src/setup/*.js ./test/**/*.js" 这个错误与: -sh: mocha: command not found 我没有摩卡全球安装,我只有通过npm安装它到这个特定的项目。 如果我安装摩卡全球然后它的作品。 为什么当我在当前目录的node_modules中只安装了mocha,而它却使用'npm test'呢?

摩卡全球范围内的问题

我正在使用我正在使用的全局对象的mochatesting时遇到了一个大问题。 我能够产生下面的MRE,它没有给出完全相同的错误,但是例证了有问题的(越野车?)行为。 任何有识之士将不胜感激。 我在/lib有以下main.js文件: exports.exec = function(){ console.log(test); } 接下来在/test/test.js : var should = require('should'); var main = require('../lib/main'); global.test = {something: 1}; describe('normal test', function(){ beforeEach(function(){ global.test = {another: 2}; }), afterEach(function(){ delete global.test; }); it ('might work with global', function(){ main.exec(); }) }); 最后,这是test/test2.js : var should = require('should'); var main = require('../lib/main'); […]