Share compiled module reference across test cases

Viewed 46

I have got a standard unit test for nestjs application

// test.spec.ts

describe('test case', () => {

  beforeAll(async () => {
    module = await createTestingModule();
  });
});

// testSetup.ts

export async function createTestingModule() {
  return Test.createTestingModule({
      imports: [AppModule],
  }).compile();
}

But Test.createTestingModule is called in every test case which takes some time. Can I somehow save the reference to the compiled module and reuse it in other tests?

  • first test runs createTestingModule, compiles the module and save the reference
  • next tests runs createTestingModule, but instead of compiling it they will use reference

Script I use to run tests jest --setupFiles dotenv/config --coverage --runInBand --detectOpenHandles --forceExit --logHeapUsage

I was trying to store it in process object but i think its not possible this way.

0 Answers
Related