node.js - Supertest + Knex.js = 当前客户端上没有定义池

标签 node.js mocha.js supertest knex.js

我正在使用 supertest(在 Mocha 内)来测试我的应用程序,该应用程序目前正在使用 knex.js 来实现数据库目的。

旧版本的 knex (0.5.x) 一切运行良好。现在我想使用最新的 knex 版本。

大多数场景下,使用

request = supertest(app)

对我来说工作得很好,但是还有其他场景我需要测试多个请求而不重复使用cookie,所以...

request = supertest.agent(app)

这会发生什么?

最终出现主题中描述的错误。我在 knex 库中添加了一些自定义日志“acquireConnection”、“releaseConnection”、“initializePool”和“destroy”函数,以查看发生了什么,输出如下:

Adquiring connection from pool {someCustomPoolIdYSet)
Adquiring connection from pool {someCustomPoolIdYSet)
Releasing connection from pool {someCustomPoolIdYSet)
Adquiring connection from pool {someCustomPoolIdYSet)
Adquiring connection from pool undefined
[Error] ........ "There is no pool defined on the current client"

如有任何帮助,我们将不胜感激。 提前致谢。

最佳答案

所以,我们终于发现了!

问题出在 Passport.js 上,默认情况下它始终被用作单例。每次我们引导应用程序时,都会在 Passport 中注入(inject)一个新的序列化器,但它会保留以前的序列化器。然后,那些一开始就被注入(inject)的人的池子就被毁了……然后轰隆隆!

关于node.js - Supertest + Knex.js = 当前客户端上没有定义池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33397332/

相关文章:

node.js - LoopBack 用户特定的数据过滤/访问

node.js - 将图像写入本地服务器

javascript - Node js从对象数组中创建特定模式的对象

php - 长插入查询

javascript - should.js 不会导致 mocha 测试失败

javascript - Jest : Wait for an async test to finish before running the next one

javascript - 是什么导致我的测试中出现 "Uncaught Error: write after end"?

javascript - 使用 rewire/cross-env 获取覆盖率报告时出错

supertest - 如何在 Apache 超集中添加大于过滤器?

node.js - Mocha 超测ECONNRESET