gulpfile.jsvarshell=require('gulp-shell');gulp.task('startRedis',shell.task(['redis-2.8.15/src/redis-server>/dev/null&']));当我运行上面的startRedisgulp任务时,它会启动redis服务器但永远不会退出。$gulpstartRedis[19:03:42]Usinggulpfile~/myhome/gulpfile.js[19:03:42]Starting'startRedis'...如果我停止redis服务器,它就会返回。不知道哪里出了问题,请帮忙。
我正在使用promises使用mocha(3.2)和supertest(3.0)测试我的其余应用程序(在节点上使用hapi制作)。它在超时后停止并返回错误:Error:Timeoutof2000msexceeded.Forasynctestsandhooks,ensure"done()"iscalled;ifreturningaPromise,ensureitresolves.我已经尝试增加超时,但没有成功。如果我添加一个done()调用,我会得到:Resolutionmethodisoverspecified.SpecifyacallbackorreturnaPromise;notb
所以我正在开发一个express.js应用程序,其中我有一个Mongoose模型用户。我编写了一个测试文件(使用Mocha)来测试save()函数,但我所有的测试执行时间太长,最终超时。这是我遇到的错误:Testing-Server-User-ModelTestingsave()1)shouldbeabletosavewithoutproblems2)shouldfailtosaveanexisitnguseragain3)shouldshouldanerrorwhentrytosavewithemptyemail4)shouldgiveanerrorwhentrytosavewith
根据AlexeyB.的评论,我修改了我的测试代码,并从我的测试代码中找到了导致相同错误的情况。当我尝试测试单个测试文件时,它运行良好。但是,如果我尝试同时测试多个测试文件,它就会损坏。常见的错误消息是Error:Tryingtoopenunclosedconnection.。看来我的数据库连接代码有一些问题。这是我修改后的代码。utils.js:varmongoose=require('mongoose');module.exports=function(models){returnfunction(done){for(variinmodels){models[i].remove({}
我的mocha测试失败了:MongoError:serverXXXXsocketsclosed我有解决方法:consthttps=require('https');constserver=https.createServer(..);close(){mongoose.disconnect();//我会注释掉mongoose.disconnect();行,然后我的测试套件开始工作。我也想在测试后进行清理。我的每个测试文件都重新创建服务器并从头开始。似乎出现错误是因为在执行下一个测试文件之前需要一些“等待”。我该如何纠正这个错误? 最佳答案
我正在使用Mocha、Mongoose和MongoDB。我的目标只是围绕创建帐户进行测试。我有以下代码:require("./../../config/config");varmongoose=require("mongoose");mongoose.connect(process.env.MONGODB_URI);constexpect=require("expect");var{Account}=require("./../../models/account");describe("AccountCreation",()=>{it("shouldsuccessfullycreate
我正在使用mocha-mongoose在测试之间自动清除mongo。在文档中,它说在您的规范文件中或在您的规范助手中全局需要该模块。按照规范执行此操作效果很好,但我想从mocha.opts执行此操作以保持我的代码干燥。用mocha.opts要求它不起作用。规范之间未清除Mongomocha.opts:--require./test/common.js--reporterspec--uibdd--recursive--colors--timeout60000--slow300通用.js:require('mocha-mongoose')('mongodb://your-mongodb-u
Seedebuggeroutputherevarexpect=require('chai').expectvarUser=require('../../app/models/index.js').Userdescribe('ModelUser',function(){it('addauser',function(done){varuser=newUser({uname:'cx',password:'cx'})user.save()//Model#save()returnPromise.then(function(user,effectNum){done()//successstate}
我一直收到超时错误,它一直告诉我确认我已经调用了done(),即使我已经调用了。constmocha=require('mocha');constassert=require('assert');constStudent=require('../models/student.js');describe('CRUDTests',function(){it('CreateRecord',function(done){vars=newStudent({name:"Yash"});s.save().then(function(){assert(s.isNew===false);done();}
我一直在到处寻找这个。有些人似乎是这样mongoose.connect('mongodb://localhost/test');然后继续他们的describe调用。那么异步等待呢?vardb=mongoose.connection;db.on('error',console.error.bind(console,'connectionerror:'));db.once('open',function(callback){//yay!});我应该如何在Mocha测试中使用此连接?我应该将所有测试都放在回调中吗?我应该将等待连接的代码包装在单元测试中吗?连接是否会在describe和it之