chore(framework): Initial commit (#8221)
**What** - Initiate the framework package (which is just a place to move things around for now) - move the config loader and related resources as well as the `ConfigModule` type - Create a ConfigManager singleton which prepare and store the config (later can be stored entirely in the container) and allow for easier test override - re export the logger from the framework - replace medusa config loader with the framework one - `build` run type check on tests as well but `prepublishOnly` will not fail on build if tests are typed broken FIXES FRMW-2607 FIXES FRMW-2609 FIXES FRMW-2614 FIXES FRMW-2618
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { getConfigFile } from "@medusajs/utils"
|
||||
|
||||
export async function configLoaderOverride(
|
||||
entryDirectory: string,
|
||||
override: { clientUrl: string; debug?: boolean }
|
||||
) {
|
||||
// in case it is not install as it is optional and required only when using this util
|
||||
// @ts-ignore
|
||||
const { configManager } = await import("@medusajs/framework/config")
|
||||
const { configModule, error } = getConfigFile<
|
||||
ReturnType<typeof configManager.loadConfig>
|
||||
>(entryDirectory, "medusa-config.js")
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message || "Error during config loading")
|
||||
}
|
||||
|
||||
configModule.projectConfig.databaseUrl = override.clientUrl
|
||||
configModule.projectConfig.databaseLogging = !!override.debug
|
||||
configModule.projectConfig.databaseDriverOptions =
|
||||
override.clientUrl.includes("localhost")
|
||||
? {}
|
||||
: {
|
||||
connection: {
|
||||
ssl: { rejectUnauthorized: false },
|
||||
},
|
||||
idle_in_transaction_session_timeout: 20000,
|
||||
}
|
||||
|
||||
configManager.loadConfig(configModule)
|
||||
}
|
||||
@@ -5,21 +5,17 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { asValue } from "awilix"
|
||||
|
||||
export async function initDb({
|
||||
cwd,
|
||||
env = {},
|
||||
}: {
|
||||
cwd: string
|
||||
env?: Record<any, any>
|
||||
}) {
|
||||
export async function initDb({ env = {} }: { env?: Record<any, any> }) {
|
||||
if (isObject(env)) {
|
||||
Object.entries(env).forEach(([k, v]) => (process.env[k] = v))
|
||||
}
|
||||
|
||||
const container = createMedusaContainer()
|
||||
|
||||
const configModule =
|
||||
await require("@medusajs/medusa/dist/loaders/config").default(cwd)
|
||||
// in case it is not install as it is optional and required only when using this util
|
||||
// @ts-ignore
|
||||
const { configManager } = await import("@medusajs/framework/config")
|
||||
const configModule = configManager.config
|
||||
|
||||
const pgConnection =
|
||||
await require("@medusajs/medusa/dist/loaders/pg-connection").default({
|
||||
|
||||
@@ -7,6 +7,7 @@ import { createDatabase, dropDatabase } from "pg-god"
|
||||
import { getDatabaseURL } from "./database"
|
||||
import { startApp } from "./medusa-test-runner-utils/bootstrap-app"
|
||||
import { initDb } from "./medusa-test-runner-utils/use-db"
|
||||
import { configLoaderOverride } from "./medusa-test-runner-utils/config"
|
||||
|
||||
const axios = require("axios").default
|
||||
|
||||
@@ -102,27 +103,6 @@ export function medusaIntegrationTestRunner({
|
||||
debug,
|
||||
}
|
||||
|
||||
const originalConfigLoader =
|
||||
require("@medusajs/medusa/dist/loaders/config").default
|
||||
require("@medusajs/medusa/dist/loaders/config").default = (
|
||||
rootDirectory: string
|
||||
) => {
|
||||
const config = originalConfigLoader(rootDirectory)
|
||||
config.projectConfig.databaseUrl = dbConfig.clientUrl
|
||||
config.projectConfig.databaseLogging = !!dbConfig.debug
|
||||
config.projectConfig.databaseDriverOptions = dbConfig.clientUrl.includes(
|
||||
"localhost"
|
||||
)
|
||||
? {}
|
||||
: {
|
||||
connection: {
|
||||
ssl: { rejectUnauthorized: false },
|
||||
},
|
||||
idle_in_transaction_session_timeout: 20000,
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
const cwd = process.cwd()
|
||||
|
||||
let shutdown = async () => void 0
|
||||
@@ -159,12 +139,13 @@ export function medusaIntegrationTestRunner({
|
||||
let isFirstTime = true
|
||||
|
||||
const beforeAll_ = async () => {
|
||||
await configLoaderOverride(cwd, dbConfig)
|
||||
|
||||
console.log(`Creating database ${dbName}`)
|
||||
await dbUtils.create(dbName)
|
||||
|
||||
try {
|
||||
dbUtils.pgConnection_ = await initDb({
|
||||
cwd,
|
||||
env,
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user