medusa-test-utils 1.1.45-snapshot-20240717160031 → 1.1.45-snapshot-20240718083016

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. package/dist/database.d.ts +0 -1
  2. package/dist/database.js +142 -56
  3. package/dist/database.js.map +1 -1
  4. package/dist/id-map.d.ts +2 -3
  5. package/dist/id-map.js +13 -8
  6. package/dist/id-map.js.map +1 -1
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +6 -3
  9. package/dist/index.js.map +1 -1
  10. package/dist/init-modules.d.ts +0 -1
  11. package/dist/init-modules.js +95 -38
  12. package/dist/init-modules.js.map +1 -1
  13. package/dist/jest.d.ts +0 -1
  14. package/dist/jest.js +62 -14
  15. package/dist/jest.js.map +1 -1
  16. package/dist/medusa-test-runner-utils/bootstrap-app.d.ts +5 -10
  17. package/dist/medusa-test-runner-utils/bootstrap-app.js +146 -54
  18. package/dist/medusa-test-runner-utils/bootstrap-app.js.map +1 -1
  19. package/dist/medusa-test-runner-utils/use-db.d.ts +12 -5
  20. package/dist/medusa-test-runner-utils/use-db.js +143 -29
  21. package/dist/medusa-test-runner-utils/use-db.js.map +1 -1
  22. package/dist/medusa-test-runner.d.ts +3 -9
  23. package/dist/medusa-test-runner.js +332 -144
  24. package/dist/medusa-test-runner.js.map +1 -1
  25. package/dist/mock-event-bus-service.d.ts +4 -5
  26. package/dist/mock-event-bus-service.js +51 -13
  27. package/dist/mock-event-bus-service.js.map +1 -1
  28. package/dist/mock-manager.d.ts +9 -0
  29. package/dist/mock-manager.js +30 -0
  30. package/dist/mock-manager.js.map +1 -0
  31. package/dist/mock-repository.d.ts +51 -0
  32. package/dist/mock-repository.js +193 -0
  33. package/dist/mock-repository.js.map +1 -0
  34. package/dist/module-test-runner.d.ts +2 -3
  35. package/dist/module-test-runner.js +129 -60
  36. package/dist/module-test-runner.js.map +1 -1
  37. package/package.json +12 -7
  38. package/dist/database.d.ts.map +0 -1
  39. package/dist/events.d.ts +0 -3
  40. package/dist/events.d.ts.map +0 -1
  41. package/dist/events.js +0 -24
  42. package/dist/events.js.map +0 -1
  43. package/dist/id-map.d.ts.map +0 -1
  44. package/dist/index.d.ts.map +0 -1
  45. package/dist/init-modules.d.ts.map +0 -1
  46. package/dist/jest.d.ts.map +0 -1
  47. package/dist/medusa-test-runner-utils/bootstrap-app.d.ts.map +0 -1
  48. package/dist/medusa-test-runner-utils/use-db.d.ts.map +0 -1
  49. package/dist/medusa-test-runner.d.ts.map +0 -1
  50. package/dist/mock-event-bus-service.d.ts.map +0 -1
  51. package/dist/module-test-runner.d.ts.map +0 -1
@@ -1,10 +1,5 @@
1
- import { MedusaContainer } from "@medusajs/types";
2
- export declare function startApp({ cwd, env, }?: {
3
- cwd?: string;
4
- env?: Record<any, any>;
5
- }): Promise<{
6
- shutdown: () => Promise<void>;
7
- container: MedusaContainer;
8
- port: number;
9
- }>;
10
- //# sourceMappingURL=bootstrap-app.d.ts.map
1
+ export function startBootstrapApp({ cwd, env, skipExpressListen, }?: {
2
+ cwd: any;
3
+ env?: {} | undefined;
4
+ skipExpressListen?: boolean | undefined;
5
+ }): Promise<any>;
@@ -1,61 +1,153 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
4
9
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.startApp = void 0;
7
- const express_1 = __importDefault(require("express"));
8
- const get_port_1 = __importDefault(require("get-port"));
9
- const path_1 = require("path");
10
- const utils_1 = require("@medusajs/utils");
11
- async function bootstrapApp({ cwd, env = {}, } = {}) {
12
- const app = (0, express_1.default)();
13
- if ((0, utils_1.isObject)(env)) {
14
- Object.entries(env).forEach(([k, v]) => (process.env[k] = v));
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
15
35
  }
16
- const loaders = require("@medusajs/medusa/dist/loaders").default;
17
- const { container, shutdown } = await loaders({
18
- directory: (0, path_1.resolve)(cwd || process.cwd()),
19
- expressApp: app,
20
- });
21
- const PORT = await (0, get_port_1.default)();
22
- return {
23
- shutdown,
24
- container,
25
- app,
26
- port: PORT,
27
- };
28
- }
29
- async function startApp({ cwd, env = {}, } = {}) {
30
- const { app, port, container, shutdown: medusaShutdown, } = await bootstrapApp({
31
- cwd,
32
- env,
33
- });
34
- let expressServer;
35
- const shutdown = async () => {
36
- await (0, utils_1.promiseAll)([expressServer?.shutdown(), medusaShutdown()]);
37
- if (typeof global !== "undefined" && global?.gc) {
38
- global.gc();
36
+ };
37
+ var __read = (this && this.__read) || function (o, n) {
38
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
39
+ if (!m) return o;
40
+ var i = m.call(o), r, ar = [], e;
41
+ try {
42
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
43
+ }
44
+ catch (error) { e = { error: error }; }
45
+ finally {
46
+ try {
47
+ if (r && !r.done && (m = i["return"])) m.call(i);
39
48
  }
40
- };
41
- return await new Promise((resolve, reject) => {
42
- const server = app
43
- .listen(port)
44
- .on("error", async (err) => {
45
- await shutdown();
46
- return reject(err);
47
- })
48
- .on("listening", () => {
49
- process.send?.(port);
50
- resolve({
51
- shutdown,
52
- container,
53
- port,
54
- });
49
+ finally { if (e) throw e.error; }
50
+ }
51
+ return ar;
52
+ };
53
+ var _this = this;
54
+ var path = require("path");
55
+ var express = require("express");
56
+ var getPort = require("get-port");
57
+ var _a = require("@medusajs/utils"), isObject = _a.isObject, promiseAll = _a.promiseAll;
58
+ var GracefulShutdownServer = require("medusa-core-utils").GracefulShutdownServer;
59
+ function bootstrapApp(_a) {
60
+ var _b = _a === void 0 ? {} : _a, cwd = _b.cwd, _c = _b.env, env = _c === void 0 ? {} : _c;
61
+ return __awaiter(this, void 0, void 0, function () {
62
+ var app, loaders, _d, container, shutdown, PORT;
63
+ return __generator(this, function (_e) {
64
+ switch (_e.label) {
65
+ case 0:
66
+ app = express();
67
+ if (isObject(env)) {
68
+ Object.entries(env).forEach(function (_a) {
69
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
70
+ return (process.env[k] = v);
71
+ });
72
+ }
73
+ loaders = require("@medusajs/medusa/dist/loaders").default;
74
+ return [4 /*yield*/, loaders({
75
+ directory: path.resolve(cwd || process.cwd()),
76
+ expressApp: app,
77
+ isTest: false,
78
+ })];
79
+ case 1:
80
+ _d = _e.sent(), container = _d.container, shutdown = _d.shutdown;
81
+ return [4 /*yield*/, getPort()];
82
+ case 2:
83
+ PORT = _e.sent();
84
+ return [2 /*return*/, {
85
+ shutdown: shutdown,
86
+ container: container,
87
+ app: app,
88
+ port: PORT,
89
+ }];
90
+ }
55
91
  });
56
- // TODO: fix that once we find the appropriate place to put this util
57
- expressServer = utils_1.GracefulShutdownServer.create(server);
58
92
  });
59
93
  }
60
- exports.startApp = startApp;
94
+ module.exports = {
95
+ startBootstrapApp: function (_a) {
96
+ var _b = _a === void 0 ? {} : _a, cwd = _b.cwd, _c = _b.env, env = _c === void 0 ? {} : _c, _d = _b.skipExpressListen, skipExpressListen = _d === void 0 ? false : _d;
97
+ return __awaiter(_this, void 0, void 0, function () {
98
+ var _e, app, port, container, medusaShutdown, expressServer, shutdown;
99
+ var _this = this;
100
+ return __generator(this, function (_f) {
101
+ switch (_f.label) {
102
+ case 0: return [4 /*yield*/, bootstrapApp({
103
+ cwd: cwd,
104
+ env: env,
105
+ })];
106
+ case 1:
107
+ _e = _f.sent(), app = _e.app, port = _e.port, container = _e.container, medusaShutdown = _e.shutdown;
108
+ if (skipExpressListen) {
109
+ return [2 /*return*/];
110
+ }
111
+ shutdown = function () { return __awaiter(_this, void 0, void 0, function () {
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0: return [4 /*yield*/, promiseAll([expressServer.shutdown(), medusaShutdown()])];
115
+ case 1:
116
+ _a.sent();
117
+ if (typeof global !== "undefined" && (global === null || global === void 0 ? void 0 : global.gc)) {
118
+ global.gc();
119
+ }
120
+ return [2 /*return*/];
121
+ }
122
+ });
123
+ }); };
124
+ return [4 /*yield*/, new Promise(function (resolve, reject) {
125
+ var server = app.listen(port, function (err) { return __awaiter(_this, void 0, void 0, function () {
126
+ return __generator(this, function (_a) {
127
+ switch (_a.label) {
128
+ case 0:
129
+ if (!err) return [3 /*break*/, 2];
130
+ return [4 /*yield*/, shutdown()];
131
+ case 1:
132
+ _a.sent();
133
+ return [2 /*return*/, reject(err)];
134
+ case 2:
135
+ process.send(port);
136
+ resolve({
137
+ shutdown: shutdown,
138
+ container: container,
139
+ port: port,
140
+ });
141
+ return [2 /*return*/];
142
+ }
143
+ });
144
+ }); });
145
+ expressServer = GracefulShutdownServer.create(server);
146
+ })];
147
+ case 2: return [2 /*return*/, _f.sent()];
148
+ }
149
+ });
150
+ });
151
+ },
152
+ };
61
153
  //# sourceMappingURL=bootstrap-app.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap-app.js","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/bootstrap-app.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAC7B,wDAA8B;AAC9B,+BAA8B;AAC9B,2CAA8E;AAG9E,KAAK,UAAU,YAAY,CAAC,EAC1B,GAAG,EACH,GAAG,GAAG,EAAE,MACoC,EAAE;IAC9C,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAA;IAErB,IAAI,IAAA,gBAAQ,EAAC,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC,OAAO,CAAA;IAEhE,MAAM,EAAE,S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,MAAM,CAAC,IAAI,EAAE,UAAO,GAAG;;;;qDACpC,GAAG,EAAH,wBAAG;gDACL,qBAAM,QAAQ,EAAE,EAAA;;gDAAhB,SAAgB,CAAA;gDAChB,sBAAO,MAAM,CAAC,GAAG,CAAC,EAAA;;gDAEpB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gDAClB,OAAO,CAAC;oDACN,QAAQ,UAAA;oDACR,SAAS,WAAA;oDACT,IAAI,MAAA;iDACL,CAAC,CAAA;;;;qCACH,CAAC,CAAA;gCAEF,aAAa,GAAG,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;4BACvD,CAAC,CAAC,EAAA;4BAfF,sBAAO,SAeL,EAAA;;;;KACH;CACF,CAAA"}
@@ -1,5 +1,12 @@
1
- export declare function initDb({ cwd, env, }: {
2
- cwd: string;
3
- env?: Record<any, any>;
4
- }): Promise<any>;
5
- //# sourceMappingURL=use-db.d.ts.map
1
+ import { DataSource } from "typeorm";
2
+ export function initDb({ cwd, database_extra, env, force_modules_migration, dbUrl, dbSchema, }: {
3
+ cwd: any;
4
+ database_extra: any;
5
+ env: any;
6
+ force_modules_migration: any;
7
+ dbUrl?: string | undefined;
8
+ dbSchema?: string | undefined;
9
+ }): Promise<{
10
+ dbDataSource: DataSource;
11
+ pgConnection: any;
12
+ }>;
@@ -1,34 +1,148 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initDb = void 0;
4
- const utils_1 = require("@medusajs/utils");
5
- const awilix_1 = require("awilix");
6
- async function initDb({ cwd, env = {}, }) {
7
- if ((0, utils_1.isObject)(env)) {
8
- Object.entries(env).forEach(([k, v]) => (process.env[k] = v));
9
- }
10
- const container = (0, utils_1.createMedusaContainer)();
11
- const configModule = await require("@medusajs/medusa/dist/loaders/config").default(cwd);
12
- const pgConnection = await require("@medusajs/medusa/dist/loaders/pg-connection").default({
13
- configModule,
14
- container,
15
- });
16
- const featureFlagRouter = require("@medusajs/medusa/dist/loaders/feature-flags").default(configModule);
17
- container.register({
18
- [utils_1.ContainerRegistrationKeys.CONFIG_MODULE]: (0, awilix_1.asValue)(configModule),
19
- [utils_1.ContainerRegistrationKeys.LOGGER]: (0, awilix_1.asValue)(console),
20
- [utils_1.ContainerRegistrationKeys.PG_CONNECTION]: (0, awilix_1.asValue)(pgConnection),
21
- [utils_1.ContainerRegistrationKeys.FEATURE_FLAG_ROUTER]: (0, awilix_1.asValue)(featureFlagRouter),
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
22
19
  });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __read = (this && this.__read) || function (o, n) {
49
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
50
+ if (!m) return o;
51
+ var i = m.call(o), r, ar = [], e;
23
52
  try {
24
- const { runMedusaAppMigrations, } = require("@medusajs/medusa/dist/loaders/medusa-app");
25
- await runMedusaAppMigrations({ configModule, container });
53
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
26
54
  }
27
- catch (err) {
28
- console.error("Something went wrong while running the migrations");
29
- throw err;
55
+ catch (error) { e = { error: error }; }
56
+ finally {
57
+ try {
58
+ if (r && !r.done && (m = i["return"])) m.call(i);
59
+ }
60
+ finally { if (e) throw e.error; }
30
61
  }
31
- return pgConnection;
32
- }
33
- exports.initDb = initDb;
62
+ return ar;
63
+ };
64
+ var path = require("path");
65
+ var getConfigFile = require("medusa-core-utils").getConfigFile;
66
+ var asValue = require("awilix").asValue;
67
+ var _a = require("@medusajs/utils"), isObject = _a.isObject, createMedusaContainer = _a.createMedusaContainer, MedusaV2Flag = _a.MedusaV2Flag;
68
+ var DataSource = require("typeorm").DataSource;
69
+ var ContainerRegistrationKeys = require("@medusajs/utils").ContainerRegistrationKeys;
70
+ var logger = require("@medusajs/medusa-cli/dist/reporter").logger;
71
+ module.exports = {
72
+ initDb: function (_a) {
73
+ var cwd = _a.cwd,
74
+ // use for v1 datasource only
75
+ database_extra = _a.database_extra, env = _a.env, force_modules_migration = _a.force_modules_migration, _b = _a.dbUrl, dbUrl = _b === void 0 ? "" : _b, _c = _a.dbSchema, dbSchema = _c === void 0 ? "public" : _c;
76
+ return __awaiter(this, void 0, void 0, function () {
77
+ var configModuleLoader, configModule, featureFlagsLoader, featureFlagRouter, modelsLoader, entities, migrationDir, _d, getEnabledMigrations, getModuleSharedResources, _e, moduleMigrations, moduleModels, enabledMigrations, enabledEntities, dbDataSource, pgConnectionLoader, featureFlagLoader, container, featureFlagRouter_1, pgConnection, migrateMedusaApp;
78
+ var _f;
79
+ return __generator(this, function (_g) {
80
+ switch (_g.label) {
81
+ case 0:
82
+ if (isObject(env)) {
83
+ Object.entries(env).forEach(function (_a) {
84
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
85
+ return (process.env[k] = v);
86
+ });
87
+ }
88
+ configModuleLoader = require("@medusajs/medusa/dist/loaders/config").default;
89
+ configModule = configModuleLoader(cwd);
90
+ featureFlagsLoader = require("@medusajs/medusa/dist/loaders/feature-flags").default;
91
+ featureFlagRouter = featureFlagsLoader(configModule);
92
+ modelsLoader = require("@medusajs/medusa/dist/loaders/models").default;
93
+ entities = modelsLoader({}, { register: false });
94
+ migrationDir = path.resolve(path.join(cwd, "../../", "node_modules", "@medusajs", "medusa", "dist", "migrations", "*.js"));
95
+ _d = require("@medusajs/medusa/dist/commands/utils/get-migrations"), getEnabledMigrations = _d.getEnabledMigrations, getModuleSharedResources = _d.getModuleSharedResources;
96
+ _e = getModuleSharedResources(configModule, featureFlagRouter), moduleMigrations = _e.migrations, moduleModels = _e.models;
97
+ enabledMigrations = getEnabledMigrations([migrationDir], function (flag) {
98
+ return featureFlagRouter.isFeatureEnabled(flag);
99
+ });
100
+ enabledEntities = entities.filter(function (e) { return typeof e.isFeatureEnabled === "undefined" || e.isFeatureEnabled(); });
101
+ dbDataSource = new DataSource({
102
+ type: "postgres",
103
+ url: dbUrl || configModule.projectConfig.database_url,
104
+ entities: enabledEntities.concat(moduleModels),
105
+ migrations: enabledMigrations.concat(moduleMigrations),
106
+ extra: database_extra !== null && database_extra !== void 0 ? database_extra : {},
107
+ //name: "integration-tests",
108
+ schema: dbSchema,
109
+ });
110
+ return [4 /*yield*/, dbDataSource.initialize()];
111
+ case 1:
112
+ _g.sent();
113
+ return [4 /*yield*/, dbDataSource.runMigrations()];
114
+ case 2:
115
+ _g.sent();
116
+ if (!(force_modules_migration ||
117
+ featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key))) return [3 /*break*/, 6];
118
+ pgConnectionLoader = require("@medusajs/medusa/dist/loaders/pg-connection").default;
119
+ featureFlagLoader = require("@medusajs/medusa/dist/loaders/feature-flags").default;
120
+ container = createMedusaContainer();
121
+ return [4 /*yield*/, featureFlagLoader(configModule)];
122
+ case 3:
123
+ featureFlagRouter_1 = _g.sent();
124
+ return [4 /*yield*/, pgConnectionLoader({
125
+ configModule: __assign(__assign({}, configModule), { projectConfig: __assign(__assign({}, configModule.projectConfig), { database_url: dbUrl || configModule.projectConfig.database_url }) }),
126
+ container: container,
127
+ })];
128
+ case 4:
129
+ pgConnection = _g.sent();
130
+ container.register((_f = {},
131
+ _f[ContainerRegistrationKeys.CONFIG_MODULE] = asValue(configModule),
132
+ _f[ContainerRegistrationKeys.LOGGER] = asValue(logger),
133
+ _f[ContainerRegistrationKeys.MANAGER] = asValue(dbDataSource.manager),
134
+ _f[ContainerRegistrationKeys.PG_CONNECTION] = asValue(pgConnection),
135
+ _f.featureFlagRouter = asValue(featureFlagRouter_1),
136
+ _f));
137
+ migrateMedusaApp = require("@medusajs/medusa/dist/loaders/medusa-app").migrateMedusaApp;
138
+ return [4 /*yield*/, migrateMedusaApp({ configModule: configModule, container: container }, { registerInContainer: false })];
139
+ case 5:
140
+ _g.sent();
141
+ _g.label = 6;
142
+ case 6: return [2 /*return*/, { dbDataSource: dbDataSource, pgConnection: pgConnection }];
143
+ }
144
+ });
145
+ });
146
+ },
147
+ };
34
148
  //# sourceMappingURL=use-db.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-db.js","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/use-db.ts"],"names":[],"mappings":";;;AAAA,2CAIwB;AACxB,mCAAgC;AAEzB,KAAK,UAAU,MAAM,CAAC,EAC3B,GAAG,EACH,GAAG,GAAG,EAAE,GAIT;IACC,IAAI,IAAA,gBAAQ,EAAC,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,SAAS,GAAG,IAAA,6BAAqB,GAAE,CAAA;IAEzC,MAAM,YAAY,GAChB,MAAM,OAAO,CAAC,sCAAsC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAEpE,MAAM,YAAY,GAChB,MAAM,OAAO,CAAC,6CAA6C,CAAC,CAAC,OAAO,CAAC;QACnE,YAAY;QACZ,SAAS;KACV,CAAC,CAAA;IAEJ,MAAM,iBAAiB,GACrB,OAAO,CAAC,6CAA6C,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;IAE9E,SAAS,CAAC,QAAQ,CAAC;QACjB,CAAC,iCAAyB,CAAC,aAAa,CAAC,EAAE,IAAA,gBAAO,EAAC,YAAY,CAAC;QAChE,CAAC,iCAAyB,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B,CAAC;gCAC5C,YAAY,wBACP,YAAY,KACf,aAAa,wBACR,YAAY,CAAC,aAAa,KAC7B,YAAY,EAAE,KAAK,IAAI,YAAY,CAAC,aAAa,CAAC,YAAY,MAEjE;gCACD,SAAS,WAAA;6BACV,CAAC,EAAA;;wBATI,YAAY,GAAG,SASnB;wBAEF,SAAS,CAAC,QAAQ;4BAChB,GAAC,yBAAyB,CAAC,aAAa,IAAG,OAAO,CAAC,YAAY,CAAC;4BAChE,GAAC,yBAAyB,CAAC,MAAM,IAAG,OAAO,CAAC,MAAM,CAAC;4BACnD,GAAC,yBAAyB,CAAC,OAAO,IAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC;4BAClE,GAAC,yBAAyB,CAAC,aAAa,IAAG,OAAO,CAAC,YAAY,CAAC;4BAChE,oBAAiB,GAAE,OAAO,CAAC,mBAAiB,CAAC;gCAC7C,CAAA;wBAGA,gBAAgB,GACd,OAAO,CAAC,0CAA0C,CAAC,iBADrC,CACqC;wBACvD,qBAAM,gBAAgB,CACpB,EAAE,YAAY,cAAA,EAAE,SAAS,WAAA,EAAE,EAC3B,EAAE,mBAAmB,EAAE,KAAK,EAAE,CAC/B,EAAA;;wBAHD,SAGC,CAAA;;4BAGH,sBAAO,EAAE,YAAY,cAAA,EAAE,YAAY,cAAA,EAAE,EAAA;;;;KACtC;CACF,CAAA"}
@@ -1,27 +1,21 @@
1
1
  import { MedusaContainer } from "@medusajs/types";
2
2
  export interface MedusaSuiteOptions<TService = unknown> {
3
+ dbUtils: any;
3
4
  dbConnection: any;
4
5
  getContainer: () => MedusaContainer;
5
6
  api: any;
6
- dbUtils: {
7
- create: (dbName: string) => Promise<void>;
8
- teardown: (options: {
9
- schema?: string;
10
- }) => Promise<void>;
11
- shutdown: (dbName: string) => Promise<void>;
12
- };
13
7
  dbConfig: {
14
8
  dbName: string;
15
9
  schema: string;
16
10
  clientUrl: string;
17
11
  };
18
12
  }
19
- export declare function medusaIntegrationTestRunner({ moduleName, dbName, schema, env, debug, testSuite, }: {
13
+ export declare function medusaIntegrationTestRunner({ moduleName, dbName, schema, env, force_modules_migration, debug, testSuite, }: {
20
14
  moduleName?: string;
21
15
  env?: Record<string, any>;
22
16
  dbName?: string;
23
17
  schema?: string;
24
18
  debug?: boolean;
19
+ force_modules_migration?: boolean;
25
20
  testSuite: <TService = unknown>(options: MedusaSuiteOptions<TService>) => void;
26
21
  }): void;
27
- //# sourceMappingURL=medusa-test-runner.d.ts.map