@medusajs/test-utils
Version:
Test utils for Medusa
46 lines • 1.9 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.initModules = initModules;
const utils_1 = require("@medusajs/framework/utils");
const logger_1 = require("@medusajs/framework/logger");
async function initModules({ injectedDependencies, databaseConfig, modulesConfig, joinerConfig, preventConnectionDestroyWarning = false, }) {
const moduleSdkImports = require("@medusajs/framework/modules-sdk");
injectedDependencies ??= {};
let sharedPgConnection = injectedDependencies?.[utils_1.ContainerRegistrationKeys.PG_CONNECTION];
let shouldDestroyConnectionAutomatically = !sharedPgConnection;
if (!sharedPgConnection) {
sharedPgConnection = (0, utils_1.createPgConnection)({
clientUrl: databaseConfig.clientUrl,
schema: databaseConfig.schema,
});
injectedDependencies[utils_1.ContainerRegistrationKeys.PG_CONNECTION] =
sharedPgConnection;
}
const medusaApp = await moduleSdkImports.MedusaApp({
modulesConfig,
servicesConfig: joinerConfig,
injectedDependencies,
});
await medusaApp.onApplicationStart();
async function shutdown() {
if (shouldDestroyConnectionAutomatically) {
await medusaApp.onApplicationPrepareShutdown();
await (0, utils_1.promiseAll)([
sharedPgConnection.context?.destroy(),
sharedPgConnection.destroy(),
medusaApp.onApplicationShutdown(),
]);
}
else {
if (!preventConnectionDestroyWarning) {
logger_1.logger.info(`You are using a custom shared connection. The connection won't be destroyed automatically.`);
}
}
moduleSdkImports.MedusaModule.clearInstances();
}
return {
medusaApp,
shutdown,
};
}
//# sourceMappingURL=init-modules.js.map
;