Node.js摩卡unit testing错误重新:蒙哥马与Mockgoose嘲笑,“错误设置集合:会话TTL索引”

在GitHub上创build这个开放源码的应用程序,在Daftmonk的强大的Yeoman angular – 全堆生成器构build的Outer / Partybot-web.git

我一直试图把我的技能包括在Node.js的testing(本地和CI)期间做MongoDB mock这个似乎很热的当代问题。

我是摩卡的粉丝,因为奔跑和的断言。 在淘汰了许多早期的竞争者之后,我现在正在用Mockgoose来嘲讽Mongoose模型来代替MongoDB。

在Travis的开放源代码partybot-web CI中也可以看到与这个问题有关的版本

到目前为止,这种configuration已经能够成功运行一些数据库操作,certificate了Mockgoose不是完全浪费时间。 然而,这个“会议”表似乎是在扼杀它。

请参阅下面的示例本地执行(Ubuntu 12),并让我知道如果任何节点向导有一个智慧的明珠…

非常感谢! -缺口

nick@om-ultrabook-ubuntu:~/Development/partybot-web$ mocha test/server/api/incoming/sms.js info - socket.io started Express server listening on port 3000 in development mode Error: Error setting TTL index on collection : sessions at /home/nick/Development/partybot-web/node_modules/connect-mongo/lib/connect-mongo.js:161:23 at /home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1404:28 at /home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1542:30 at /home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:159:22 at commandHandler (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:678:48) at /home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1806:9 at __executeQueryCommand (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1636:44) at Db._executeQueryCommand (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1805:7) at Cursor.nextObject (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:729:13) at Cursor.toArray (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:158:10) at Cursor.toArray (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/scope.js:10:20) at /home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1541:65 at Db.collection (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:495:44) at Db.indexInformation (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1539:8) at Db.ensureIndex (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1403:8) at Collection.ensureIndex (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/collection/index.js:65:11) at /home/nick/Development/partybot-web/node_modules/connect-mongo/lib/connect-mongo.js:159:29 at Db.collection (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:495:44) at MongoStore._get_collection (/home/nick/Development/partybot-web/node_modules/connect-mongo/lib/connect-mongo.js:150:17) at MongoStore.set (/home/nick/Development/partybot-web/node_modules/connect-mongo/lib/connect-mongo.js:262:12) at Session.save (/home/nick/Development/partybot-web/node_modules/express/node_modules/connect/node_modules/express-session/session/session.js:63:25) at ServerResponse.res.end (/home/nick/Development/partybot-web/node_modules/express/node_modules/connect/node_modules/express-session/index.js:304:19) at twilioResponse (/home/nick/Development/partybot-web/lib/controllers/incoming.js:19:7) at Promise.<anonymous> (/home/nick/Development/partybot-web/lib/controllers/incoming.js:58:5) at Promise.<anonymous> (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/mpromise/lib/promise.js:177:8) at Promise.EventEmitter.emit (events.js:98:17) at Promise.emit (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/mpromise/lib/promise.js:84:38) at Promise.fulfill (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/mpromise/lib/promise.js:97:20) at handleSave (/home/nick/Development/partybot-web/node_modules/mongoose/lib/model.js:133:13) at /home/nick/Development/partybot-web/node_modules/mongoose/lib/utils.js:408:16 at /home/nick/Development/partybot-web/node_modules/mockgoose/lib/Collection.js:116:13 at Object.validateOptions [as validate] (/home/nick/Development/partybot-web/node_modules/mockgoose/lib/validation/Validation.js:40:5) at Collection.insert (/home/nick/Development/partybot-web/node_modules/mockgoose/lib/Collection.js:110:20) at model.save (/home/nick/Development/partybot-web/node_modules/mongoose/lib/model.js:190:21) at model._done (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/hooks/hooks.js:59:24) at _next (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/hooks/hooks.js:52:28) at fnWrapper (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/hooks/hooks.js:159:8) at model.<anonymous> (/home/nick/Development/partybot-web/lib/models/message.js:31:3) at _next (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/hooks/hooks.js:50:30) at fnWrapper (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/hooks/hooks.js:159:8) at complete (/home/nick/Development/partybot-web/node_modules/mongoose/lib/document.js:974:5) at /home/nick/Development/partybot-web/node_modules/mongoose/lib/document.js:965:20 at ObjectId.SchemaType.doValidate (/home/nick/Development/partybot-web/node_modules/mongoose/lib/schematype.js:603:22) at /home/nick/Development/partybot-web/node_modules/mongoose/lib/document.js:956:9 at process._tickCallback (node.js:415:13) GET /api/incoming/sms 200 21ms ․db connection open POST /api/incoming/sms 200 6ms 

Solutions Collecting From Web of "Node.js摩卡unit testing错误重新:蒙哥马与Mockgoose嘲笑,“错误设置集合:会话TTL索引”"

Node.js Express框架的“会话”模块在这里要求“会话”MongoDB集合:

 Session.save (node_modules/express-session/session/session.js:63:25) 

我一直在使用Mockgoose来模拟我的Mongoose包装的MongoDB表格, 而且它完美地完成了它的工作

问题是这个“sessions”集合是在Express框架configuration中直接指定的, 而不是实现Mongoose

  // Persist sessions with mongoStore app.use(express.session({ secret: 'angular-fullstack secret', store: new mongoStore({ url: config.mongo.uri, collection: 'sessions' }, function () { console.log("db connection open"); }) })); 

我将不得不分开我的快速会议嘲笑!

并不是所有的mongoose都已经完全实施。 但是,如果你可以添加一个testing用例来显示这个问题,那么我通常会把重点放在我的清单上的其他项目上。

https://github.com/mccormicka/Mockgoose/issues/38

我遇到了同样的问题 – 我的解决scheme是使用express-session的memorystore选项(默认情况下,没有指定其他的时候),而不是mongodb。 真的很快,我只是这样做:

 if (process.env.NODE_ENV === 'test') { app.use(session({ secret: config.sessionSecret })); } else { app.use(session({ secret: config.sessionSecret, store: new mongoStore({ //db: db.connection.db, mongoose_connection: db.connection, collection: config.sessionCollection }) })); }