@medusajs/test-utils 3.0.0-snapshot-20250410112222 → 3.0.0-snapshot-20251104004624
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.
- package/dist/database.d.ts +1 -1
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +121 -39
- package/dist/database.js.map +1 -1
- package/dist/events.d.ts +15 -3
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +120 -21
- package/dist/events.js.map +1 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/dist/init-modules.d.ts +2 -1
- package/dist/init-modules.d.ts.map +1 -1
- package/dist/init-modules.js +10 -8
- package/dist/init-modules.js.map +1 -1
- package/dist/medusa-test-runner-utils/bootstrap-app.d.ts.map +1 -1
- package/dist/medusa-test-runner-utils/bootstrap-app.js +94 -40
- package/dist/medusa-test-runner-utils/bootstrap-app.js.map +1 -1
- package/dist/medusa-test-runner-utils/config.d.ts.map +1 -1
- package/dist/medusa-test-runner-utils/config.js +6 -0
- package/dist/medusa-test-runner-utils/config.js.map +1 -1
- package/dist/medusa-test-runner-utils/use-db.d.ts +2 -2
- package/dist/medusa-test-runner-utils/use-db.d.ts.map +1 -1
- package/dist/medusa-test-runner-utils/use-db.js +9 -8
- package/dist/medusa-test-runner-utils/use-db.js.map +1 -1
- package/dist/medusa-test-runner-utils/utils.d.ts +8 -0
- package/dist/medusa-test-runner-utils/utils.d.ts.map +1 -1
- package/dist/medusa-test-runner-utils/utils.js +15 -0
- package/dist/medusa-test-runner-utils/utils.js.map +1 -1
- package/dist/medusa-test-runner-utils/wait-workflow-executions.d.ts +9 -0
- package/dist/medusa-test-runner-utils/wait-workflow-executions.d.ts.map +1 -0
- package/dist/medusa-test-runner-utils/wait-workflow-executions.js +34 -0
- package/dist/medusa-test-runner-utils/wait-workflow-executions.js.map +1 -0
- package/dist/medusa-test-runner.d.ts +22 -1
- package/dist/medusa-test-runner.d.ts.map +1 -1
- package/dist/medusa-test-runner.js +220 -95
- package/dist/medusa-test-runner.js.map +1 -1
- package/dist/module-test-runner.d.ts +21 -1
- package/dist/module-test-runner.d.ts.map +1 -1
- package/dist/module-test-runner.js +231 -85
- package/dist/module-test-runner.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -22
package/dist/database.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MikroORM, Options, SqlEntityManager } from "@mikro-orm/postgresql";
|
|
1
|
+
import { MikroORM, Options, SqlEntityManager } from "@medusajs/framework/mikro-orm/postgresql";
|
|
2
2
|
export declare function getDatabaseURL(dbName?: string): string;
|
|
3
3
|
export declare function getMikroOrmConfig({ mikroOrmEntities, pathToMigrations, clientUrl, schema, }: {
|
|
4
4
|
mikroOrmEntities: any[];
|
package/dist/database.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,QAAQ,EACR,OAAO,EACP,gBAAgB,EACjB,MAAM,0CAA0C,CAAA;AAgBjD,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAUtD;AAED,wBAAgB,iBAAiB,CAAC,EAChC,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,MAAM,GACP,EAAE;IACD,gBAAgB,EAAE,GAAG,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,OAAO,CAiBV;AAED,MAAM,WAAW,YAAY;IAC3B,gBAAgB,EAAE,GAAG,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,GAAG,EAAE,QAAQ,GAAG,IAAI,CAAA;IACpB,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAAA;IAEhC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B,UAAU,IAAI,gBAAgB,CAAA;IAC9B,WAAW,IAAI,gBAAgB,CAAA;IAC/B,MAAM,IAAI,QAAQ,CAAA;CACnB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,MAAM,GACP,EAAE;IACD,gBAAgB,EAAE,GAAG,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,YAAY,CAiHf;AAED,eAAO,MAAM,iBAAiB,QAAO,GA+FnC,CAAA"}
|
package/dist/database.js
CHANGED
|
@@ -4,22 +4,28 @@ exports.dbTestUtilFactory = void 0;
|
|
|
4
4
|
exports.getDatabaseURL = getDatabaseURL;
|
|
5
5
|
exports.getMikroOrmConfig = getMikroOrmConfig;
|
|
6
6
|
exports.getMikroOrmWrapper = getMikroOrmWrapper;
|
|
7
|
-
const
|
|
7
|
+
const logger_1 = require("@medusajs/framework/logger");
|
|
8
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
9
|
+
const postgresql_1 = require("@medusajs/framework/mikro-orm/postgresql");
|
|
8
10
|
const pg_god_1 = require("pg-god");
|
|
11
|
+
const medusa_test_runner_utils_1 = require("./medusa-test-runner-utils");
|
|
9
12
|
const DB_HOST = process.env.DB_HOST ?? "localhost";
|
|
10
13
|
const DB_USERNAME = process.env.DB_USERNAME ?? "";
|
|
11
14
|
const DB_PASSWORD = process.env.DB_PASSWORD ?? "";
|
|
15
|
+
const DB_PORT = process.env.DB_PORT ?? "5432";
|
|
12
16
|
const pgGodCredentials = {
|
|
13
17
|
user: DB_USERNAME,
|
|
14
18
|
password: DB_PASSWORD,
|
|
15
19
|
host: DB_HOST,
|
|
20
|
+
port: parseInt(DB_PORT),
|
|
16
21
|
};
|
|
17
22
|
function getDatabaseURL(dbName) {
|
|
18
23
|
const DB_HOST = process.env.DB_HOST ?? "localhost";
|
|
19
24
|
const DB_USERNAME = process.env.DB_USERNAME ?? "postgres";
|
|
20
25
|
const DB_PASSWORD = process.env.DB_PASSWORD ?? "";
|
|
26
|
+
const DB_PORT = process.env.DB_PORT ?? "5432";
|
|
21
27
|
const DB_NAME = dbName ?? process.env.DB_TEMP_NAME;
|
|
22
|
-
return `postgres://${DB_USERNAME}${DB_PASSWORD ? `:${DB_PASSWORD}` : ""}@${DB_HOST}/${DB_NAME}`;
|
|
28
|
+
return `postgres://${DB_USERNAME}${DB_PASSWORD ? `:${DB_PASSWORD}` : ""}@${DB_HOST}:${DB_PORT}/${DB_NAME}`;
|
|
23
29
|
}
|
|
24
30
|
function getMikroOrmConfig({ mikroOrmEntities, pathToMigrations, clientUrl, schema, }) {
|
|
25
31
|
const DB_URL = clientUrl ?? getDatabaseURL();
|
|
@@ -35,6 +41,7 @@ function getMikroOrmConfig({ mikroOrmEntities, pathToMigrations, clientUrl, sche
|
|
|
35
41
|
pathTs: pathToMigrations,
|
|
36
42
|
silent: true,
|
|
37
43
|
},
|
|
44
|
+
extensions: [utils_1.CustomDBMigrator],
|
|
38
45
|
});
|
|
39
46
|
}
|
|
40
47
|
function getMikroOrmWrapper({ mikroOrmEntities, pathToMigrations, clientUrl, schema, }) {
|
|
@@ -70,68 +77,143 @@ function getMikroOrmWrapper({ mikroOrmEntities, pathToMigrations, clientUrl, sch
|
|
|
70
77
|
clientUrl: this.clientUrl,
|
|
71
78
|
schema: this.schema,
|
|
72
79
|
});
|
|
73
|
-
// Initializing the ORM
|
|
74
|
-
this.orm = await postgresql_1.MikroORM.init(OrmConfig);
|
|
75
|
-
this.manager = this.orm.em;
|
|
76
80
|
try {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
await this.orm
|
|
81
|
+
this.orm = await postgresql_1.MikroORM.init(OrmConfig);
|
|
82
|
+
this.manager = this.orm.em;
|
|
83
|
+
try {
|
|
84
|
+
await this.orm.getSchemaGenerator().ensureDatabase();
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
logger_1.logger.error("Error ensuring database:", err);
|
|
88
|
+
throw err;
|
|
89
|
+
}
|
|
90
|
+
await this.manager?.execute(`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`);
|
|
91
|
+
const pendingMigrations = await this.orm
|
|
88
92
|
.getMigrator()
|
|
89
|
-
.
|
|
93
|
+
.getPendingMigrations();
|
|
94
|
+
if (pendingMigrations && pendingMigrations.length > 0) {
|
|
95
|
+
await this.orm
|
|
96
|
+
.getMigrator()
|
|
97
|
+
.up({ migrations: pendingMigrations.map((m) => m.name) });
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
await this.orm.schema.refreshDatabase();
|
|
101
|
+
}
|
|
90
102
|
}
|
|
91
|
-
|
|
92
|
-
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (this.orm) {
|
|
105
|
+
try {
|
|
106
|
+
await this.orm.close();
|
|
107
|
+
}
|
|
108
|
+
catch (closeError) {
|
|
109
|
+
logger_1.logger.error("Error closing ORM:", closeError);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
this.orm = null;
|
|
113
|
+
this.manager = null;
|
|
114
|
+
throw error;
|
|
93
115
|
}
|
|
94
116
|
},
|
|
95
117
|
async clearDatabase() {
|
|
96
118
|
if (this.orm === null) {
|
|
97
119
|
throw new Error("ORM not configured");
|
|
98
120
|
}
|
|
99
|
-
await this.manager?.execute(`DROP SCHEMA IF EXISTS "${this.schema ?? "public"}" CASCADE;`);
|
|
100
|
-
await this.manager?.execute(`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`);
|
|
101
121
|
try {
|
|
102
|
-
await this.
|
|
122
|
+
await this.manager?.execute(`DROP SCHEMA IF EXISTS "${this.schema ?? "public"}" CASCADE;`);
|
|
123
|
+
await this.manager?.execute(`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`);
|
|
124
|
+
const closePromise = this.orm.close();
|
|
125
|
+
await (0, medusa_test_runner_utils_1.execOrTimeout)(closePromise);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
logger_1.logger.error("Error clearing database:", error);
|
|
129
|
+
try {
|
|
130
|
+
await this.orm?.close();
|
|
131
|
+
}
|
|
132
|
+
catch (closeError) {
|
|
133
|
+
logger_1.logger.error("Error during forced ORM close:", closeError);
|
|
134
|
+
}
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
this.orm = null;
|
|
139
|
+
this.manager = null;
|
|
103
140
|
}
|
|
104
|
-
catch { }
|
|
105
|
-
this.orm = null;
|
|
106
|
-
this.manager = null;
|
|
107
141
|
},
|
|
108
142
|
};
|
|
109
143
|
}
|
|
110
144
|
const dbTestUtilFactory = () => ({
|
|
111
145
|
pgConnection_: null,
|
|
112
146
|
create: async function (dbName) {
|
|
113
|
-
|
|
147
|
+
try {
|
|
148
|
+
await (0, pg_god_1.createDatabase)({ databaseName: dbName, errorIfExist: false }, pgGodCredentials);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
logger_1.logger.error("Error creating database:", error);
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
114
154
|
},
|
|
115
155
|
teardown: async function ({ schema } = {}) {
|
|
116
156
|
if (!this.pgConnection_) {
|
|
117
157
|
return;
|
|
118
158
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
159
|
+
try {
|
|
160
|
+
const runRawQuery = this.pgConnection_.raw.bind(this.pgConnection_);
|
|
161
|
+
schema ??= "public";
|
|
162
|
+
const { rows: tableNames } = await runRawQuery(`SELECT table_name
|
|
163
|
+
FROM information_schema.tables
|
|
164
|
+
WHERE table_schema = '${schema}';`);
|
|
165
|
+
const skipIndexPartitionPrefix = "cat_";
|
|
166
|
+
const mainPartitionTables = ["index_data", "index_relation"];
|
|
167
|
+
let hasIndexTables = false;
|
|
168
|
+
const tablesToTruncate = [];
|
|
169
|
+
for (const { table_name } of tableNames) {
|
|
170
|
+
if (mainPartitionTables.includes(table_name)) {
|
|
171
|
+
hasIndexTables = true;
|
|
172
|
+
}
|
|
173
|
+
if (table_name.startsWith(skipIndexPartitionPrefix) ||
|
|
174
|
+
mainPartitionTables.includes(table_name)) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
tablesToTruncate.push(`${schema}."${table_name}"`);
|
|
178
|
+
}
|
|
179
|
+
if (tablesToTruncate.length > 0) {
|
|
180
|
+
await runRawQuery(`TRUNCATE ${tablesToTruncate.join(", ")};`);
|
|
181
|
+
}
|
|
182
|
+
if (hasIndexTables) {
|
|
183
|
+
await runRawQuery(`TRUNCATE ${schema}.index_data, ${schema}.index_relation;`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
logger_1.logger.error("Error during database teardown:", error);
|
|
188
|
+
throw error;
|
|
128
189
|
}
|
|
129
|
-
await runRawQuery(`SET session_replication_role = 'origin';`);
|
|
130
190
|
},
|
|
131
191
|
shutdown: async function (dbName) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
192
|
+
try {
|
|
193
|
+
const cleanupPromises = [];
|
|
194
|
+
if (this.pgConnection_?.context) {
|
|
195
|
+
cleanupPromises.push((0, medusa_test_runner_utils_1.execOrTimeout)(this.pgConnection_.context.destroy()));
|
|
196
|
+
}
|
|
197
|
+
if (this.pgConnection_) {
|
|
198
|
+
cleanupPromises.push((0, medusa_test_runner_utils_1.execOrTimeout)(this.pgConnection_.destroy()));
|
|
199
|
+
}
|
|
200
|
+
await Promise.all(cleanupPromises);
|
|
201
|
+
return await (0, pg_god_1.dropDatabase)({ databaseName: dbName, errorIfNonExist: false }, pgGodCredentials);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
logger_1.logger.error("Error during database shutdown:", error);
|
|
205
|
+
try {
|
|
206
|
+
await this.pgConnection_?.context?.destroy();
|
|
207
|
+
await this.pgConnection_?.destroy();
|
|
208
|
+
}
|
|
209
|
+
catch (cleanupError) {
|
|
210
|
+
logger_1.logger.error("Error during forced cleanup:", cleanupError);
|
|
211
|
+
}
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
finally {
|
|
215
|
+
this.pgConnection_ = null;
|
|
216
|
+
}
|
|
135
217
|
},
|
|
136
218
|
});
|
|
137
219
|
exports.dbTestUtilFactory = dbTestUtilFactory;
|
package/dist/database.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":";;;AAwBA,wCAUC;AAED,8CA2BC;AAkBD,gDA2HC;AA5MD,uDAAmD;AACnD,qDAA4D;AAE5D,yEAKiD;AACjD,mCAAqD;AACrD,yEAA0D;AAE1D,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,WAAW,CAAA;AAClD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAA;AACjD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAA;AACjD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAA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AC5D,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;QAC3B,CAAC;IACH,CAAC;CACF,CAAC,CAAA;AA/FW,QAAA,iBAAiB,qBA+F5B"}
|
package/dist/events.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type WaitSubscribersExecutionOptions = {
|
|
2
|
+
/** Timeout in milliseconds for waiting for the event. Defaults to 15000ms. */
|
|
3
3
|
timeout?: number;
|
|
4
|
-
|
|
4
|
+
/** Number of times the event should be triggered before resolving. Defaults to 1. */
|
|
5
|
+
triggerCount?: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Allows you to wait for all subscribers to execute for a given event.
|
|
9
|
+
* It ensures that concurrent waits for the same event are queued and executed sequentially.
|
|
10
|
+
*
|
|
11
|
+
* @param eventName - The name of the event to wait for.
|
|
12
|
+
* @param eventBus - The event bus instance.
|
|
13
|
+
* @param options - Options including timeout and triggerCount.
|
|
14
|
+
*/
|
|
15
|
+
export declare const waitSubscribersExecution: (eventName: string | symbol, eventBus: any, options?: WaitSubscribersExecutionOptions) => Promise<any>;
|
|
16
|
+
export {};
|
|
5
17
|
//# sourceMappingURL=events.d.ts.map
|
package/dist/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAMA,KAAK,+BAA+B,GAAG;IACrC,8EAA8E;IAC9E,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,qFAAqF;IACrF,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAyJD;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GACnC,WAAW,MAAM,GAAG,MAAM,EAC1B,UAAU,GAAG,EACb,UAAU,+BAA+B,KACxC,OAAO,CAAC,GAAG,CAoCb,CAAA"}
|
package/dist/events.js
CHANGED
|
@@ -1,29 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.waitSubscribersExecution = void 0;
|
|
4
|
-
//
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
// Map to hold pending promises for each event.
|
|
5
|
+
const waits = new Map();
|
|
6
|
+
/**
|
|
7
|
+
* Creates a promise that rejects after a specified timeout.
|
|
8
|
+
* @param timeout - The timeout in milliseconds.
|
|
9
|
+
* @param eventName - The name of the event being waited on.
|
|
10
|
+
* @returns A tuple containing the timeout promise and a function to clear the timeout.
|
|
11
|
+
*/
|
|
12
|
+
const createTimeoutPromise = (timeout, eventName) => {
|
|
9
13
|
let timeoutId = null;
|
|
10
|
-
|
|
11
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
14
|
+
const promise = new Promise((_, reject) => {
|
|
12
15
|
timeoutId = setTimeout(() => {
|
|
13
|
-
reject(new Error(`Timeout of ${timeout}ms exceeded while waiting for event "${eventName}"`));
|
|
16
|
+
reject(new Error(`Timeout of ${timeout}ms exceeded while waiting for event "${String(eventName)}"`));
|
|
14
17
|
}, timeout);
|
|
18
|
+
timeoutId.unref();
|
|
15
19
|
});
|
|
16
|
-
|
|
20
|
+
return [promise, () => timeoutId && clearTimeout(timeoutId)];
|
|
21
|
+
};
|
|
22
|
+
// Core logic to wait for subscribers.
|
|
23
|
+
const doWaitSubscribersExecution = (eventName, eventBus, { timeout = 15000, triggerCount = 1 } = {}) => {
|
|
24
|
+
const eventEmitter = eventBus.eventEmitter_;
|
|
25
|
+
const subscriberPromises = [];
|
|
26
|
+
const [timeoutPromise, clearTimeout] = createTimeoutPromise(timeout, eventName);
|
|
27
|
+
let currentCount = 0;
|
|
17
28
|
if (!eventEmitter.listeners(eventName).length) {
|
|
18
29
|
let ok;
|
|
19
30
|
const promise = new Promise((resolve) => {
|
|
20
31
|
ok = resolve;
|
|
21
32
|
});
|
|
22
33
|
subscriberPromises.push(promise);
|
|
23
|
-
|
|
34
|
+
let res = [];
|
|
35
|
+
const newListener = async (...args) => {
|
|
36
|
+
currentCount++;
|
|
37
|
+
res.push(args);
|
|
38
|
+
if (currentCount >= triggerCount) {
|
|
39
|
+
eventEmitter.removeListener(eventName, newListener);
|
|
40
|
+
if (triggerCount === 1) {
|
|
41
|
+
ok(...args);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
ok(res);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
Object.defineProperty(newListener, "__isSubscribersExecutionWrapper", {
|
|
49
|
+
value: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
enumerable: false,
|
|
52
|
+
});
|
|
53
|
+
eventEmitter.on(eventName, newListener);
|
|
24
54
|
}
|
|
25
55
|
else {
|
|
26
56
|
eventEmitter.listeners(eventName).forEach((listener) => {
|
|
57
|
+
if (listener.__isSubscribersExecutionWrapper) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
27
60
|
eventEmitter.removeListener(eventName, listener);
|
|
28
61
|
let ok, nok;
|
|
29
62
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -31,32 +64,98 @@ const waitSubscribersExecution = (eventName, eventBus, { timeout = 5000, } = {})
|
|
|
31
64
|
nok = reject;
|
|
32
65
|
});
|
|
33
66
|
subscriberPromises.push(promise);
|
|
67
|
+
let res = [];
|
|
68
|
+
let cleanupDone = false;
|
|
34
69
|
const newListener = async (...args2) => {
|
|
35
70
|
try {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
71
|
+
const listenerRes = listener.apply(eventBus, args2);
|
|
72
|
+
if (typeof listenerRes?.then === "function") {
|
|
73
|
+
await listenerRes.then((res_) => {
|
|
74
|
+
res.push(res_);
|
|
75
|
+
currentCount++;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
res.push(listenerRes);
|
|
80
|
+
currentCount++;
|
|
81
|
+
}
|
|
82
|
+
if (currentCount >= triggerCount) {
|
|
83
|
+
const res_ = triggerCount === 1 ? res[0] : res;
|
|
84
|
+
ok(res_);
|
|
85
|
+
}
|
|
39
86
|
}
|
|
40
87
|
catch (error) {
|
|
41
88
|
nok(error);
|
|
42
89
|
}
|
|
90
|
+
if (currentCount >= triggerCount && !cleanupDone) {
|
|
91
|
+
// As soon as the subscriber is executed the required number of times, we restore the original listener
|
|
92
|
+
cleanupDone = true;
|
|
93
|
+
eventEmitter.removeListener(eventName, newListener);
|
|
94
|
+
// Unwrap to find the true original listener
|
|
95
|
+
let listenerToAdd = listener;
|
|
96
|
+
while (listenerToAdd?.originalListener) {
|
|
97
|
+
listenerToAdd = listenerToAdd.originalListener;
|
|
98
|
+
}
|
|
99
|
+
if (listenerToAdd) {
|
|
100
|
+
eventEmitter.on(eventName, listenerToAdd);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
43
103
|
};
|
|
104
|
+
Object.defineProperty(newListener, "__isSubscribersExecutionWrapper", {
|
|
105
|
+
value: true,
|
|
106
|
+
configurable: true,
|
|
107
|
+
enumerable: false,
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(newListener, "originalListener", {
|
|
110
|
+
value: listener,
|
|
111
|
+
configurable: true,
|
|
112
|
+
enumerable: false,
|
|
113
|
+
});
|
|
44
114
|
eventEmitter.on(eventName, newListener);
|
|
45
115
|
});
|
|
46
116
|
}
|
|
47
117
|
const subscribersPromise = Promise.all(subscriberPromises).finally(() => {
|
|
48
118
|
// Clear the timeout since events have been fired and handled
|
|
49
|
-
|
|
50
|
-
clearTimeout(timeoutId);
|
|
51
|
-
}
|
|
52
|
-
// Restore original event listeners
|
|
53
|
-
eventEmitter.removeAllListeners(eventName);
|
|
54
|
-
originalListeners.forEach((listener) => {
|
|
55
|
-
eventEmitter.on(eventName, listener);
|
|
56
|
-
});
|
|
119
|
+
clearTimeout();
|
|
57
120
|
});
|
|
58
121
|
// Race between the subscribers and the timeout
|
|
59
122
|
return Promise.race([subscribersPromise, timeoutPromise]);
|
|
60
123
|
};
|
|
124
|
+
/**
|
|
125
|
+
* Allows you to wait for all subscribers to execute for a given event.
|
|
126
|
+
* It ensures that concurrent waits for the same event are queued and executed sequentially.
|
|
127
|
+
*
|
|
128
|
+
* @param eventName - The name of the event to wait for.
|
|
129
|
+
* @param eventBus - The event bus instance.
|
|
130
|
+
* @param options - Options including timeout and triggerCount.
|
|
131
|
+
*/
|
|
132
|
+
const waitSubscribersExecution = (eventName, eventBus, options) => {
|
|
133
|
+
const chain = waits.get(eventName);
|
|
134
|
+
if (!chain) {
|
|
135
|
+
const newPromise = doWaitSubscribersExecution(eventName, eventBus, options).finally(() => {
|
|
136
|
+
// Once this chain is done, remove it from the map
|
|
137
|
+
// if it's still the same promise. This prevents race conditions
|
|
138
|
+
// where a new wait is queued before this one is removed.
|
|
139
|
+
if (waits.get(eventName) === newPromise) {
|
|
140
|
+
waits.delete(eventName);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
waits.set(eventName, newPromise);
|
|
144
|
+
return newPromise;
|
|
145
|
+
}
|
|
146
|
+
const runner = () => {
|
|
147
|
+
return doWaitSubscribersExecution(eventName, eventBus, options);
|
|
148
|
+
};
|
|
149
|
+
const newPromise = chain.then(runner, runner).finally(() => {
|
|
150
|
+
// Once this chain is done, remove it from the map
|
|
151
|
+
// if it's still the same promise. This prevents race conditions
|
|
152
|
+
// where a new wait is queued before this one is removed.
|
|
153
|
+
if (waits.get(eventName) === newPromise) {
|
|
154
|
+
waits.delete(eventName);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
waits.set(eventName, newPromise);
|
|
158
|
+
return newPromise;
|
|
159
|
+
};
|
|
61
160
|
exports.waitSubscribersExecution = waitSubscribersExecution;
|
|
62
161
|
//# sourceMappingURL=events.js.map
|
package/dist/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;AAaA,+CAA+C;AAC/C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAiC,CAAA;AAEtD;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,CAC3B,OAAe,EACf,SAA0B,EACI,EAAE;IAChC,IAAI,SAAS,GAA0B,IAAI,CAAA;IAC3C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAC/C,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YAC1B,MAAM,CACJ,IAAI,KAAK,CACP,cAAc,OAAO,wCAAwC,MAAM,CACjE,SAAS,CACV,GAAG,CACL,CACF,CAAA;QACH,CAAC,EAAE,OAAO,CAAC,CAAA;QACX,SAAS,CAAC,KAAK,EAAE,CAAA;IACnB,CAAC,CAAC,CAAA;IACF,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC,CAAA;AAC9D,CAAC,CAAA;AAED,sCAAsC;AACtC,MAAM,0BAA0B,GAAG,CACjC,SAA0B,EAC1B,QAAkB,EAClB,EAAE,OAAO,GAAG,KAAK,EAAE,YAAY,GAAG,CAAC,KAAsC,EAAE,EAC7D,EAAE;IAChB,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAA;IAC3C,MAAM,kBAAkB,GAAmB,EAAE,CAAA;IAC7C,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,GAAG,oBAAoB,CACzD,OAAO,EACP,SAAS,CACV,CAAA;IAED,IAAI,YAAY,GAAG,CAAC,CAAA;IAEpB,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,C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,yDAAyD;YACzD,IAAI,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,UAAU,EAAE,CAAC;gBACxC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YACzB,CAAC;QACH,CAAC,CAAC,CAAA;QACF,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;QAChC,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,OAAO,0BAA0B,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;IACjE,CAAC,CAAA;IAED,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;QACzD,kDAAkD;QAClD,gEAAgE;QAChE,yDAAyD;QACzD,IAAI,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,UAAU,EAAE,CAAC;YACxC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QACzB,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;IAEhC,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AAxCY,QAAA,wBAAwB,4BAwCpC"}
|
package/dist/index.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
37
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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,uDAAoC;AACpC,6DAA0C;AAC1C,mEAAyE;AAAhE,8IAAA,OAAO,OAAuB;AACvC,uDAAoC"}
|
package/dist/init-modules.d.ts
CHANGED
|
@@ -10,8 +10,9 @@ export interface InitModulesOptions {
|
|
|
10
10
|
};
|
|
11
11
|
joinerConfig?: ModuleJoinerConfig[];
|
|
12
12
|
preventConnectionDestroyWarning?: boolean;
|
|
13
|
+
cwd?: string;
|
|
13
14
|
}
|
|
14
|
-
export declare function initModules({ injectedDependencies, databaseConfig, modulesConfig, joinerConfig, preventConnectionDestroyWarning, }: InitModulesOptions): Promise<{
|
|
15
|
+
export declare function initModules({ injectedDependencies, databaseConfig, modulesConfig, joinerConfig, preventConnectionDestroyWarning, cwd, }: InitModulesOptions): Promise<{
|
|
15
16
|
medusaApp: any;
|
|
16
17
|
shutdown: () => Promise<void>;
|
|
17
18
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-modules.d.ts","sourceRoot":"","sources":["../src/init-modules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init-modules.d.ts","sourceRoot":"","sources":["../src/init-modules.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EACnB,MAAM,2BAA2B,CAAA;AAOlC,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;IACzC,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,wBAAsB,WAAW,CAAC,EAChC,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,YAAY,EACZ,+BAAuC,EACvC,GAAG,GACJ,EAAE,kBAAkB;;;GAoDpB"}
|
package/dist/init-modules.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initModules = initModules;
|
|
4
|
+
const logger_1 = require("@medusajs/framework/logger");
|
|
4
5
|
const utils_1 = require("@medusajs/framework/utils");
|
|
5
|
-
async function initModules({ injectedDependencies, databaseConfig, modulesConfig, joinerConfig, preventConnectionDestroyWarning = false, }) {
|
|
6
|
+
async function initModules({ injectedDependencies, databaseConfig, modulesConfig, joinerConfig, preventConnectionDestroyWarning = false, cwd, }) {
|
|
6
7
|
const moduleSdkImports = require("@medusajs/framework/modules-sdk");
|
|
7
8
|
injectedDependencies ??= {};
|
|
8
9
|
let sharedPgConnection = injectedDependencies?.[utils_1.ContainerRegistrationKeys.PG_CONNECTION];
|
|
@@ -19,22 +20,23 @@ async function initModules({ injectedDependencies, databaseConfig, modulesConfig
|
|
|
19
20
|
modulesConfig,
|
|
20
21
|
servicesConfig: joinerConfig,
|
|
21
22
|
injectedDependencies,
|
|
23
|
+
cwd,
|
|
22
24
|
});
|
|
23
25
|
await medusaApp.onApplicationStart();
|
|
24
26
|
async function shutdown() {
|
|
27
|
+
const promises = [];
|
|
25
28
|
if (shouldDestroyConnectionAutomatically) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
medusaApp.onApplicationShutdown(),
|
|
31
|
-
]);
|
|
29
|
+
promises.push(sharedPgConnection.context?.destroy());
|
|
30
|
+
promises.push(sharedPgConnection.destroy());
|
|
31
|
+
promises.push(medusaApp.onApplicationPrepareShutdown());
|
|
32
|
+
promises.push(medusaApp.onApplicationShutdown());
|
|
32
33
|
}
|
|
33
34
|
else {
|
|
34
35
|
if (!preventConnectionDestroyWarning) {
|
|
35
|
-
|
|
36
|
+
logger_1.logger.info(`You are using a custom shared connection. The connection won't be destroyed automatically.`);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
39
|
+
await (0, utils_1.promiseAll)(promises);
|
|
38
40
|
moduleSdkImports.MedusaModule.clearInstances();
|
|
39
41
|
}
|
|
40
42
|
return {
|
package/dist/init-modules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-modules.js","sourceRoot":"","sources":["../src/init-modules.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"init-modules.js","sourceR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BAAqB,EAAE,CAAC,CAAA;QAClD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,+BAA+B,EAAE,CAAC;gBACrC,eAAM,CAAC,IAAI,CACT,4FAA4F,CAC7F,CAAA;YACH,CAAC;QACH,CAAC;QAED,MAAM,IAAA,kBAAU,EAAC,QAAQ,CAAC,CAAA;QAC1B,gBAAgB,CAAC,YAAY,CAAC,cAAc,EAAE,CAAA;IAChD,CAAC;IAED,OAAO;QACL,SAAS;QACT,QAAQ;KACT,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-app.d.ts","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/bootstrap-app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bootstrap-app.d.ts","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/bootstrap-app.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAyC3D,wBAAsB,QAAQ,CAAC,EAC7B,GAAG,EACH,GAAQ,GACT,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;CAAO,GAAG,OAAO,CAAC;IACzD,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7B,SAAS,EAAE,eAAe,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;CACb,CAAC,CAiFD"}
|