with-all-lifecycle-hooks.ts 793 B

123456789101112131415161718192021222324
  1. import { INestApplication, INestMicroservice } from '@nestjs/common';
  2. export class TestPluginWithAllLifecycleHooks {
  3. private static onConstructorFn: any;
  4. static init(constructorFn: any) {
  5. this.onConstructorFn = constructorFn;
  6. return this;
  7. }
  8. constructor() {
  9. TestPluginWithAllLifecycleHooks.onConstructorFn();
  10. }
  11. /**
  12. * This is required because on the first run, the Vendure server will be bootstrapped twice -
  13. * once to populate the database and the second time for the actual tests. Thus the call counts
  14. * for the plugin lifecycles will be doubled. This method resets them after the initial
  15. * (population) run.
  16. */
  17. private resetSpies() {
  18. TestPluginWithAllLifecycleHooks.onConstructorFn.mockClear();
  19. }
  20. }