Tag: 摩卡

在Windows上开发并构build在Linux上的代码上使用NodeJs的Grunt?

如何使用nodejs构build跨平台项目? 我在Windows上开发,但是我的代码库build立在一个基于Linux的CI服务器上。 它使用Grunt构build前端,并且需要几个nodejs模块。 Nodejs需要将模块本地安装到项目中,以便由grunt.task.loadNpmTasks加载。 这个问题是我必须从Windows或Linux的某个地方安装它们,而当我从一个地方安装它时,它不能在另一个地方工作。 我的项目需要的列表模块安装在本地,如下所示: npm install connect-livereload –production npm install time-grunt –production npm install load-grunt-tasks –production npm install jshint-stylish –production npm install load-grunt-tasks –production npm install grunt-contrib-copy –production npm install grunt-contrib-concat –production npm install grunt-contrib-uglify –production npm install grunt-contrib-compass –production npm install grunt-contrib-jshint –production npm install grunt-contrib-cssmin –production npm install grunt-contrib-connect –production npm […]

在需要的时候,扼杀/嘲笑一个返回函数的库

所以我试图嘲弄或存根电话咆哮图书馆。 当需要的时候,它会返回一个函数,当被调用时会触发一个咆哮通知。 我无法弄清楚如何在我的testing中模拟或者删除它。 这是我迄今为止所尝试的: /* /lib/some_code.js */ var growl = require('growl'); exports.some_func = function() { growl('A message', { title: 'Title' }); }; (注:我使用sinon-chai来expression我的观点) /* /test/some_code.js */ var growl = require('growl') , some_code = require('../lib/some_code'); describe('Some code', function() { it('sends a growl notification', function(done) { var growlStub = sinon.stub(growl); some_code.some_func(); growlStub.should.have.been.called; done(); }); });

使用Gulp,Mocha,Browserify进行正确configuration,以执行服务器端testing的客户端testing

我正在开发一个节点应用程序,利用我们的构build过程中的gulp-mocha以及我们testing运行者的gulp-mocha插件。 gulp.task('test', function () { return gulp.src(TESTJS) .pipe(mocha({reporter: 'spec'})) .on("error", function (err) { // handle the mocha errors so that they don't cloud the test results, // or end the watch console.log(err.toString()); this.emit('end'); }); }); 目前TESTJS只是我的服务器端testing。 我想要使​​用相同的过程来执行我的客户端testing。 我看了一下, gulp-blanket-mocha并给了它一枪,但我一直遇到同样的问题。 当试图testing我的主干代码时,它失败了,因为testing运行器找不到其他客户端组件(即jquery ),并且失败。 我得知我需要使用像phantomJS这样的无phantomJS webkit。 但是我真的很难搞清楚如何将这一点与browserify结合到一起。 任何人试图得到像这样的设置,或者有什么想法,我在这里失去了我的吞咽“testing”任务执行我的客户端摩卡testing以及我的服务器端?

摩卡列表只能跳过testing

我有数百个摩卡testing,其中几十个正在跳过。 我想运行该套件,但只列出跳过的,所以我可以解决它们。 有没有人知道一个方法来实现这一目标? 似乎没有一个命令行标志

如何模拟通过require创build的对象

我是node.js的新手,在大多数代码中,我没有看到依赖关系的IoC / DI样式构造函数注入。 相反,通常使用node.js扩展require()来创build允许访问外部模块导出的本地variables。 但是当编写unit testing(隔离单层/函数)时,如何模拟通过使用require创build的variables访问的模块? /helpers/dataHelper.js var dataModel = require('../models/dataModel.js'); var getFormattedDataForRegion = function(region, callback) { var data = {}; // validate region // query dataModel // async.map format data items // callback(data); } /tests/dataHelperTests.js describe('dataHelper', function(){ it('getFormattedDataForRegion returns expected response', function(done){ var expectedData = {}; // populate expectedData // **** need some way […]

超时使用mongoose createConnection与摩卡testing

我有一个mongoose.createConnection函数的问题,这里是我的testing代码: "use strict"; // connect to mongodb://localhost/node_marque_test // empty database before each test let mongoose = require('mongoose'), expect = require('chai').expect, // use a specific base for test purposes dbURI = 'mongodb://localhost/node_marque_test', Marque = require('../lib/marque.js'); before(function(done){ // connect to db let connection = mongoose.createConnection(dbURI); // remove all documents connection.on('open', function(){ Marque.remove(function(err, marques){ if(err){ console.log(err); throw(err); } […]

我如何构buildnode.js摩卡testing

我非常喜欢在node.js中进行unit testing,我想知道在node.js中编写unit testing的最佳做法是什么,比如'it'方法可以有多less个asserttesting用例,有没有什么标准只用一个方法写一个testing用例。 请给我一个写unit testing用例的想法。 提前致谢。:)

运行摩卡testing会导致“意外的保留字”错误

STEP: npm test 错误:“意外的保留字” 今天早些时候我做了这个工作,并没有意识到我所做的任何可能导致回归的东西。 当我运行npm test我得到“意外的保留字”,它指向一个ES6导入语句。 我的理解是 – –compilers js:babel-register应该解决这个问题。 我曾尝试在全局和本地安装babel-core ,并使用babel-core/register代替。 同样的结果。 这是我的package.json 。 { "name": "fresh", "version": "0.0.1", "private": true, "scripts": { "remotedev": "remotedev –hostname=localhost –port=8000", "start": "node node_modules/react-native/local-cli/cli.js start", "test": "mocha –compilers js:babel-register 'test/**/*.test.js'", "test:watch": "npm run test — –watch –watch-extensions jsx" }, "dependencies": { "immutable": "^3.7.6", "lodash": "^4.5.1", "ramda": "^0.19.1", […]

ES2016类,Sinon存根构造器

我正在试着用一个超级电话来剔除,而且我没有太多的运气。 任何想法,为什么这是行不通的? 运行Node 6.2.2,这可能是其实现类/构造函数的一个问题。 .babelrc文件: { "presets": [ "es2016" ], "plugins": [ "transform-es2015-modules-commonjs", "transform-async-to-generator" ] } testing: import sinon from 'sinon'; class Foo { constructor(message) { console.log(message) } } class Bar extends Foo { constructor() { super('test'); } } describe('Example', () => { it('should stub super.constructor call', () => { sinon.stub(Foo.prototype, 'constructor'); new Bar(); sinon.assert.calledOnce(Foo.prototype.constructor); […]

如何以时间顺序运行摩卡testing?

我有一套基于全局事件发射器运行的模块。 他们按照时间顺序的事件运行,如下所示: boot.ready 服务器创build(因为boot.ready事件) 服务器configuration(由于server.created事件) 因此,我需要创build一个server-test.js按照时间顺序执行testing。 摩卡这可能吗? 像下面的东西? var EventEmitter2 = require('eventemitter2').EventEmitter2, should = require('should'); describe('server', function() { var mediator = new EventEmitter2({ wildcard: false }); require('../../src/routines/server/creator')(mediator); require('../../src/routines/server/configurer')(mediator); it('should be created after boot', function(done) { mediator.once('server.created', function(server) { server.should.exist; done(); }); it('should be configured after created', function(done) { mediator.once('server.configured', function() { done(); }); }); mediator.emit('boot.ready'); […]