Tag: mocha

closuresOpenLink Virtuoso HTTP连接

我们使用OpenLink Virtuoso作为NodeJS项目的主要数据库pipe理器。 我们只通过HTTP SPARQL端点使用SPARQL查询来查询数据库。 为此,我们使用request-promise库,具有以下configuration: const queryRequest = rp({ method: "POST", uri: queryObject.fullUrl, form: { query: queryObject.query, maxrows: queryObject.maxRows, format: queryObject.resultsFormat }, headers: { 'content-type': 'application/x-www-form-urlencoded' }, json: true, forever : true, // Keep connections alive instead of creating new ones timeout : Config.dbOperationTimeout, }) .then(function (parsedBody) { 运行我们的testing时,我们启动应用程序(新的快速应用程序对象和nodejs服务器)数百次,并试图closures它干净。 应用程序closures,服务器也,但我认为,virtuoso连接保持开放,因为连接的数量不断增加,尽pipe我们正试图重用现有的连接。 close()方法(将应用程序closures)运行这些函数: const closePendingConnections = function(callback) […]

用mocha-chai superagenttesting多个同时进行的会话

我正在尝试编写多个套接字连接的testing,我需要多个会话(同时) ,因为它们由服务器端的会话ID标识。 在下面的例子client1将连接和握手将通过与会话ID的cookie,所以我可以使用express-socket.io会话获取该用户的会话数据…. 我遇到的问题是,当我想连接第二个套接字,握手数据传递通过显然将是相同的第一个套接字。 我不能只发送一个注销请求,并更改用户,因为我试图testing多人游戏function。 var agent = chai.request.agent(app) describe("authentication", function () { it('login as user', function (done) { agent .post('/login') .send({ username: username, password: password }) .then(function (res) { expect(res).to.have.status(200); expect(res).to.have.cookie('connect.sid'); done() }) .catch(function (err) { done(err) }) }); }) describe("socket tests", function () { var client1, client2; it('can connect to socket', function (done) […]

Sinon存根并testingAWS-SDK的承诺

//正在testing的类 var AWS = require('aws-sdk'); var s3Export = function() { var s3Client = new AWS.S3(); this.getObject => (params) => { return s3Client.getObject(params).promise(); } }; module.exports.S3 = new s3Export(); //testing类 describe('s3-wrapper-tests', function() { var app, aws, s3, getObjectData = {Bucket: 'test-bucket', Key: 'test-file'}, deleteObjectData, deleteObjectsDatas, putObject; before(() => { s3 = sinon.stub({ getObject: function(params) { getObjectData […]

摩卡和柴:写作断言

我正在使用摩卡和柴第一次写testing用例。 这是我的服务返回的非常简单的响应: { "success": true, "message": "Done" } 我写过这样的断言: describe('GET /TestService', function() { it('should run successfully.', function(done) { request .get('/myApp/TestService/') .expect(200) .expect('Content-Type', 'application/json') .end(function(err, res) { expect(res.body.success).to.equal(true); expect(res.body.message).to.equal('Done'); }); }); }); 当我执行testing时,它返回: Uncaught AssertionError:预计未定义为等于true 这有什么问题? 这是我第一次遇到摩卡和柴。 也许我错过了一个非常基本的东西。 这只是第一步。 有人能推我吗?

摩卡testing不返回mongod保存

我在使用nodejs,MongoDB和mochatesting用户validation方法时遇到了麻烦。 错误 ^CHarrys-MacBook-Pro:Phonex hcbh96$ npm run test-watch > ls@1.0.0 test-watch /Users/hcbh96/Desktop/PhonexDevelopment/Phonex > nodemon –exec 'npm test' [nodemon] 1.12.1 [nodemon] to restart at any time, enter `rs` [nodemon] watching: *.* [nodemon] starting `npm test` > ls@1.0.0 test /Users/hcbh96/Desktop/PhonexDevelopment/Phonex > mocha tests/**/*.test.js Node app is running at localhost: + 3000 Post /tempUser { phone: '5005550006', countryCode: '+1', […]

摩卡和JSCover

我正在使用摩卡testing我的nodejs代码。 我想获得一份报道。 我find了我试图运行的JSCover 。 但是我越来越 ReferenceError: _$jscoverage is not defined 我正在执行: java -jar ../tools/jscover/JSCover-all.jar –no-instrument=node_modules -fs api/ api-coverage test: @NODE_ENV=test ./node_modules/.bin/mocha \ –require expect.js \ –reporter $(REPORTER) \ –timeout 2000 \ –growl \ $(TESTS) COVERAGE_ENABLED=1 $(MAKE) test REPORTER=html-file-cov 任何帮助?

使用Mocha和should.js进行NodeJStesting数据库

我用摩卡testing我的NodeJS应用程序,应该。 第一次testing顺利进行时,第二次失败(错误等于空)。 在这两个testing中,如果在callback中有一个有效的用户(两者在mongoose中都有相同的ID)。 testing显然不等待数据库操作发生。 describe("User", function(){ before(function (done) { // clear database model.UserModel.collection.remove(done); }) it("should save", function(done){ user1.save(function(error, user){ should.not.exist(error); user.should.have.property("first_name", "Rainer"); done(); }) }) it("should not save duplicate user", function(done){ user1.save(function(error, user){ should.exist(error); done(); }) }) }) 当我在第一个testing的callback中放置第二个testing时,它也不起作用。 我想testing一个重复的键错误,但不能达到给定的情况。

制造unit testing的git回购

我在节点中的function应该返回最近修改(1天)的文件列表中的git。 该function基本上做类似的东西 git diff –name-only $(git rev-list -n1 –before="1 day ago" HEAD) 要么 git log –since="1.day" –name-only –oneline 所以,我想validation函数做它应该做的。 所以,在摩卡testing中,我有: var tmp = require('tmp'); describe('Git test', function() { var today = new Date(); var threedays = new Date(); var yesterday = new Date(); threedays.setDate(today.getDate() – 3); yesterday.setDate(today.getDate() – 1); beforeEach(function(done) { tmp.dir({ template: '/tmp/test-XXXXXX', unsafeCleanup: […]

指定可通过节点,Nodemon或Istanbul / Mocha执行的Node应用程序同样可用的optimist / minimist命令行选项

所以我有很多方法来运行我的节点应用程序: 生产和运行WebDrivertesting: node app.js 发展 nodemon app.js 摩卡testing istanbul cover node_modules/mocha/bin/_mocha — -R spec 我想使用Optimist / Minimist模块来处理命令行选项,但是,有什么办法来提供这些参数的所有上述命令以一贯的方式处理我的应用程序?

ChaiJS不处理exception

这是一个NodeJS模块: var plural = function(words, num) { if (words.length != 3) { throw new Error('Wrong words array'); } var lastNum = num % 10; var second = (num / 10) % 10; if (second == 1) return words[2] else if (lastNum == 1) return words[0]; else if (lastNum <= 4) return words[1]; else return words[2]; […]