Tag: unit testing

摩卡:以编程方式创build并完成testing

我想要代理testing结果在其他环境上实时运行。 下面是一些我想实现的伪代码: var test = proxy.getCurrentTest(); // => {slow: 200, timeout: 2000, duration: 235, result: 'error'}; var tmpIt = it('test1', function(){ this.slow(test.slow); this.timeout(test.timeout); }); tmpIt.close({ duration: test.duration, result: test.result }); // this should make this test red in the output, // because the `result` is not 'success' 无论如何设置testing的结果和持续时间没有“真正”运行吗? 并获得所有的视觉摩卡输出到terminal? 编辑:这个问题不是关于如何将testing结果forms的subprocess传递给主进程。 它已经在为我工作。

咕嘟,摩卡,手表不重新加载我的源文件

我正试图让gulp工作来帮助自动化一些unit testing。 我有以下gulp文件。 var gulp = require('gulp'), mocha = require('gulp-mocha'); gulp.task('unit', function() { return gulp.src('test/unit/**/*.js') .pipe(mocha({ reporter: 'spec' })) .on('error', handleError); }); gulp.task('watch', function() { gulp.watch(['src/**/*.js', 'test/unit/**/*.js'], ['unit']); }); gulp.task('test', ['unit', 'watch']); 当我运行“吞吐单位”时,testing运行良好。 当我运行“吞噬testing”时,testing运行,看起来“看”正在工作。 如果我对其中一个testing文件进行了更改,则考虑到我在testing文件中所做的更改,testing会正确地重新运行。 如果我对源文件进行了更改,那么testing也会重新运行,但不会针对源文件的更新版本运行。 我的想法是,不知何故,源文件被caching,但我找不到任何似乎有这个问题或find解决scheme的其他人。 感谢帮助这个Gulp / Node / Mocha的新手!

SyntaxError:使用Web组件testing程序注释时出现意外的标记ILLEGAL

我使用Codeship来testing基于聚合物入门套件v1.1的项目 。 当我在testingpipe道内运行npm test ,看到以下错误: > @ test /home/rof/src/github.com/TFarla/night-live > gulp test:local /home/rof/src/github.com/TFarla/night-live/node_modules/browser-sync/node_modules/lodash/index.js:8404 /** ^^^ SyntaxError: Unexpected token ILLEGAL at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:413:25) at Object.Module._extensions..js (module.js:452:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) at require (module.js:384:17) at Object.<anonymous> (/home/rof/src/github.com/TFarla/night-live/node_modules/browser-sync/lib/hooks.js:3:20) at Module._compile (module.js:434:26) at Object.Module._extensions..js (module.js:452:10) npm ERR! Test failed. See above […]

伊斯坦布尔的摩卡testing代码覆盖率

我正试图让伊斯坦布尔工作。 我在伊斯坦布尔运行结束时一直收到这个消息: 没有收集覆盖信息,没有写覆盖信息退出 我已经尝试了一切,我可以在网上find你可以看到: "scripts": { "start": "node ./bin/start.js", "test": "mocha test –no-timeouts", "debug_mocha": "node-debug –no-timeouts _mocha", "eslint": "eslint .", "jshint": "jshint –exclude ./node_modules .", "istanbul": "istanbul cover –include-all-sources –hook-run-in-context node_modules/.bin/_mocha — -u exports -R spec test/**/*", "istanbul2":"istanbul cover node_modules/.bin/_mocha — -u exports -R spec test/**/*", "istanbul1":"istanbul cover node_modules/.bin/_mocha — test/**/*", "istanbul0":"istanbul cover _mocha test/**/*.js", […]

在Node.js中模拟模块进行unit testing

我想unit testingnode.js模块中的一些function。 我认为嘲笑第三个模块会有帮助。 特别要避免碰到数据库 # models/account.coffee register = (email, password)-> sha_sum.update(password) pw = sha_sum.digest('hex') user = email: email password: sha_sum.digest('hex') users_db.save user, (err, doc)-> register_callback(err) account_module = register: register module.exports = account_module 这是我想testing的模块 # routes/auth.coffee account = require '../models/account' exports.auth = post_signup: (req, res)-> email = req.body.email password = req.body.password if email and password account.register(email, […]

testingMongoose Node.JS应用程序

我正在尝试为我的Node应用程序的部分编写unit testing。 我正在使用Mongoose作为我的ORM。 我已经search了一堆如何使用Mongoose和Node进行testing,但没有任何东西。 解决scheme/框架似乎都是完整的,或者没有提到嘲笑的东西。 有没有办法我可以嘲笑我的Mongoose数据库,所以我可以在我的testing中返回静态数据? 我宁愿不必设置testing数据库,并填写每个unit testing的数据。 有人遇到过这种情况么?

摩卡失败断言造成超时

我正在开始使用NodeJS的摩卡testing框架。 成功断言工作正常,但如果断言失败,我的testing超时。 为了断言我已经尝试了应该和期望。 例如(asynchronous代码) it('should create new user', function(done){ userService.create(user).then(function(model){ expect(model.id).to.be(1); //created user ID done(); }, done) }); 在这里,如果模型id不是1,那么testing超时而不是报告失败的断言。 我确定我做错了什么。 感谢你的帮助。 谢谢!

如何unit testingexpress路由器路由

我是Node和Express的新手,我试图unit testing我的路线/控制器。 我已经从我的控制器中分离出我的路线。 我如何去testing我的路线? configuration/ express.js var app = express(); // middleware, etc var router = require('../app/router')(app); 应用程序/路由器/ index.js module.exports = function(app) { app.use('/api/books', require('./routes/books')); }; 应用程序/路由器/路由/ books.js var controller = require('../../api/controllers/books'); var express = require('express'); var router = express.Router(); router.get('/', controller.index); module.exports = router; 应用程序/ API /控制器/ books.js // this is just an example […]

unit testing与mongoose

我是Node.js,Mongoose和在这个环境中testing的新手。 我有以下模式在一个单独的文件中声明。 Issue = mongoose.model("Issue", { identifier: String, date: String, url: String, name: String, thumbnailURL: String }); 然后我有这个方法,它只是返回MongoDB集合中的所有Issue实例。 function issues(request, response) { response.setHeader('Content-Type', 'text/json'); Issue.find().sort('date').exec(function(error, items) { if (error) { response.send(403, {"status": "error", "error:": exception}); } else { response.send(200, {"issues": items}); } }); } 我已经通过实验得到了很多,现在我想testing它,但是我遇到了一个问题。 我怎么去testing它,而没有build立一个MongoDB连接等。我知道我可以设置所有的东西,但这是一个集成testing。 我想编写unit testing来testing如下的东西: 函数是否正确设置内容types 函数按date字段进行sorting 发生错误时函数是否返回403? … 等等 我很好奇,看看我可以重构我现有的代码,使其更容易testing。 我已经尝试过创build第二个被调用的函数,接受response和Item模式对象作为参数,但是感觉不对。 […]

使用Bookshelf.js和knex.js进行unit testing

我对Node相对比较陌生,正在使用knex和bookshelf开展一个项目。 我有一些unit testing我的代码有点麻烦,我不知道我做错了什么。 基本上我有一个模型(称为VorcuProduct),看起来像这样: var VorcuProduct = bs.Model.extend({ tableName: 'vorcu_products' }); module.exports.VorcuProduct = VorcuProduct 还有一个function可以将VorcuProduct保存在数据库中。 非常简单。 这样做的function如下所示: function subscribeToUpdates(productInformation, callback) { model.VorcuProduct .where({product_id: productInformation.product_id, store_id: productInformation.store_id}) .fetch() .then(function(existing_model) { if (existing_model == undefined) { new model.VorcuProduct(productInformation) .save() .then(function(new_model) { callback(null, new_model)}) .catch(callback); } else { callback(null, existing_model) } }) } 哪种方法可以正确testing而不碰到数据库? 我需要模拟fetch返回一个模型或未定义(取决于testing),然后做同样的save ? 我应该使用rewire吗? 正如你可以看到我有点失落,所以任何帮助将不胜感激。 […]