1
0
Эх сурвалжийг харах

test(core): Fix e2e plugin tests

Michael Bromley 6 жил өмнө
parent
commit
0d6cb3121a

+ 19 - 1
packages/core/e2e/fixtures/test-plugins.ts

@@ -46,9 +46,23 @@ export class TestPluginWithAllLifecycleHooks
     }
     onVendureClose(): void | Promise<void> {
         TestPluginWithAllLifecycleHooks.onCloseFn();
+        this.resetSpies();
     }
     onVendureWorkerClose(): void | Promise<void> {
         TestPluginWithAllLifecycleHooks.onWorkerCloseFn();
+        this.resetSpies();
+    }
+
+    /**
+     * This is required because on the first run, the Vendure server will be bootstrapped twice -
+     * once to populate the database and the second time forthe actual tests. Thus the call counts
+     * for the plugin lifecycles will be doubled. This method resets them after the initial
+     * (population) run.
+     */
+    private resetSpies() {
+        TestPluginWithAllLifecycleHooks.onConstructorFn.mockClear();
+        TestPluginWithAllLifecycleHooks.onBootstrapFn.mockClear();
+        TestPluginWithAllLifecycleHooks.onWorkerBootstrapFn.mockClear();
     }
 }
 
@@ -165,7 +179,7 @@ export class TestPluginWithProvider {}
         return config;
     },
 })
-export class TestPluginWithConfigAndBootstrap implements OnVendureBootstrap {
+export class TestPluginWithConfigAndBootstrap implements OnVendureBootstrap, OnVendureClose {
     private static boostrapWasCalled: any;
     static setup(boostrapWasCalled: (arg: any) => void) {
         TestPluginWithConfigAndBootstrap.boostrapWasCalled = boostrapWasCalled;
@@ -176,4 +190,8 @@ export class TestPluginWithConfigAndBootstrap implements OnVendureBootstrap {
     onVendureBootstrap() {
         TestPluginWithConfigAndBootstrap.boostrapWasCalled(this.configService);
     }
+
+    onVendureClose() {
+        TestPluginWithConfigAndBootstrap.boostrapWasCalled.mockClear();
+    }
 }