medusa-test-utils 1.1.45-snapshot-20240808104955 → 1.1.45-snapshot-20240815071705
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/medusa-test-runner-utils/bootstrap-app.d.ts.map +1 -1
- package/dist/medusa-test-runner-utils/bootstrap-app.js +5 -6
- package/dist/medusa-test-runner-utils/bootstrap-app.js.map +1 -1
- package/dist/medusa-test-runner-utils/clear-instances.d.ts +8 -0
- package/dist/medusa-test-runner-utils/clear-instances.d.ts.map +1 -0
- package/dist/medusa-test-runner-utils/clear-instances.js +15 -0
- package/dist/medusa-test-runner-utils/clear-instances.js.map +1 -0
- package/dist/medusa-test-runner-utils/use-db.d.ts +13 -3
- package/dist/medusa-test-runner-utils/use-db.d.ts.map +1 -1
- package/dist/medusa-test-runner-utils/use-db.js +32 -25
- package/dist/medusa-test-runner-utils/use-db.js.map +1 -1
- package/dist/medusa-test-runner-utils/utils.d.ts +2 -0
- package/dist/medusa-test-runner-utils/utils.d.ts.map +1 -0
- package/dist/medusa-test-runner-utils/utils.js +11 -0
- package/dist/medusa-test-runner-utils/utils.js.map +1 -0
- package/dist/medusa-test-runner.d.ts +2 -1
- package/dist/medusa-test-runner.d.ts.map +1 -1
- package/dist/medusa-test-runner.js +32 -12
- package/dist/medusa-test-runner.js.map +1 -1
- package/package.json +8 -7
@@ -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":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AA4BjD,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,CAyCD"}
|
@@ -7,12 +7,11 @@ exports.startApp = void 0;
|
|
7
7
|
const express_1 = __importDefault(require("express"));
|
8
8
|
const get_port_1 = __importDefault(require("get-port"));
|
9
9
|
const path_1 = require("path");
|
10
|
-
const utils_1 = require("
|
10
|
+
const utils_1 = require("./utils");
|
11
|
+
const utils_2 = require("@medusajs/utils");
|
11
12
|
async function bootstrapApp({ cwd, env = {}, } = {}) {
|
12
13
|
const app = (0, express_1.default)();
|
13
|
-
|
14
|
-
Object.entries(env).forEach(([k, v]) => (process.env[k] = v));
|
15
|
-
}
|
14
|
+
(0, utils_1.applyEnvVarsToProcess)(env);
|
16
15
|
const loaders = require("@medusajs/medusa/dist/loaders").default;
|
17
16
|
const { container, shutdown } = await loaders({
|
18
17
|
directory: (0, path_1.resolve)(cwd || process.cwd()),
|
@@ -33,7 +32,7 @@ async function startApp({ cwd, env = {}, } = {}) {
|
|
33
32
|
});
|
34
33
|
let expressServer;
|
35
34
|
const shutdown = async () => {
|
36
|
-
await (0,
|
35
|
+
await (0, utils_2.promiseAll)([expressServer?.shutdown(), medusaShutdown()]);
|
37
36
|
if (typeof global !== "undefined" && global?.gc) {
|
38
37
|
global.gc();
|
39
38
|
}
|
@@ -54,7 +53,7 @@ async function startApp({ cwd, env = {}, } = {}) {
|
|
54
53
|
});
|
55
54
|
});
|
56
55
|
// TODO: fix that once we find the appropriate place to put this util
|
57
|
-
expressServer =
|
56
|
+
expressServer = utils_2.GracefulShutdownServer.create(server);
|
58
57
|
});
|
59
58
|
}
|
60
59
|
exports.startApp = startApp;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"bootstrap-app.js","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/bootstrap-app.ts"],"names":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,MAAM,KAAK,WAAW,IAAI,MAAM,EAAE,EAAE,EAAE,CAAC;YAChD,MAAM,CAAC,EAAE,EAAE,CAAA;QACb,CAAC;IACH,CAAC,CAAA;IAED,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,GAAG;aACf,MAAM,CAAC,IAAI,CAAC;aACZ,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YACzB,MAAM,QAAQ,EAAE,CAAA;YAChB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;QACpB,CAAC,CAAC;aACD,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE;YACpB,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAA;YAEpB,OAAO,CAAC;gBACN,QAAQ;gBACR,SAAS;gBACT,IAAI;aACL,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEJ,qEAAqE;QACrE,aAAa,GAAG,8BAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;AACJ,CAAC;AAhDD,4BAgDC"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
* cleanup temporary created resources for the migrations
|
3
|
+
* @internal I didnt find a god place to put that, should we eventually add a close function
|
4
|
+
* to the planner to handle that part? so that you would do planner.close() and it will handle the cleanup
|
5
|
+
* automatically just like we usually do for the classic migrations actions
|
6
|
+
*/
|
7
|
+
export declare function clearInstances(): Promise<void>;
|
8
|
+
//# sourceMappingURL=clear-instances.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"clear-instances.d.ts","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/clear-instances.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAsB,cAAc,kBAGnC"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.clearInstances = void 0;
|
4
|
+
/**
|
5
|
+
* cleanup temporary created resources for the migrations
|
6
|
+
* @internal I didnt find a god place to put that, should we eventually add a close function
|
7
|
+
* to the planner to handle that part? so that you would do planner.close() and it will handle the cleanup
|
8
|
+
* automatically just like we usually do for the classic migrations actions
|
9
|
+
*/
|
10
|
+
async function clearInstances() {
|
11
|
+
const { MedusaModule } = require("@medusajs/modules-sdk");
|
12
|
+
MedusaModule.clearInstances();
|
13
|
+
}
|
14
|
+
exports.clearInstances = clearInstances;
|
15
|
+
//# sourceMappingURL=clear-instances.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"clear-instances.js","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/clear-instances.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,KAAK,UAAU,cAAc;IAClC,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;IACzD,YAAY,CAAC,cAAc,EAAE,CAAA;AAC/B,CAAC;AAHD,wCAGC"}
|
@@ -1,4 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
import type { MedusaAppLoader } from "@medusajs/framework";
|
2
|
+
/**
|
3
|
+
* Initiates the database connection
|
4
|
+
*/
|
5
|
+
export declare function initDb(): Promise<import("@mikro-orm/knex").Knex<any, any>>;
|
6
|
+
/**
|
7
|
+
* Migrates the database
|
8
|
+
*/
|
9
|
+
export declare function migrateDatabase(appLoader: MedusaAppLoader): Promise<void>;
|
10
|
+
/**
|
11
|
+
* Syncs links with the databse
|
12
|
+
*/
|
13
|
+
export declare function syncLinks(appLoader: MedusaAppLoader): Promise<void>;
|
4
14
|
//# sourceMappingURL=use-db.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-db.d.ts","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/use-db.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"use-db.d.ts","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/use-db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAI1D;;GAEG;AACH,wBAAsB,MAAM,sDAS3B;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,SAAS,EAAE,eAAe,iBAO/D;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,SAAS,EAAE,eAAe,iBAYzD"}
|
@@ -1,38 +1,45 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.initDb = void 0;
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
}
|
10
|
-
const { pgConnectionLoader, logger, container, featureFlagsLoader, MedusaAppLoader, } = await import("@medusajs/framework");
|
3
|
+
exports.syncLinks = exports.migrateDatabase = exports.initDb = void 0;
|
4
|
+
/**
|
5
|
+
* Initiates the database connection
|
6
|
+
*/
|
7
|
+
async function initDb() {
|
8
|
+
const { pgConnectionLoader, featureFlagsLoader } = await import("@medusajs/framework");
|
11
9
|
const pgConnection = pgConnectionLoader();
|
12
10
|
await featureFlagsLoader();
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
return pgConnection;
|
12
|
+
}
|
13
|
+
exports.initDb = initDb;
|
14
|
+
/**
|
15
|
+
* Migrates the database
|
16
|
+
*/
|
17
|
+
async function migrateDatabase(appLoader) {
|
18
|
+
try {
|
19
|
+
await appLoader.runModulesMigrations();
|
20
|
+
}
|
21
|
+
catch (err) {
|
22
|
+
console.error("Something went wrong while running the migrations");
|
23
|
+
throw err;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
exports.migrateDatabase = migrateDatabase;
|
27
|
+
/**
|
28
|
+
* Syncs links with the databse
|
29
|
+
*/
|
30
|
+
async function syncLinks(appLoader) {
|
16
31
|
try {
|
17
|
-
const
|
18
|
-
await medusaAppLoader.runModulesMigrations();
|
19
|
-
const planner = await medusaAppLoader.getLinksExecutionPlanner();
|
32
|
+
const planner = await appLoader.getLinksExecutionPlanner();
|
20
33
|
const actionPlan = await planner.createPlan();
|
34
|
+
actionPlan.forEach((action) => {
|
35
|
+
console.log(`Sync links: "${action.action}" ${action.tableName}`);
|
36
|
+
});
|
21
37
|
await planner.executePlan(actionPlan);
|
22
|
-
/**
|
23
|
-
* cleanup temporary created resources for the migrations
|
24
|
-
* @internal I didnt find a god place to put that, should we eventually add a close function
|
25
|
-
* to the planner to handle that part? so that you would do planner.close() and it will handle the cleanup
|
26
|
-
* automatically just like we usually do for the classic migrations actions
|
27
|
-
*/
|
28
|
-
const { MedusaModule } = require("@medusajs/modules-sdk");
|
29
|
-
MedusaModule.clearInstances();
|
30
38
|
}
|
31
39
|
catch (err) {
|
32
|
-
console.error("Something went wrong while
|
40
|
+
console.error("Something went wrong while syncing links");
|
33
41
|
throw err;
|
34
42
|
}
|
35
|
-
return pgConnection;
|
36
43
|
}
|
37
|
-
exports.
|
44
|
+
exports.syncLinks = syncLinks;
|
38
45
|
//# 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":";;;
|
1
|
+
{"version":3,"file":"use-db.js","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/use-db.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACI,KAAK,UAAU,MAAM;IAC1B,MAAM,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAC7D,qBAAqB,CACtB,CAAA;IAED,MAAM,YAAY,GAAG,kBAAkB,EAAE,CAAA;IACzC,MAAM,kBAAkB,EAAE,CAAA;IAE1B,OAAO,YAAY,CAAA;AACrB,CAAC;AATD,wBASC;AAED;;GAEG;AACI,KAAK,UAAU,eAAe,CAAC,SAA0B;IAC9D,IAAI,CAAC;QACH,MAAM,SAAS,CAAC,oBAAoB,EAAE,CAAA;IACxC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAA;QAClE,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC;AAPD,0CAOC;AAED;;GAEG;AACI,KAAK,UAAU,SAAS,CAAC,SAA0B;IACxD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,wBAAwB,EAAE,CAAA;QAC1D,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,UAAU,EAAE,CAAA;QAC7C,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAC5B,OAAO,CAAC,GAAG,CAAC,gBAAgB,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC,CAAA;QACnE,CAAC,CAAC,CAAA;QACF,MAAM,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAAA;IACvC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAA;QACzD,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC;AAZD,8BAYC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/utils.ts"],"names":[],"mappings":"AAGA,wBAAgB,qBAAqB,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,QAI3D"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.applyEnvVarsToProcess = void 0;
|
4
|
+
const utils_1 = require("@medusajs/utils");
|
5
|
+
function applyEnvVarsToProcess(env) {
|
6
|
+
if ((0, utils_1.isObject)(env)) {
|
7
|
+
Object.entries(env).forEach(([k, v]) => (process.env[k] = v));
|
8
|
+
}
|
9
|
+
}
|
10
|
+
exports.applyEnvVarsToProcess = applyEnvVarsToProcess;
|
11
|
+
//# sourceMappingURL=utils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/medusa-test-runner-utils/utils.ts"],"names":[],"mappings":";;;AACA,2CAAqE;AAErE,SAAgB,qBAAqB,CAAC,GAAsB;IAC1D,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;AACH,CAAC;AAJD,sDAIC"}
|
@@ -16,12 +16,13 @@ export interface MedusaSuiteOptions<TService = unknown> {
|
|
16
16
|
clientUrl: string;
|
17
17
|
};
|
18
18
|
}
|
19
|
-
export declare function medusaIntegrationTestRunner({ moduleName, dbName, schema, env, debug, testSuite, }: {
|
19
|
+
export declare function medusaIntegrationTestRunner({ moduleName, dbName, schema, env, debug, inApp, testSuite, }: {
|
20
20
|
moduleName?: string;
|
21
21
|
env?: Record<string, any>;
|
22
22
|
dbName?: string;
|
23
23
|
schema?: string;
|
24
24
|
debug?: boolean;
|
25
|
+
inApp?: boolean;
|
25
26
|
testSuite: <TService = unknown>(options: MedusaSuiteOptions<TService>) => void;
|
26
27
|
}): void;
|
27
28
|
//# sourceMappingURL=medusa-test-runner.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"medusa-test-runner.d.ts","sourceRoot":"","sources":["../src/medusa-test-runner.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"medusa-test-runner.d.ts","sourceRoot":"","sources":["../src/medusa-test-runner.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAqEhE,MAAM,WAAW,kBAAkB,CAAC,QAAQ,GAAG,OAAO;IACpD,YAAY,EAAE,GAAG,CAAA;IACjB,YAAY,EAAE,MAAM,eAAe,CAAA;IACnC,GAAG,EAAE,GAAG,CAAA;IACR,OAAO,EAAE;QACP,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;QACzC,QAAQ,EAAE,CAAC,OAAO,EAAE;YAAE,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;QACzD,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAC5C,CAAA;IACD,QAAQ,EAAE;QACR,MAAM,EAAE,MAAM,CAAA;QACd,MAAM,EAAE,MAAM,CAAA;QACd,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF;AAED,wBAAgB,2BAA2B,CAAC,EAC1C,UAAU,EACV,MAAM,EACN,MAAiB,EACjB,GAAQ,EACR,KAAa,EACb,KAAa,EACb,SAAS,GACV,EAAE;IACD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,SAAS,EAAE,CAAC,QAAQ,GAAG,OAAO,EAAE,OAAO,EAAE,kBAAkB,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAA;CAC/E,QAkKA"}
|
@@ -1,12 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.medusaIntegrationTestRunner = void 0;
|
4
|
+
const awilix_1 = require("awilix");
|
4
5
|
const utils_1 = require("@medusajs/utils");
|
5
6
|
const pg_god_1 = require("pg-god");
|
6
7
|
const database_1 = require("./database");
|
7
8
|
const bootstrap_app_1 = require("./medusa-test-runner-utils/bootstrap-app");
|
8
9
|
const use_db_1 = require("./medusa-test-runner-utils/use-db");
|
9
10
|
const config_1 = require("./medusa-test-runner-utils/config");
|
11
|
+
const utils_2 = require("./medusa-test-runner-utils/utils");
|
12
|
+
const clear_instances_1 = require("./medusa-test-runner-utils/clear-instances");
|
10
13
|
const axios = require("axios").default;
|
11
14
|
const DB_HOST = process.env.DB_HOST;
|
12
15
|
const DB_USERNAME = process.env.DB_USERNAME;
|
@@ -43,7 +46,7 @@ const dbTestUtilFactory = () => ({
|
|
43
46
|
return await (0, pg_god_1.dropDatabase)({ databaseName: dbName, errorIfNonExist: false }, pgGodCredentials);
|
44
47
|
},
|
45
48
|
});
|
46
|
-
function medusaIntegrationTestRunner({ moduleName, dbName, schema = "public", env = {}, debug = false, testSuite, }) {
|
49
|
+
function medusaIntegrationTestRunner({ moduleName, dbName, schema = "public", env = {}, debug = false, inApp = false, testSuite, }) {
|
47
50
|
const tempName = parseInt(process.env.JEST_WORKER_ID || "1");
|
48
51
|
moduleName = moduleName ?? Math.random().toString(36).substring(7);
|
49
52
|
dbName ??= `medusa-${moduleName.toLowerCase()}-integration-${tempName}`;
|
@@ -56,7 +59,7 @@ function medusaIntegrationTestRunner({ moduleName, dbName, schema = "public", en
|
|
56
59
|
const cwd = process.cwd();
|
57
60
|
let shutdown = async () => void 0;
|
58
61
|
const dbUtils = dbTestUtilFactory();
|
59
|
-
let
|
62
|
+
let globalContainer;
|
60
63
|
let apiUtils;
|
61
64
|
let options = {
|
62
65
|
api: new Proxy({}, {
|
@@ -69,7 +72,7 @@ function medusaIntegrationTestRunner({ moduleName, dbName, schema = "public", en
|
|
69
72
|
return dbUtils.pgConnection_[prop];
|
70
73
|
},
|
71
74
|
}),
|
72
|
-
getContainer: () =>
|
75
|
+
getContainer: () => globalContainer,
|
73
76
|
dbConfig: {
|
74
77
|
dbName,
|
75
78
|
schema,
|
@@ -80,26 +83,34 @@ function medusaIntegrationTestRunner({ moduleName, dbName, schema = "public", en
|
|
80
83
|
let isFirstTime = true;
|
81
84
|
const beforeAll_ = async () => {
|
82
85
|
await (0, config_1.configLoaderOverride)(cwd, dbConfig);
|
83
|
-
|
84
|
-
await
|
86
|
+
(0, utils_2.applyEnvVarsToProcess)(env);
|
87
|
+
const { logger, container, MedusaAppLoader } = await import("@medusajs/framework");
|
88
|
+
const appLoader = new MedusaAppLoader();
|
89
|
+
container.register({
|
90
|
+
[utils_1.ContainerRegistrationKeys.LOGGER]: (0, awilix_1.asValue)(logger),
|
91
|
+
});
|
85
92
|
try {
|
86
|
-
|
87
|
-
|
88
|
-
|
93
|
+
console.log(`Creating database ${dbName}`);
|
94
|
+
await dbUtils.create(dbName);
|
95
|
+
dbUtils.pgConnection_ = await (0, use_db_1.initDb)();
|
89
96
|
}
|
90
97
|
catch (error) {
|
91
98
|
console.error("Error initializing database", error?.message);
|
92
99
|
throw error;
|
93
100
|
}
|
94
|
-
|
101
|
+
console.log(`Migrating database with core migrations and links ${dbName}`);
|
102
|
+
await (0, use_db_1.migrateDatabase)(appLoader);
|
103
|
+
await (0, use_db_1.syncLinks)(appLoader);
|
104
|
+
await (0, clear_instances_1.clearInstances)();
|
105
|
+
let containerRes = container;
|
95
106
|
let serverShutdownRes;
|
96
107
|
let portRes;
|
97
108
|
try {
|
98
|
-
const { shutdown = () => void 0, container, port, } = await (0, bootstrap_app_1.startApp)({
|
109
|
+
const { shutdown = () => void 0, container: appContainer, port, } = await (0, bootstrap_app_1.startApp)({
|
99
110
|
cwd,
|
100
111
|
env,
|
101
112
|
});
|
102
|
-
containerRes =
|
113
|
+
containerRes = appContainer;
|
103
114
|
serverShutdownRes = shutdown;
|
104
115
|
portRes = port;
|
105
116
|
}
|
@@ -107,8 +118,17 @@ function medusaIntegrationTestRunner({ moduleName, dbName, schema = "public", en
|
|
107
118
|
console.error("Error starting the app", error?.message);
|
108
119
|
throw error;
|
109
120
|
}
|
121
|
+
/**
|
122
|
+
* Run application migrations and sync links when inside
|
123
|
+
* an application
|
124
|
+
*/
|
125
|
+
if (inApp) {
|
126
|
+
console.log(`Migrating database with core migrations and links ${dbName}`);
|
127
|
+
await (0, use_db_1.migrateDatabase)(appLoader);
|
128
|
+
await (0, use_db_1.syncLinks)(appLoader);
|
129
|
+
}
|
110
130
|
const cancelTokenSource = axios.CancelToken.source();
|
111
|
-
|
131
|
+
globalContainer = containerRes;
|
112
132
|
shutdown = async () => {
|
113
133
|
await serverShutdownRes();
|
114
134
|
cancelTokenSource.cancel("Request canceled by shutdown");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"medusa-test-runner.js","sourceRoot":"","sources":["../src/medusa-test-runner.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"medusa-test-runner.js","sourceRoot":"","sources":["../src/medusa-test-runner.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,2CAGwB;AACxB,mCAAqD;AACrD,yCAA2C;AAC3C,4EAAmE;AACnE,8DAI0C;AAC1C,8DAAwE;AACxE,4DAAwE;AACxE,gFAA2E;AAE3E,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAA;AAEtC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAA;AACnC,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;AAC3C,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;AAE3C,MAAM,gBAAgB,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE,WAAW;IACrB,IAAI,EAAE,OAAO;CACd,CAAA;AAED,MAAM,iBAAiB,GAAG,GAAQ,EAAE,CAAC,CAAC;IACpC,aAAa,EAAE,IAAI;IAEnB,MAAM,EAAE,KAAK,WAAW,MAAc;QACpC,MAAM,IAAA,uBAAc,EAAC,EAAE,YAAY,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QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;YAC7D,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC,CAAA;IAED,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;QAC5B,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;QACpC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,8BAA8B,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;AAlLD,kEAkLC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "medusa-test-utils",
|
3
|
-
"version": "1.1.45-snapshot-
|
3
|
+
"version": "1.1.45-snapshot-20240815071705",
|
4
4
|
"description": "Test utils for Medusa",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"repository": {
|
@@ -24,17 +24,18 @@
|
|
24
24
|
"author": "Medusa",
|
25
25
|
"license": "MIT",
|
26
26
|
"devDependencies": {
|
27
|
-
"@medusajs/framework": "0.0.2-snapshot-
|
28
|
-
"@medusajs/types": "1.12.0-snapshot-
|
29
|
-
"@medusajs/utils": "1.12.0-snapshot-
|
27
|
+
"@medusajs/framework": "0.0.2-snapshot-20240815071705",
|
28
|
+
"@medusajs/types": "1.12.0-snapshot-20240815071705",
|
29
|
+
"@medusajs/utils": "1.12.0-snapshot-20240815071705",
|
30
30
|
"cross-env": "^5.2.1",
|
31
31
|
"jest": "^29.7.0",
|
32
32
|
"rimraf": "^3.0.2",
|
33
33
|
"typescript": "^5.1.6"
|
34
34
|
},
|
35
35
|
"peerDependencies": {
|
36
|
-
"@medusajs/medusa": "1.20.6-snapshot-
|
37
|
-
"@medusajs/modules-sdk": "1.13.0-snapshot-
|
36
|
+
"@medusajs/medusa": "1.20.6-snapshot-20240815071705",
|
37
|
+
"@medusajs/modules-sdk": "1.13.0-snapshot-20240815071705",
|
38
|
+
"@mikro-orm/core": "5.9.7",
|
38
39
|
"axios": "^0.28.0",
|
39
40
|
"express": "^4.18.3",
|
40
41
|
"get-port": "^5.1.0",
|
@@ -58,7 +59,7 @@
|
|
58
59
|
}
|
59
60
|
},
|
60
61
|
"dependencies": {
|
61
|
-
"@medusajs/utils": "1.12.0-snapshot-
|
62
|
+
"@medusajs/utils": "1.12.0-snapshot-20240815071705",
|
62
63
|
"@mikro-orm/migrations": "5.9.7",
|
63
64
|
"@mikro-orm/postgresql": "5.9.7",
|
64
65
|
"randomatic": "^3.1.1"
|