问题描述
在运行笑话测试时,我只希望有一个羽毛“ app”实例。这是我在每次测试中导入应用程序的方式:
const app = require('../../src/app');
describe(`service`,() => {
it('registered the service',() => {
const service = app.service('my-service');
expect(service).toBeTruthy();
});
问题在于,这正在创建一个实例应用,并且我有100多个测试,这很快就吞噬了所有postgres连接,
我的应用程序文件导出如下:
const app = express(feathers());
app.configure(express.rest());
app.configure(objection);
// ... some more configs and bells & whistles
module.exports = app;
我考虑过在测试套件中以客户端的身份打开套接字,而不是导入“ app”,而是以客户端的身份打开连接,但是在测试环境中考虑了替代方法。
解决方法
您到达那里的 是应用程序的单个实例。多次导入模块没有初始化开销。