How to Initialize Feathers instance for Jest once

Viewed 364

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.

1 Answers

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

Related