Tag: 摩卡

testing同步代码

我有一段使用节点同步的代码,如下所示: function funcA() { return new Promise(function(resolve, reject) { Sync(function () { return funcB.sync(); }, function (err, result) { if(err) { reject(err); } else { resolve(result); } }); } 这段代码使用mocha + chai进行testing: it("should return array", function() { return funcA().then(function(result) { expect(result).to.be.an.instanceof(Array); }); }); 几个月前它工作得很好,但现在这个testing总是超时: 错误:超过2000毫秒超时。 确保在此testing中正在调用done()callback。 我到目前为止所尝试的是: 使用done()而不是返回一个promise 用syncize.jsreplacenode-sync synchronize.js 增加超时 我发现的是, expect(…这个testing的一部分实际上是被调用的,但是只有在mocha杀死testing之后,无论目前设置了什么超时间隔, expect(..总是被称为〜 20毫秒后我得到Error: […]

用SailsJS和Superagent运行摩卡testing

我目前正在使用SailsJS编写一个应用程序。 到目前为止所做的工作都是按照“手动”进行testing,但是在使用Mocha进行testing时没有发生。 我试图按照SailsJStesting指南 ,用npm调用testing: […] "scripts": { "start": "node app.js", "debug": "node debug app.js", "test": "mocha test/bootstrap.test.js test/unit/**/*.test.js" }, […] 我的testing目录结构如下: test ├── bootstrap.test.js ├── mocha.opts └── unit └── controllers └── UserController.test.js boostrap.test.js: var Sails = require('sails'); var sails; before(function(done) { Sails.lift(function(err, server) { sails = server; if (err) return done(err); done(err, sails); }); }); […]

轮询一个URL,直到在JSON响应中设置了一定的值:Mocha,集成testing

我正在使用Mocha自动化端到端场景。 我有一个url端点被轮询,直到得到一个特定的值在得到的响应。 有没有办法做到这一点?

摩卡作为一个图书馆

我想使用mocha(node.jstesting框架,而不是ruby mocking库)作为库,而不是使用mocha可执行文件来运行我的testing。 这样可以进行摩卡testing吗? 这些例子都假设它们已经是“需要”的,就叫做mocha库,而mocha可执行文件提前完成所有的“require-ing”,但是我真的希望在脚本中明确地做到这一点,这样我就可以简单地在我的脚本上设置+ x并直接调用它。 我可以做这样的事吗? #!/usr/bin/env coffee mocha = require 'mocha' test = mocha.Test suite = mocha.Suite assert = require("chai").assert thing = null suite "Logging", () -> setup (done) -> thing = new Thing() done() test "the thing does a thing.", (done) -> thing.doThing () -> assert.equal thing.numThingsDone, 1 done() teardown (done) -> thing […]

摩卡与节点:只显示testing失败的日志logging

我使用摩卡和winston的节点。 有没有办法设置它,所以它只显示失败的testing日志?

Express JS与Supertest和模拟数据库的集成testing

是否可以使用supertesttestingExpress JS REST API,但用模拟数据库对象replace实际的数据库连接? 我有unit testing覆盖数据库模型和应用程序的其他部分,以及API端点的functiontesting,使得实际的数据库连接,但我有一个奇怪的要求,创build像functiontesting,但使用模拟数据库连接的集成testing。 示例端点控制器如下所示: var model = require('../../../lib/models/list'); module.exports = { index: function(req, res) { var data = { key: 'domains', table: 'demo.events'}; var dataModel = new model(data); dataModel.query().then(function(results) { res.respond({data: results}, 200); }).fail(function(err) { console.log(err); res.respond({message: 'there was an error retrieving data'}, 500); }); } }; 而URI的索引是 var express = require('express'), […]

运行只有一个摩卡testing文件的变化与吞噬

我有一个标准的吞咽testing观察者和亚军我的Node.js /摩卡安装程序; gulp.task('mocha', function() { process.env.NODE_ENV = 'test'; return gulp.src(['./test/**/*.js'], {read: false}) .pipe(mocha({ recursive: true, reporter: 'list', ui: 'bdd' })).on('error', gutil.log); }); gulp.task('tests', function() { gulp.watch(sources.concat(tests), ['mocha']); }); 我想知道如何调整我的观察任务(和其他),只发送给摩卡的已经改变了的testing – 所以我不必等待20秒就可以运行一百个testing。 我已经尝试了这个fgulp-newer和gulp-cached,但没有运气。 我在这里寻找一个答案或一个吞咽插件的伪algorithm,我可以为此写:)

使用grunt-mocha-test创buildtesting组

我正在使用grunt-mocha-test来运行节点服务器端testing。 我的Gruntfile.js看起来像这样 module.exports = function(grunt) { // Add the grunt-mocha-test tasks. grunt.loadNpmTasks('grunt-mocha-test'); grunt.initConfig({ // Configure a mochaTest task mochaTest: { test: { options: { reporter: 'dot' }, src: [ 'test/setup.js', 'test/*.test.js' ] } }, }); grunt.registerTask('default', 'mochaTest'); }; 我想要做的是这个,我想能够运行不同的testing组,使用不同的命令如下 grunt将运行所有的testing grunt test1运行testing文件夹中的一个testing子集 grunt test2运行另一个testing子集 我不知道这是否可能,而且在grunt-mocha-test的文档中我还没有find任何有关这方面的信息 我可以肯定在这里使用一些帮助。 谢谢

如何为node.js应用程序的mochatesting运行make命令

我创build了一个文件夹: MyFirstNodeAppl ,在其中创build了一个testing文件夹,其中包含了所有需要使用mocha框架运行的testing。 我还创build了一个名为MakeFile的make文件,其内容如下所示: test: @./node_modules/.bin/mocha -u tdd .PHONY: test package.json与test和MakeFile处于同一级别,其内容如下: { "name": "nockmarket", "version": "0.0.1", "private": true, "dependencies": { "jquery" : "1.7.3", "mocha": "1.3.0", "should": "1.0.0" } } 设置完上述内容后,我使用节点命令提示符窗口运行npm install命令。 现在我知道Mocha使用make来运行testing工具,而对于Windows用户,我们需要Cygwin,所以我将它安装在我的系统中。 但是我不能运行make命令来testingunit testing用例。 任何人都可以帮助我解决这个问题,在上面给我提供指导。 文件夹结构细节:

使用伊斯坦布尔和摩卡来覆盖ES6的代码

我有用ES6编写的Node代码,通过发布mocha –harmonytesting。 testing很好 – 一切正常。 现在我想添加覆盖和伊斯坦布尔的混合,但我不断遇到遇到的第一个箭头函数的错误: No coverage information was collected, exit without writing coverage information c:\Users\Guy\Code\alpha-dev\tests\helpers.js:12 setTimeout(() => { ^ SyntaxError: Unexpected token ) at exports.runInThisContext (vm.js:73:16) at Module._compile (module.js:443:25) at Module._extensions..js (module.js:478:10) at Object.Module._extensions..js (c:\Users\Guy\Code\alpha-dev\node_modules\istanbul\lib\hook.js:101:13) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) 这是我的尝试: 安装伊斯坦布尔和谐(从git://github.com/gotwarlost/istanbul.git#harmony)作为我的开发依赖。 运行以下命令: "./node_modules/.bin/istanbul" cover "./node_modules/mocha/bin/_mocha" — –harmony tests […]