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:
Adrien de Peretti
2024-09-23 19:54:04 +00:00
committed by GitHub
parent eb7899d05c
commit e1fdc54a3f
2 changed files with 33 additions and 5 deletions
@@ -1,4 +1,7 @@
import type { MedusaAppLoader } from "@medusajs/framework"
import { join } from "path"
import { MedusaContainer } from "@medusajs/types"
import { ContainerRegistrationKeys } from "@medusajs/utils"
/**
* Initiates the database connection
@@ -29,8 +32,14 @@ export async function migrateDatabase(appLoader: MedusaAppLoader) {
/**
* Syncs links with the databse
*/
export async function syncLinks(appLoader: MedusaAppLoader) {
export async function syncLinks(
appLoader: MedusaAppLoader,
directory: string,
container: MedusaContainer
) {
try {
await loadCustomLinks(directory, container)
const planner = await appLoader.getLinksExecutionPlanner()
const actionPlan = await planner.createPlan()
actionPlan.forEach((action) => {
@@ -42,3 +51,22 @@ export async function syncLinks(appLoader: MedusaAppLoader) {
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"
const DB_HOST = process.env.DB_HOST
const DB_USERNAME = process.env.DB_USERNAME ?? ''
const DB_PASSWORD = process.env.DB_PASSWORD ?? ''
const DB_USERNAME = process.env.DB_USERNAME ?? ""
const DB_PASSWORD = process.env.DB_PASSWORD ?? ""
const pgGodCredentials = {
user: DB_USERNAME,
@@ -179,7 +179,7 @@ export function medusaIntegrationTestRunner({
console.log(`Migrating database with core migrations and links ${dbName}`)
await migrateDatabase(appLoader)
await syncLinks(appLoader)
await syncLinks(appLoader, cwd, container)
await clearInstances()
let containerRes: MedusaContainer = container
@@ -215,7 +215,7 @@ export function medusaIntegrationTestRunner({
if (inApp) {
console.log(`Migrating database with core migrations and links ${dbName}`)
await migrateDatabase(appLoader)
await syncLinks(appLoader)
await syncLinks(appLoader, cwd, containerRes)
}
const axios = (await import("axios")).default.default