@etohq/test-utils 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/database.d.ts +29 -0
  2. package/dist/database.d.ts.map +1 -0
  3. package/dist/database.js +139 -0
  4. package/dist/database.js.map +1 -0
  5. package/dist/eto-test-runner-utils/bootstrap-app.d.ts +10 -0
  6. package/dist/eto-test-runner-utils/bootstrap-app.d.ts.map +1 -0
  7. package/dist/eto-test-runner-utils/bootstrap-app.js +59 -0
  8. package/dist/eto-test-runner-utils/bootstrap-app.js.map +1 -0
  9. package/dist/eto-test-runner-utils/clear-instances.d.ts +8 -0
  10. package/dist/eto-test-runner-utils/clear-instances.d.ts.map +1 -0
  11. package/dist/eto-test-runner-utils/clear-instances.js +14 -0
  12. package/dist/eto-test-runner-utils/clear-instances.js.map +1 -0
  13. package/dist/eto-test-runner-utils/config.d.ts +5 -0
  14. package/dist/eto-test-runner-utils/config.d.ts.map +1 -0
  15. package/dist/eto-test-runner-utils/config.js +31 -0
  16. package/dist/eto-test-runner-utils/config.js.map +1 -0
  17. package/dist/eto-test-runner-utils/index.d.ts +6 -0
  18. package/dist/eto-test-runner-utils/index.d.ts.map +1 -0
  19. package/dist/eto-test-runner-utils/index.js +22 -0
  20. package/dist/eto-test-runner-utils/index.js.map +1 -0
  21. package/dist/eto-test-runner-utils/use-db.d.ts +15 -0
  22. package/dist/eto-test-runner-utils/use-db.d.ts.map +1 -0
  23. package/dist/eto-test-runner-utils/use-db.js +56 -0
  24. package/dist/eto-test-runner-utils/use-db.js.map +1 -0
  25. package/dist/eto-test-runner-utils/utils.d.ts +2 -0
  26. package/dist/eto-test-runner-utils/utils.d.ts.map +1 -0
  27. package/dist/eto-test-runner-utils/utils.js +10 -0
  28. package/dist/eto-test-runner-utils/utils.js.map +1 -0
  29. package/dist/eto-test-runner.d.ts +31 -0
  30. package/dist/eto-test-runner.d.ts.map +1 -0
  31. package/dist/eto-test-runner.js +144 -0
  32. package/dist/eto-test-runner.js.map +1 -0
  33. package/dist/events.d.ts +3 -0
  34. package/dist/events.d.ts.map +1 -0
  35. package/dist/events.js +41 -0
  36. package/dist/events.js.map +1 -0
  37. package/dist/id-map.d.ts +7 -0
  38. package/dist/id-map.d.ts.map +1 -0
  39. package/dist/id-map.js +22 -0
  40. package/dist/id-map.js.map +1 -0
  41. package/dist/index.d.ts +10 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +44 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/init-modules.d.ts +18 -0
  46. package/dist/init-modules.d.ts.map +1 -0
  47. package/dist/init-modules.js +45 -0
  48. package/dist/init-modules.js.map +1 -0
  49. package/dist/jest.d.ts +2 -0
  50. package/dist/jest.d.ts.map +1 -0
  51. package/dist/jest.js +24 -0
  52. package/dist/jest.js.map +1 -0
  53. package/dist/mock-event-bus-service.d.ts +9 -0
  54. package/dist/mock-event-bus-service.d.ts.map +1 -0
  55. package/dist/mock-event-bus-service.js +19 -0
  56. package/dist/mock-event-bus-service.js.map +1 -0
  57. package/dist/module-test-runner.d.ts +24 -0
  58. package/dist/module-test-runner.d.ts.map +1 -0
  59. package/dist/module-test-runner.js +148 -0
  60. package/dist/module-test-runner.js.map +1 -0
  61. package/dist/tsconfig.tsbuildinfo +1 -0
  62. package/package.json +60 -0
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.etoIntegrationTestRunner = etoIntegrationTestRunner;
4
+ const utils_1 = require("@etohq/framework/utils");
5
+ const awilix_1 = require("awilix");
6
+ const database_1 = require("./database");
7
+ const eto_test_runner_utils_1 = require("./eto-test-runner-utils");
8
+ function etoIntegrationTestRunner({ moduleName, dbName, etoConfigFile, schema = "public", env = {}, debug = false, inApp = false, testSuite, }) {
9
+ const tempName = parseInt(process.env.JEST_WORKER_ID || "1");
10
+ moduleName = moduleName ?? Math.random().toString(36).substring(7);
11
+ dbName ??= `eto-${moduleName.toLowerCase()}-integration-${tempName}`;
12
+ let dbConfig = {
13
+ dbName,
14
+ clientUrl: (0, database_1.getDatabaseURL)(dbName),
15
+ schema,
16
+ debug,
17
+ };
18
+ const cwd = etoConfigFile ?? process.cwd();
19
+ let shutdown = async () => void 0;
20
+ const dbUtils = (0, database_1.dbTestUtilFactory)();
21
+ let globalContainer;
22
+ let apiUtils;
23
+ let loadedApplication;
24
+ let options = {
25
+ api: new Proxy({}, {
26
+ get: (target, prop) => {
27
+ return apiUtils[prop];
28
+ },
29
+ }),
30
+ dbConnection: new Proxy({}, {
31
+ get: (target, prop) => {
32
+ return dbUtils.pgConnection_[prop];
33
+ },
34
+ }),
35
+ getEtoApp: () => loadedApplication,
36
+ getContainer: () => globalContainer,
37
+ dbConfig: {
38
+ dbName,
39
+ schema,
40
+ clientUrl: dbConfig.clientUrl,
41
+ },
42
+ dbUtils,
43
+ };
44
+ let isFirstTime = true;
45
+ const beforeAll_ = async () => {
46
+ await (0, eto_test_runner_utils_1.configLoaderOverride)(cwd, dbConfig);
47
+ (0, eto_test_runner_utils_1.applyEnvVarsToProcess)(env);
48
+ const { logger, container, EtoAppLoader } = await import("@etohq/framework");
49
+ const appLoader = new EtoAppLoader();
50
+ container.register({
51
+ [utils_1.ContainerRegistrationKeys.LOGGER]: (0, awilix_1.asValue)(logger),
52
+ });
53
+ try {
54
+ console.log(`Creating database ${dbName}`);
55
+ await dbUtils.create(dbName);
56
+ dbUtils.pgConnection_ = await (0, eto_test_runner_utils_1.initDb)();
57
+ }
58
+ catch (error) {
59
+ console.error("Error initializing database", error?.message);
60
+ throw error;
61
+ }
62
+ console.log(`Migrating database with core migrations and links ${dbName}`);
63
+ await (0, eto_test_runner_utils_1.migrateDatabase)(appLoader);
64
+ await (0, eto_test_runner_utils_1.syncLinks)(appLoader, cwd, container);
65
+ await (0, eto_test_runner_utils_1.clearInstances)();
66
+ let containerRes = container;
67
+ let serverShutdownRes;
68
+ let portRes;
69
+ loadedApplication = await appLoader.load();
70
+ try {
71
+ const { shutdown = () => void 0, container: appContainer, port, } = await (0, eto_test_runner_utils_1.startApp)({
72
+ cwd,
73
+ env,
74
+ });
75
+ containerRes = appContainer;
76
+ serverShutdownRes = shutdown;
77
+ portRes = port;
78
+ }
79
+ catch (error) {
80
+ console.error("Error starting the app", error?.message);
81
+ throw error;
82
+ }
83
+ /**
84
+ * Run application migrations and sync links when inside
85
+ * an application
86
+ */
87
+ if (inApp) {
88
+ console.log(`Migrating database with core migrations and links ${dbName}`);
89
+ await (0, eto_test_runner_utils_1.migrateDatabase)(appLoader);
90
+ await (0, eto_test_runner_utils_1.syncLinks)(appLoader, cwd, containerRes);
91
+ }
92
+ const { default: axios } = (await import("axios"));
93
+ const cancelTokenSource = axios.CancelToken.source();
94
+ globalContainer = containerRes;
95
+ shutdown = async () => {
96
+ await serverShutdownRes();
97
+ cancelTokenSource.cancel("Request canceled by shutdown");
98
+ };
99
+ apiUtils = axios.create({
100
+ baseURL: `http://localhost:${portRes}`,
101
+ cancelToken: cancelTokenSource.token,
102
+ });
103
+ };
104
+ const beforeEach_ = async () => {
105
+ // The beforeAll already run everything, so lets not re run the loaders for the first iteration
106
+ if (isFirstTime) {
107
+ isFirstTime = false;
108
+ return;
109
+ }
110
+ const container = options.getContainer();
111
+ const copiedContainer = (0, utils_1.createEtoContainer)({}, container);
112
+ try {
113
+ const { EtoAppLoader } = await import("@etohq/framework");
114
+ const etoAppLoader = new EtoAppLoader({
115
+ container: copiedContainer,
116
+ });
117
+ await etoAppLoader.runModulesLoader();
118
+ }
119
+ catch (error) {
120
+ console.error("Error runner modules loaders", error?.message);
121
+ throw error;
122
+ }
123
+ };
124
+ const afterEach_ = async () => {
125
+ try {
126
+ await dbUtils.teardown({ schema });
127
+ }
128
+ catch (error) {
129
+ console.error("Error tearing down database:", error?.message);
130
+ throw error;
131
+ }
132
+ };
133
+ return describe("", () => {
134
+ beforeAll(beforeAll_);
135
+ beforeEach(beforeEach_);
136
+ afterEach(afterEach_);
137
+ afterAll(async () => {
138
+ await dbUtils.shutdown(dbName);
139
+ await shutdown();
140
+ });
141
+ testSuite(options);
142
+ });
143
+ }
144
+ //# sourceMappingURL=eto-test-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eto-test-runner.js","sourceRoot":"","sources":["../src/eto-test-runner.ts"],"names":[],"mappings":";;AAmCA,4DA2LC;AA5ND,kDAG+B;AAC/B,mCAAgC;AAChC,yCAA8D;AAC9D,mEAQgC;AAmBhC,SAAgB,wBAAwB,CAAC,EACvC,UAAU,EACV,MAAM,EACN,aAAa,EACb,MAAM,GAAG,QAAQ,EACjB,GAAG,GAAG,EAAE,EACR,KAAK,GAAG,KAAK,EACb,KAAK,GAAG,KAAK,EACb,SAAS,GAUV;IACC,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,GAAG,CAAC,CAAA;IAC5D,UAAU,GAAG,UAAU,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IAClE,MAAM,KAAK,OAAO,UAAU,CAAC,WAAW,EAAE,gBAAgB,QAAQ,EAAE,CAAA;IAEpE,IAAI,QAAQ,GAAG;QACb,MAAM;QACN,SAAS,EAAE,IAAA,yBAAc,EAAC,MAAM,CAAC;QACjC,MAAM;QACN,KAAK;KACN,CAAA;IAED,MAAM,GAAG,GAAG,aAAa,IAAI,OAAO,CAAC,GAAG,EAAE,CAAA;IAE1C,IAAI,QAAQ,GAAG,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,CAAA;IACjC,MAAM,OAAO,GAAG,IAAA,4BAAiB,GAAE,CAAA;IACnC,IAAI,eAA8B,CAAA;IAClC,IAAI,QAAa,CAAA;IACjB,IAAI,iBAAsB,CAAA;IAE1B,IAAI,OAAO,GAAG;QACZ,GAAG,EAAE,IAAI,KAAK,CACZ,EAAE,EACF;YACE,GAAG,EA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A8B,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;YAC7D,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC,CAAA;IAED,OAAO,QAAQ,CAAC,EAAE,EAAE,GAAG,EAAE;QACvB,SAAS,CAAC,UAAU,CAAC,CAAA;QACrB,UAAU,CAAC,WAAW,CAAC,CAAA;QACvB,SAAS,CAAC,UAAU,CAAC,CAAA;QACrB,QAAQ,CAAC,KAAK,IAAI,EAAE;YAClB,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;YAC9B,MAAM,QAAQ,EAAE,CAAA;QAClB,CAAC,CAAC,CAAA;QAEF,SAAS,CAAC,OAAQ,CAAC,CAAA;IACrB,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { IEventBusModuleService } from "@etohq/framework/types";
2
+ export declare const waitSubscribersExecution: (eventName: string, eventBus: IEventBusModuleService) => Promise<any[]>;
3
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AAI/D,eAAO,MAAM,wBAAwB,cACxB,MAAM,YACP,sBAAsB,mBAwCjC,CAAA"}
package/dist/events.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitSubscribersExecution = void 0;
4
+ // Allows you to wait for all subscribers to execute for a given event. Only works with the local event bus.
5
+ const waitSubscribersExecution = (eventName, eventBus) => {
6
+ const eventEmitter = eventBus.eventEmitter_;
7
+ const subscriberPromises = [];
8
+ const originalListeners = eventEmitter.listeners(eventName);
9
+ // If there are no existing listeners, resolve once the event happens. Otherwise, wrap the existing subscribers in a promise and resolve once they are done.
10
+ if (!eventEmitter.listeners(eventName).length) {
11
+ let ok;
12
+ const promise = new Promise((resolve) => {
13
+ ok = resolve;
14
+ });
15
+ subscriberPromises.push(promise);
16
+ eventEmitter.on(eventName, ok);
17
+ }
18
+ else {
19
+ eventEmitter.listeners(eventName).forEach((listener) => {
20
+ eventEmitter.removeListener(eventName, listener);
21
+ let ok, nok;
22
+ const promise = new Promise((resolve, reject) => {
23
+ ok = resolve;
24
+ nok = reject;
25
+ });
26
+ subscriberPromises.push(promise);
27
+ const newListener = async (...args2) => {
28
+ return await listener.apply(eventBus, args2).then(ok).catch(nok);
29
+ };
30
+ eventEmitter.on(eventName, newListener);
31
+ });
32
+ }
33
+ return Promise.all(subscriberPromises).finally(() => {
34
+ eventEmitter.removeAllListeners(eventName);
35
+ originalListeners.forEach((listener) => {
36
+ eventEmitter.on(eventName, listener);
37
+ });
38
+ });
39
+ };
40
+ exports.waitSubscribersExecution = waitSubscribersExecution;
41
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;AAGA,4GAA4G;AACrG,MAAM,wBAAwB,GAAG,CACtC,SAAiB,EACjB,QAAgC,EAChC,EAAE;IACF,MAAM,YAAY,GAAkB,QAAgB,CAAC,aAAa,CAAA;IAClE,MAAM,kBAAkB,GAAmB,EAAE,CAAA;IAC7C,MAAM,iBAAiB,GAAG,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;IAE3D,4JAA4J;IAC5J,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,CAAC;QAC9C,IAAI,EAAE,CAAA;QACN,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACtC,EAAE,GAAG,OAAO,CAAA;QACd,CAAC,CAAC,CAAA;QAEF,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAChC,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;IAChC,CAAC;SAAM,CAAC;QACN,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,QAAa,EAAE,EAAE;YAC1D,YAAY,CAAC,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;YAEhD,IAAI,EAAE,EAAE,GAAG,CAAA;YACX,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC9C,EAAE,GAAG,OAAO,CAAA;gBACZ,GAAG,GAAG,MAAM,CAAA;YACd,CAAC,CAAC,CAAA;YACF,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YAEhC,MAAM,WAAW,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE;gBACrC,OAAO,MAAM,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAClE,CAAC,CAAA;YAED,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;QACzC,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;QAClD,YAAY,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAA;QAC1C,iBAAiB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YACrC,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,QAAkC,CAAC,CAAA;QAChE,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AA1CY,QAAA,wBAAwB,4BA0CpC"}
@@ -0,0 +1,7 @@
1
+ declare class IdMap {
2
+ ids: {};
3
+ getId(key: any, prefix?: string, length?: number): any;
4
+ }
5
+ declare const instance: IdMap;
6
+ export default instance;
7
+ //# sourceMappingURL=id-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-map.d.ts","sourceRoot":"","sources":["../src/id-map.ts"],"names":[],"mappings":"AAEA,cAAM,KAAK;IACT,GAAG,KAAK;IAER,KAAK,CAAC,GAAG,KAAA,EAAE,MAAM,SAAK,EAAE,MAAM,SAAK;CAUpC;AAED,QAAA,MAAM,QAAQ,OAAc,CAAA;AAC5B,eAAe,QAAQ,CAAA"}
package/dist/id-map.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const randomatic_1 = __importDefault(require("randomatic"));
7
+ class IdMap {
8
+ constructor() {
9
+ this.ids = {};
10
+ }
11
+ getId(key, prefix = "", length = 10) {
12
+ if (this.ids[key]) {
13
+ return this.ids[key];
14
+ }
15
+ const id = `${prefix && prefix + "_"}${(0, randomatic_1.default)("Aa0", length)}`;
16
+ this.ids[key] = id;
17
+ return id;
18
+ }
19
+ }
20
+ const instance = new IdMap();
21
+ exports.default = instance;
22
+ //# sourceMappingURL=id-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-map.js","sourceRoot":"","sources":["../src/id-map.ts"],"names":[],"mappings":";;;;;AAAA,4DAAkC;AAElC,MAAM,KAAK;IAAX;QACE,QAAG,GAAG,EAAE,CAAA;IAYV,CAAC;IAVC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE;QACjC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACtB,CAAC;QAED,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,MAAM,GAAG,GAAG,GAAG,IAAA,oBAAS,EAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAA;QACjE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;QAElB,OAAO,EAAE,CAAA;IACX,CAAC;CACF;AAED,MAAM,QAAQ,GAAG,IAAI,KAAK,EAAE,CAAA;AAC5B,kBAAe,QAAQ,CAAA"}
@@ -0,0 +1,10 @@
1
+ export * as TestDatabaseUtils from "./database";
2
+ export * as TestEventUtils from "./events";
3
+ export { default as IdMap } from "./id-map";
4
+ export * from "./init-modules";
5
+ export * as JestUtils from "./jest";
6
+ export * from "./eto-test-runner";
7
+ export * from "./eto-test-runner-utils";
8
+ export { default as MockEventBusService } from "./mock-event-bus-service";
9
+ export * from "./module-test-runner";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,iBAAiB,MAAM,YAAY,CAAA;AAC/C,OAAO,KAAK,cAAc,MAAM,UAAU,CAAA;AAC1C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,UAAU,CAAA;AAC3C,cAAc,gBAAgB,CAAA;AAC9B,OAAO,KAAK,SAAS,MAAM,QAAQ,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,yBAAyB,CAAA;AACvC,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AACzE,cAAc,sBAAsB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ var __importDefault = (this && this.__importDefault) || function (mod) {
29
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.MockEventBusService = exports.JestUtils = exports.IdMap = exports.TestEventUtils = exports.TestDatabaseUtils = void 0;
33
+ exports.TestDatabaseUtils = __importStar(require("./database"));
34
+ exports.TestEventUtils = __importStar(require("./events"));
35
+ var id_map_1 = require("./id-map");
36
+ Object.defineProperty(exports, "IdMap", { enumerable: true, get: function () { return __importDefault(id_map_1).default; } });
37
+ __exportStar(require("./init-modules"), exports);
38
+ exports.JestUtils = __importStar(require("./jest"));
39
+ __exportStar(require("./eto-test-runner"), exports);
40
+ __exportStar(require("./eto-test-runner-utils"), exports);
41
+ var mock_event_bus_service_1 = require("./mock-event-bus-service");
42
+ Object.defineProperty(exports, "MockEventBusService", { enumerable: true, get: function () { return __importDefault(mock_event_bus_service_1).default; } });
43
+ __exportStar(require("./module-test-runner"), exports);
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA+C;AAC/C,2DAA0C;AAC1C,mCAA2C;AAAlC,gHAAA,OAAO,OAAS;AACzB,iDAA8B;AAC9B,oDAAmC;AACnC,oDAAiC;AACjC,0DAAuC;AACvC,mEAAyE;AAAhE,8IAAA,OAAO,OAAuB;AACvC,uDAAoC"}
@@ -0,0 +1,18 @@
1
+ import { ExternalModuleDeclaration, InternalModuleDeclaration, ModuleJoinerConfig } from "@etohq/framework/types";
2
+ export interface InitModulesOptions {
3
+ injectedDependencies?: Record<string, unknown>;
4
+ databaseConfig: {
5
+ clientUrl: string;
6
+ schema?: string;
7
+ };
8
+ modulesConfig: {
9
+ [key: string]: string | boolean | Partial<InternalModuleDeclaration | ExternalModuleDeclaration>;
10
+ };
11
+ joinerConfig?: ModuleJoinerConfig[];
12
+ preventConnectionDestroyWarning?: boolean;
13
+ }
14
+ export declare function initModules({ injectedDependencies, databaseConfig, modulesConfig, joinerConfig, preventConnectionDestroyWarning, }: InitModulesOptions): Promise<{
15
+ etoApp: any;
16
+ shutdown: () => Promise<void>;
17
+ }>;
18
+ //# sourceMappingURL=init-modules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-modules.d.ts","sourceRoot":"","sources":["../src/init-modules.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EACnB,MAAM,wBAAwB,CAAA;AAO/B,MAAM,WAAW,kBAAkB;IACjC,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9C,cAAc,EAAE;QACd,SAAS,EAAE,MAAM,CAAA;QACjB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,aAAa,EAAE;QACb,CAAC,GAAG,EAAE,MAAM,GACR,MAAM,GACN,OAAO,GACP,OAAO,CAAC,yBAAyB,GAAG,yBAAyB,CAAC,CAAA;KACnE,CAAA;IACD,YAAY,CAAC,EAAE,kBAAkB,EAAE,CAAA;IACnC,+BAA+B,CAAC,EAAE,OAAO,CAAA;CAC1C;AAED,wBAAsB,WAAW,CAAC,EAChC,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,YAAY,EACZ,+BAAuC,GACxC,EAAE,kBAAkB;;;GAkDpB"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initModules = initModules;
4
+ const utils_1 = require("@etohq/framework/utils");
5
+ async function initModules({ injectedDependencies, databaseConfig, modulesConfig, joinerConfig, preventConnectionDestroyWarning = false, }) {
6
+ const moduleSdkImports = require("@etohq/framework/modules-sdk");
7
+ injectedDependencies ??= {};
8
+ let sharedPgConnection = injectedDependencies?.[utils_1.ContainerRegistrationKeys.PG_CONNECTION];
9
+ let shouldDestroyConnectionAutomatically = !sharedPgConnection;
10
+ if (!sharedPgConnection) {
11
+ sharedPgConnection = (0, utils_1.createPgConnection)({
12
+ clientUrl: databaseConfig.clientUrl,
13
+ schema: databaseConfig.schema,
14
+ });
15
+ injectedDependencies[utils_1.ContainerRegistrationKeys.PG_CONNECTION] =
16
+ sharedPgConnection;
17
+ }
18
+ const etoApp = await moduleSdkImports.EtoApp({
19
+ modulesConfig,
20
+ servicesConfig: joinerConfig,
21
+ injectedDependencies,
22
+ });
23
+ await etoApp.onApplicationStart();
24
+ async function shutdown() {
25
+ if (shouldDestroyConnectionAutomatically) {
26
+ await etoApp.onApplicationPrepareShutdown();
27
+ await (0, utils_1.promiseAll)([
28
+ sharedPgConnection.context?.destroy(),
29
+ sharedPgConnection.destroy(),
30
+ etoApp.onApplicationShutdown(),
31
+ ]);
32
+ }
33
+ else {
34
+ if (!preventConnectionDestroyWarning) {
35
+ console.info(`You are using a custom shared connection. The connection won't be destroyed automatically.`);
36
+ }
37
+ }
38
+ moduleSdkImports.EtoModule.clearInstances();
39
+ }
40
+ return {
41
+ etoApp,
42
+ shutdown,
43
+ };
44
+ }
45
+ //# sourceMappingURL=init-modules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-modules.js","sourceRoot":"","sources":["../src/init-modules.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AS,CAAC,cAAc,EAAE,CAAA;IAC7C,CAAC;IAED,OAAO;QACL,MAAM;QACN,QAAQ;KACT,CAAA;AACH,CAAC"}
package/dist/jest.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function afterAllHookDropDatabase(): void;
2
+ //# sourceMappingURL=jest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest.d.ts","sourceRoot":"","sources":["../src/jest.ts"],"names":[],"mappings":"AAEA,wBAAgB,wBAAwB,SAqBvC"}
package/dist/jest.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.afterAllHookDropDatabase = afterAllHookDropDatabase;
4
+ const pg_god_1 = require("pg-god");
5
+ function afterAllHookDropDatabase() {
6
+ const DB_HOST = process.env.DB_HOST ?? "localhost";
7
+ const DB_USERNAME = process.env.DB_USERNAME ?? "postgres";
8
+ const DB_PASSWORD = process.env.DB_PASSWORD ?? "";
9
+ const DB_NAME = process.env.DB_TEMP_NAME || "";
10
+ const pgGodCredentials = {
11
+ user: DB_USERNAME,
12
+ password: DB_PASSWORD,
13
+ host: DB_HOST,
14
+ };
15
+ afterAll(async () => {
16
+ try {
17
+ await (0, pg_god_1.dropDatabase)({ databaseName: DB_NAME }, pgGodCredentials);
18
+ }
19
+ catch (e) {
20
+ console.error(`This might fail if it is run during the unit tests since there is no database to drop. Otherwise, please check what is the issue. ${e.message}`);
21
+ }
22
+ });
23
+ }
24
+ //# sourceMappingURL=jest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest.js","sourceRoot":"","sources":["../src/jest.ts"],"names":[],"mappings":";;AAEA,4DAqBC;AAvBD,mCAAqC;AAErC,SAAgB,wBAAwB;IACtC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,WAAW,CAAA;IAClD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,UAAU,CAAA;IACzD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAA;IACjD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAA;IAE9C,MAAM,gBAAgB,GAAG;QACvB,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,WAAW;QACrB,IAAI,EAAE,OAAO;KACd,CAAA;IAED,QAAQ,CAAC,KAAK,IAAI,EAAE;QAClB,IAAI,CAAC;YACH,MAAM,IAAA,qBAAY,EAAC,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,gBAAgB,CAAC,CAAA;QACjE,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CACX,qIAAqI,CAAC,CAAC,OAAO,EAAE,CACjJ,CAAA;QACH,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { EventBusTypes, IEventBusModuleService, Message, Subscriber } from "@etohq/framework/types";
2
+ export default class EventBusService implements IEventBusModuleService {
3
+ emit<T>(data: Message<T> | Message<T>[], options: Record<string, unknown>): Promise<void>;
4
+ subscribe(event: string | symbol, subscriber: Subscriber): this;
5
+ unsubscribe(event: string | symbol, subscriber: Subscriber, context?: EventBusTypes.SubscriberContext): this;
6
+ releaseGroupedEvents(eventGroupId: string): Promise<void>;
7
+ clearGroupedEvents(eventGroupId: string): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=mock-event-bus-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-event-bus-service.d.ts","sourceRoot":"","sources":["../src/mock-event-bus-service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,OAAO,EACP,UAAU,EACX,MAAM,wBAAwB,CAAA;AAE/B,MAAM,CAAC,OAAO,OAAO,eAAgB,YAAW,sBAAsB;IAC9D,IAAI,CAAC,CAAC,EACV,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,EAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC;IAEhB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI;IAI/D,WAAW,CACT,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,UAAU,EAAE,UAAU,EACtB,OAAO,CAAC,EAAE,aAAa,CAAC,iBAAiB,GACxC,IAAI;IAIP,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGxD"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class EventBusService {
4
+ async emit(data, options) { }
5
+ subscribe(event, subscriber) {
6
+ return this;
7
+ }
8
+ unsubscribe(event, subscriber, context) {
9
+ return this;
10
+ }
11
+ releaseGroupedEvents(eventGroupId) {
12
+ return Promise.resolve();
13
+ }
14
+ clearGroupedEvents(eventGroupId) {
15
+ return Promise.resolve();
16
+ }
17
+ }
18
+ exports.default = EventBusService;
19
+ //# sourceMappingURL=mock-event-bus-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-event-bus-service.js","sourceRoot":"","sources":["../src/mock-event-bus-service.ts"],"names":[],"mappings":";;AAOA,MAAqB,eAAe;IAClC,KAAK,CAAC,IAAI,CACR,IAA+B,EAC/B,OAAgC,IAChB,CAAC;IAEnB,SAAS,CAAC,KAAsB,EAAE,UAAsB;QACtD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,WAAW,CACT,KAAsB,EACtB,UAAsB,EACtB,OAAyC;QAEzC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,oBAAoB,CAAC,YAAoB;QACvC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IAC1B,CAAC;IAED,kBAAkB,CAAC,YAAoB;QACrC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IAC1B,CAAC;CACF;AAzBD,kCAyBC"}
@@ -0,0 +1,24 @@
1
+ import { TestDatabase } from "./database";
2
+ export interface SuiteOptions<TService = unknown> {
3
+ MikroOrmWrapper: TestDatabase;
4
+ etoApp: any;
5
+ service: TService;
6
+ dbConfig: {
7
+ schema: string;
8
+ clientUrl: string;
9
+ };
10
+ }
11
+ export declare function moduleIntegrationTestRunner<TService = any>({ moduleName, moduleModels, moduleOptions, moduleDependencies, joinerConfig, schema, debug, testSuite, resolve, injectedDependencies, }: {
12
+ moduleName: string;
13
+ moduleModels?: any[];
14
+ moduleOptions?: Record<string, any>;
15
+ moduleDependencies?: string[];
16
+ joinerConfig?: any[];
17
+ schema?: string;
18
+ dbName?: string;
19
+ injectedDependencies?: Record<string, any>;
20
+ resolve?: string;
21
+ debug?: boolean;
22
+ testSuite: (options: SuiteOptions<TService>) => void;
23
+ }): void;
24
+ //# sourceMappingURL=module-test-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-test-runner.d.ts","sourceRoot":"","sources":["../src/module-test-runner.ts"],"names":[],"mappings":"AAWA,OAAO,EAAsC,YAAY,EAAE,MAAM,YAAY,CAAA;AAI7E,MAAM,WAAW,YAAY,CAAC,QAAQ,GAAG,OAAO;IAC9C,eAAe,EAAE,YAAY,CAAA;IAC7B,MAAM,EAAE,GAAG,CAAA;IACX,OAAO,EAAE,QAAQ,CAAA;IACjB,QAAQ,EAAE;QACR,MAAM,EAAE,MAAM,CAAA;QACd,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF;AA0CD,wBAAgB,2BAA2B,CAAC,QAAQ,GAAG,GAAG,EAAE,EAC1D,UAAU,EACV,YAAY,EACZ,aAAkB,EAClB,kBAAkB,EAClB,YAAiB,EACjB,MAAiB,EACjB,KAAa,EACb,SAAS,EACT,OAAO,EACP,oBAAyB,GAC1B,EAAE;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,GAAG,EAAE,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACnC,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC7B,YAAY,CAAC,EAAE,GAAG,EAAE,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,SAAS,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAA;CACrD,QA4GA"}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.moduleIntegrationTestRunner = moduleIntegrationTestRunner;
30
+ const utils_1 = require("@etohq/framework/utils");
31
+ const fs = __importStar(require("fs"));
32
+ const database_1 = require("./database");
33
+ const init_modules_1 = require("./init-modules");
34
+ const mock_event_bus_service_1 = __importDefault(require("./mock-event-bus-service"));
35
+ function createMikroOrmWrapper(options) {
36
+ let moduleModels = options.moduleModels ?? [];
37
+ if (!options.moduleModels) {
38
+ const basePath = (0, utils_1.normalizeImportPathWithSource)(options.resolve ?? process.cwd());
39
+ const modelsPath = fs.existsSync(`${basePath}/dist/models`)
40
+ ? "/dist/models"
41
+ : fs.existsSync(`${basePath}/models`)
42
+ ? "/models"
43
+ : "";
44
+ if (modelsPath) {
45
+ moduleModels = (0, utils_1.loadModels)(`${basePath}${modelsPath}`);
46
+ }
47
+ else {
48
+ moduleModels = [];
49
+ }
50
+ }
51
+ moduleModels = (0, utils_1.toMikroOrmEntities)(moduleModels);
52
+ const MikroOrmWrapper = (0, database_1.getMikroOrmWrapper)({
53
+ mikroOrmEntities: moduleModels,
54
+ clientUrl: options.dbConfig.clientUrl,
55
+ schema: options.dbConfig.schema,
56
+ });
57
+ return { MikroOrmWrapper, models: moduleModels };
58
+ }
59
+ function moduleIntegrationTestRunner({ moduleName, moduleModels, moduleOptions = {}, moduleDependencies, joinerConfig = [], schema = "public", debug = false, testSuite, resolve, injectedDependencies = {}, }) {
60
+ const moduleSdkImports = require("@etohq/framework/modules-sdk");
61
+ process.env.LOG_LEVEL = "error";
62
+ const tempName = parseInt(process.env.JEST_WORKER_ID || "1");
63
+ const dbName = `eto-${moduleName.toLowerCase()}-integration-${tempName}`;
64
+ const dbConfig = {
65
+ clientUrl: (0, database_1.getDatabaseURL)(dbName),
66
+ schema,
67
+ debug,
68
+ };
69
+ // Use a unique connection for all the entire suite
70
+ const connection = utils_1.ModulesSdkUtils.createPgConnection(dbConfig);
71
+ const { MikroOrmWrapper, models } = createMikroOrmWrapper({
72
+ moduleModels,
73
+ resolve,
74
+ dbConfig,
75
+ });
76
+ moduleModels = models;
77
+ const modulesConfig_ = {
78
+ [moduleName]: {
79
+ definition: moduleSdkImports.ModulesDefinition[moduleName],
80
+ resolve,
81
+ dependencies: moduleDependencies,
82
+ options: {
83
+ database: dbConfig,
84
+ ...moduleOptions,
85
+ [utils_1.isSharedConnectionSymbol]: true,
86
+ },
87
+ },
88
+ };
89
+ const moduleOptions_ = {
90
+ injectedDependencies: {
91
+ [utils_1.ContainerRegistrationKeys.PG_CONNECTION]: connection,
92
+ [utils_1.Modules.EVENT_BUS]: new mock_event_bus_service_1.default(),
93
+ [utils_1.ContainerRegistrationKeys.LOGGER]: console,
94
+ ...injectedDependencies,
95
+ },
96
+ modulesConfig: modulesConfig_,
97
+ databaseConfig: dbConfig,
98
+ joinerConfig,
99
+ preventConnectionDestroyWarning: true,
100
+ };
101
+ let shutdown;
102
+ let moduleService;
103
+ let etoApp = {};
104
+ const options = {
105
+ MikroOrmWrapper,
106
+ etoApp: new Proxy({}, {
107
+ get: (target, prop) => {
108
+ return etoApp[prop];
109
+ },
110
+ }),
111
+ service: new Proxy({}, {
112
+ get: (target, prop) => {
113
+ return moduleService[prop];
114
+ },
115
+ }),
116
+ dbConfig: {
117
+ schema,
118
+ clientUrl: dbConfig.clientUrl,
119
+ },
120
+ };
121
+ const beforeEach_ = async () => {
122
+ if (moduleModels.length) {
123
+ await MikroOrmWrapper.setupDatabase();
124
+ }
125
+ const output = await (0, init_modules_1.initModules)(moduleOptions_);
126
+ shutdown = output.shutdown;
127
+ etoApp = output.etoApp;
128
+ moduleService = output.etoApp.modules[moduleName];
129
+ };
130
+ const afterEach_ = async () => {
131
+ if (moduleModels.length) {
132
+ await MikroOrmWrapper.clearDatabase();
133
+ }
134
+ await shutdown();
135
+ moduleService = {};
136
+ etoApp = {};
137
+ };
138
+ return describe("", () => {
139
+ beforeEach(beforeEach_);
140
+ afterEach(afterEach_);
141
+ afterAll(async () => {
142
+ await connection.context?.destroy();
143
+ await connection.destroy();
144
+ });
145
+ testSuite(options);
146
+ });
147
+ }
148
+ //# sourceMappingURL=module-test-runner.js.map