chore(medusa-test-utils): Add custom link loading before syncing (#9249)
**What** Include custom links to be loaded from the medusa integration test runner
This commit is contained in:
1 parent
eb7899d05c
commit
e1fdc54a3f
2 files changed
+33
-5
No files matched your search
@@ -1,4 +1,7 @@
|
|||||||
import type { MedusaAppLoader } from "@medusajs/framework"
|
import type { MedusaAppLoader } from "@medusajs/framework"
|
||||||
|
import { join } from "path"
|
||||||
|
import { MedusaContainer } from "@medusajs/types"
|
||||||
|
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiates the database connection
|
* Initiates the database connection
|
||||||
@@ -29,8 +32,14 @@ export async function migrateDatabase(appLoader: MedusaAppLoader) {
|
|||||||
/**
|
/**
|
||||||
* Syncs links with the databse
|
* Syncs links with the databse
|
||||||
*/
|
*/
|
||||||
export async function syncLinks(appLoader: MedusaAppLoader) {
|
export async function syncLinks(
|
||||||
|
appLoader: MedusaAppLoader,
|
||||||
|
directory: string,
|
||||||
|
container: MedusaContainer
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
|
await loadCustomLinks(directory, container)
|
||||||
|
|
||||||
const planner = await appLoader.getLinksExecutionPlanner()
|
const planner = await appLoader.getLinksExecutionPlanner()
|
||||||
const actionPlan = await planner.createPlan()
|
const actionPlan = await planner.createPlan()
|
||||||
actionPlan.forEach((action) => {
|
actionPlan.forEach((action) => {
|
||||||
@@ -42,3 +51,22 @@ export async function syncLinks(appLoader: MedusaAppLoader) {
|
|||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadCustomLinks(directory: string, container: MedusaContainer) {
|
||||||
|
// TODO: move to framework once settle down
|
||||||
|
const { getResolvedPlugins } = await import(
|
||||||
|
// @ts-expect-error
|
||||||
|
"@medusajs/medusa/dist/loaders/helpers/resolve-plugins"
|
||||||
|
)
|
||||||
|
|
||||||
|
const configModule = container.resolve(
|
||||||
|
ContainerRegistrationKeys.CONFIG_MODULE
|
||||||
|
)
|
||||||
|
const plugins = getResolvedPlugins(directory, configModule, true) || []
|
||||||
|
const linksSourcePaths = plugins.map((plugin) =>
|
||||||
|
join(plugin.resolve, "links")
|
||||||
|
)
|
||||||
|
|
||||||
|
const { LinkLoader } = await import("@medusajs/framework")
|
||||||
|
await new LinkLoader(linksSourcePaths).load()
|
||||||
|
}
|
||||||
@@ -18,8 +18,8 @@ import {
|
|||||||
import { applyEnvVarsToProcess } from "./medusa-test-runner-utils/utils"
|
import { applyEnvVarsToProcess } from "./medusa-test-runner-utils/utils"
|
||||||
|
|
||||||
const DB_HOST = process.env.DB_HOST
|
const DB_HOST = process.env.DB_HOST
|
||||||
const DB_USERNAME = process.env.DB_USERNAME ?? ''
|
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||||
const DB_PASSWORD = process.env.DB_PASSWORD ?? ''
|
const DB_PASSWORD = process.env.DB_PASSWORD ?? ""
|
||||||
|
|
||||||
const pgGodCredentials = {
|
const pgGodCredentials = {
|
||||||
user: DB_USERNAME,
|
user: DB_USERNAME,
|
||||||
@@ -179,7 +179,7 @@ export function medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
console.log(`Migrating database with core migrations and links ${dbName}`)
|
console.log(`Migrating database with core migrations and links ${dbName}`)
|
||||||
await migrateDatabase(appLoader)
|
await migrateDatabase(appLoader)
|
||||||
await syncLinks(appLoader)
|
await syncLinks(appLoader, cwd, container)
|
||||||
await clearInstances()
|
await clearInstances()
|
||||||
|
|
||||||
let containerRes: MedusaContainer = container
|
let containerRes: MedusaContainer = container
|
||||||
@@ -215,7 +215,7 @@ export function medusaIntegrationTestRunner({
|
|||||||
if (inApp) {
|
if (inApp) {
|
||||||
console.log(`Migrating database with core migrations and links ${dbName}`)
|
console.log(`Migrating database with core migrations and links ${dbName}`)
|
||||||
await migrateDatabase(appLoader)
|
await migrateDatabase(appLoader)
|
||||||
await syncLinks(appLoader)
|
await syncLinks(appLoader, cwd, containerRes)
|
||||||
}
|
}
|
||||||
|
|
||||||
const axios = (await import("axios")).default.default
|
const axios = (await import("axios")).default.default
|
||||||
|
|||||||
Reference in new issue
Block a user