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.
- package/dist/database.d.ts +0 -1
- package/dist/database.js +142 -56
- package/dist/database.js.map +1 -1
- package/dist/id-map.d.ts +2 -3
- package/dist/id-map.js +13 -8
- package/dist/id-map.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/init-modules.d.ts +0 -1
- package/dist/init-modules.js +95 -38
- package/dist/init-modules.js.map +1 -1
- package/dist/jest.d.ts +0 -1
- package/dist/jest.js +62 -14
- package/dist/jest.js.map +1 -1
- package/dist/medusa-test-runner-utils/bootstrap-app.d.ts +5 -10
- package/dist/medusa-test-runner-utils/bootstrap-app.js +146 -54
- package/dist/medusa-test-runner-utils/bootstrap-app.js.map +1 -1
- package/dist/medusa-test-runner-utils/use-db.d.ts +12 -5
- package/dist/medusa-test-runner-utils/use-db.js +143 -29
- package/dist/medusa-test-runner-utils/use-db.js.map +1 -1
- package/dist/medusa-test-runner.d.ts +3 -9
- package/dist/medusa-test-runner.js +332 -144
- package/dist/medusa-test-runner.js.map +1 -1
- package/dist/mock-event-bus-service.d.ts +4 -5
- package/dist/mock-event-bus-service.js +51 -13
- package/dist/mock-event-bus-service.js.map +1 -1
- package/dist/mock-manager.d.ts +9 -0
- package/dist/mock-manager.js +30 -0
- package/dist/mock-manager.js.map +1 -0
- package/dist/mock-repository.d.ts +51 -0
- package/dist/mock-repository.js +193 -0
- package/dist/mock-repository.js.map +1 -0
- package/dist/module-test-runner.d.ts +2 -3
- package/dist/module-test-runner.js +129 -60
- package/dist/module-test-runner.js.map +1 -1
- package/package.json +12 -7
- package/dist/database.d.ts.map +0 -1
- package/dist/events.d.ts +0 -3
- package/dist/events.d.ts.map +0 -1
- package/dist/events.js +0 -24
- package/dist/events.js.map +0 -1
- package/dist/id-map.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/init-modules.d.ts.map +0 -1
- package/dist/jest.d.ts.map +0 -1
- package/dist/medusa-test-runner-utils/bootstrap-app.d.ts.map +0 -1
- package/dist/medusa-test-runner-utils/use-db.d.ts.map +0 -1
- package/dist/medusa-test-runner.d.ts.map +0 -1
- package/dist/mock-event-bus-service.d.ts.map +0 -1
- package/dist/module-test-runner.d.ts.map +0 -1
@@ -1,10 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
2
|
-
|
3
|
-
return (
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
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.
|
1
|
+
{"version":3,"file":"bootstrap-app.js","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/bootstrap-app.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBA+EA;AA/EA,IAAM,IAAI,GA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C,CAAC,EAAA;4BAfF,sBAAO,SAeL,EAAA;;;;KACH;CACF,CAAA"}
|
@@ -1,5 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
2
|
-
Object.
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
}
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
25
|
-
await runMedusaAppMigrations({ configModule, container });
|
53
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
26
54
|
}
|
27
|
-
catch (
|
28
|
-
|
29
|
-
|
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
|
32
|
-
}
|
33
|
-
|
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.
|
1
|
+
{"version":3,"file":"use-db.js","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/use-db.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAEpB,IAAA,aAAa,GAAK,OAAO,CAAC,mBAAmB,CAAC,cAAjC,CAAiC;AAC9C,IAAA,OAAO,GAAK,OAAO,CAAC,QAAQ,CAAC,QAAtB,CAAsB;AAC/B,IAAA,KAIF,OAAO,CAAC,iBAAiB,CAAC,EAH5B,QAAQ,cAAA,EACR,qBAAqB,2BAAA,EACrB,YAAY,kBACgB,CAAA;AACtB,IAAA,UAAU,GAAK,OAAO,CAAC,SAAS,CAAC,WAAvB,CAAuB;AACjC,IAAA,yBAAyB,GAAK,OAAO,CAAC,iBAAiB,CAAC,0BAA/B,CAA+B;AACxD,IAAA,MAAM,GAAK,OAAO,CAAC,oCAAoC,CAAC,OAAlD,CAAkD;AAEhE,MAAM,CAAC,OAAO,GAAG;IACf,MAAM,EAAE,UAAgB,EAQvB;YAPC,GAAG,SAAA;QACH,6BAA6B;QAC7B,cAAc,oBAAA,EACd,GAAG,SAAA,EACH,uBAAuB,6BAAA,EACvB,aAAU,EAAV,KAAK,mBAAG,EAAE,KAAA,EACV,gBAAmB,EAAnB,QAA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EF,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
|