fix: Use logger in the test runner and migration commands (#12406)
This commit is contained in:
1 parent
fe3e79ea5a
commit
f929185021
5 files changed
+18
-17
No files matched your search
@@ -28,8 +28,8 @@ export function buildRevertMigrationScript({ moduleName, pathToMigrations }) {
|
|||||||
> = {}) {
|
> = {}) {
|
||||||
logger ??= console as unknown as Logger
|
logger ??= console as unknown as Logger
|
||||||
|
|
||||||
console.log(new Array(TERMINAL_SIZE).join("-"))
|
logger.info(new Array(TERMINAL_SIZE).join("-"))
|
||||||
console.log("")
|
logger.info("")
|
||||||
logger.info(`MODULE: ${moduleName}`)
|
logger.info(`MODULE: ${moduleName}`)
|
||||||
|
|
||||||
const dbData = loadDatabaseConfig(moduleName, options)!
|
const dbData = loadDatabaseConfig(moduleName, options)!
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ export function buildGenerateMigrationScript({
|
|||||||
> = {}) {
|
> = {}) {
|
||||||
logger ??= console as unknown as Logger
|
logger ??= console as unknown as Logger
|
||||||
|
|
||||||
console.log(new Array(TERMINAL_SIZE).join("-"))
|
logger.info(new Array(TERMINAL_SIZE).join("-"))
|
||||||
console.log("")
|
logger.info("")
|
||||||
logger.info(`MODULE: ${moduleName}`)
|
logger.info(`MODULE: ${moduleName}`)
|
||||||
|
|
||||||
const dbData = loadDatabaseConfig(moduleName, options)!
|
const dbData = loadDatabaseConfig(moduleName, options)!
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ export function buildMigrationScript({ moduleName, pathToMigrations }) {
|
|||||||
> = {}) {
|
> = {}) {
|
||||||
logger ??= console as unknown as Logger
|
logger ??= console as unknown as Logger
|
||||||
|
|
||||||
console.log(new Array(TERMINAL_SIZE).join("-"))
|
logger.info(new Array(TERMINAL_SIZE).join("-"))
|
||||||
console.log("")
|
logger.info("")
|
||||||
logger.info(`MODULE: ${moduleName}`)
|
logger.info(`MODULE: ${moduleName}`)
|
||||||
|
|
||||||
const dbData = loadDatabaseConfig(moduleName, options)!
|
const dbData = loadDatabaseConfig(moduleName, options)!
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { MedusaAppLoader } from "@medusajs/framework"
|
import type { MedusaAppLoader } from "@medusajs/framework"
|
||||||
import { MedusaContainer } from "@medusajs/framework/types"
|
import { Logger, MedusaContainer } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
getResolvedPlugins,
|
getResolvedPlugins,
|
||||||
@@ -38,7 +38,8 @@ export async function migrateDatabase(appLoader: MedusaAppLoader) {
|
|||||||
export async function syncLinks(
|
export async function syncLinks(
|
||||||
appLoader: MedusaAppLoader,
|
appLoader: MedusaAppLoader,
|
||||||
directory: string,
|
directory: string,
|
||||||
container: MedusaContainer
|
container: MedusaContainer,
|
||||||
|
logger: Logger
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
await loadCustomLinks(directory, container)
|
await loadCustomLinks(directory, container)
|
||||||
@@ -46,11 +47,11 @@ export async function syncLinks(
|
|||||||
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) => {
|
||||||
console.log(`Sync links: "${action.action}" ${action.tableName}`)
|
logger.info(`Sync links: "${action.action}" ${action.tableName}`)
|
||||||
})
|
})
|
||||||
await planner.executePlan(actionPlan)
|
await planner.executePlan(actionPlan)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Something went wrong while syncing links")
|
logger.error("Something went wrong while syncing links")
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,17 +114,17 @@ export function medusaIntegrationTestRunner({
|
|||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(`Creating database ${dbName}`)
|
logger.info(`Creating database ${dbName}`)
|
||||||
await dbUtils.create(dbName)
|
await dbUtils.create(dbName)
|
||||||
dbUtils.pgConnection_ = await initDb()
|
dbUtils.pgConnection_ = await initDb()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error initializing database", error?.message)
|
logger.error(`Error initializing database: ${error?.message}`)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Migrating database with core migrations and links ${dbName}`)
|
logger.info(`Migrating database with core migrations and links ${dbName}`)
|
||||||
await migrateDatabase(appLoader)
|
await migrateDatabase(appLoader)
|
||||||
await syncLinks(appLoader, cwd, container)
|
await syncLinks(appLoader, cwd, container, logger)
|
||||||
await clearInstances()
|
await clearInstances()
|
||||||
|
|
||||||
let containerRes: MedusaContainer = container
|
let containerRes: MedusaContainer = container
|
||||||
@@ -147,7 +147,7 @@ export function medusaIntegrationTestRunner({
|
|||||||
serverShutdownRes = shutdown
|
serverShutdownRes = shutdown
|
||||||
portRes = port
|
portRes = port
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error starting the app", error?.message)
|
logger.error(`Error starting the app: error?.message`)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,9 +156,9 @@ export function medusaIntegrationTestRunner({
|
|||||||
* an application
|
* an application
|
||||||
*/
|
*/
|
||||||
if (inApp) {
|
if (inApp) {
|
||||||
console.log(`Migrating database with core migrations and links ${dbName}`)
|
logger.info(`Migrating database with core migrations and links ${dbName}`)
|
||||||
await migrateDatabase(appLoader)
|
await migrateDatabase(appLoader)
|
||||||
await syncLinks(appLoader, cwd, containerRes)
|
await syncLinks(appLoader, cwd, containerRes, logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { default: axios } = (await import("axios")) as any
|
const { default: axios } = (await import("axios")) as any
|
||||||
|
|||||||
Reference in new issue
Block a user