简体   繁体   中英

How to Initialize Feathers instance for Jest once

I'd like to have just a single instance of feathers "app" when a run jest tests. this is how I import app in every test:

const app = require('../../src/app');

describe(`service`, () => {
  it('registered the service', () => {
    const service = app.service('my-service');
    expect(service).toBeTruthy();
  });

The problem is that this is creating an instance app and I have over 100 tests, this quickly eats up all of postgres connections,

my app file exports like this:

const app = express(feathers());
app.configure(express.rest()); 
app.configure(objection);
// ... some more configs and bells & whistles
module.exports = app;

I thought about opening a socket as a client in the test suite, and instead of importing "app" I open a connection as a client, but thinking of alternatives to that in a test context.

What you are getting there is the single instance of the app. There is no initialization overhead for importing the module multiple times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM