chore(): Remove default limit from the build query (#9257)
* chore(): Remove default limit from the build query * rm take: null * fix tests * fix tests * fix db usage * fix typo * rm unsused template arg * fixes * fixes * fixes * fixes * fixes * fixes * fixes
This commit is contained in:
@@ -1,4 +1,15 @@
|
||||
import { MikroORM, Options, SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD ?? ""
|
||||
|
||||
const pgGodCredentials = {
|
||||
user: DB_USERNAME,
|
||||
password: DB_PASSWORD,
|
||||
host: DB_HOST,
|
||||
}
|
||||
|
||||
export function getDatabaseURL(dbName?: string): string {
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||
@@ -158,3 +169,46 @@ export function getMikroOrmWrapper({
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export const dbTestUtilFactory = (): any => ({
|
||||
pgConnection_: null,
|
||||
|
||||
create: async function (dbName: string) {
|
||||
await createDatabase(
|
||||
{ databaseName: dbName, errorIfExist: false },
|
||||
pgGodCredentials
|
||||
)
|
||||
},
|
||||
|
||||
teardown: async function ({ schema }: { schema?: string } = {}) {
|
||||
if (!this.pgConnection_) {
|
||||
return
|
||||
}
|
||||
|
||||
const runRawQuery = this.pgConnection_.raw.bind(this.pgConnection_)
|
||||
|
||||
schema ??= "public"
|
||||
|
||||
await runRawQuery(`SET session_replication_role = 'replica';`)
|
||||
const { rows: tableNames } = await runRawQuery(`SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = '${schema}';`)
|
||||
|
||||
for (const { table_name } of tableNames) {
|
||||
await runRawQuery(`DELETE
|
||||
FROM ${schema}."${table_name}";`)
|
||||
}
|
||||
|
||||
await runRawQuery(`SET session_replication_role = 'origin';`)
|
||||
},
|
||||
|
||||
shutdown: async function (dbName: string) {
|
||||
await this.pgConnection_?.context?.destroy()
|
||||
await this.pgConnection_?.destroy()
|
||||
|
||||
return await dropDatabase(
|
||||
{ databaseName: dbName, errorIfNonExist: false },
|
||||
pgGodCredentials
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -4,5 +4,6 @@ export { default as IdMap } from "./id-map"
|
||||
export * from "./init-modules"
|
||||
export * as JestUtils from "./jest"
|
||||
export * from "./medusa-test-runner"
|
||||
export * from "./medusa-test-runner-utils/"
|
||||
export { default as MockEventBusService } from "./mock-event-bus-service"
|
||||
export * from "./module-test-runner"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export * from "./bootstrap-app"
|
||||
export * from "./clear-instances"
|
||||
export * from "./config"
|
||||
export * from "./use-db"
|
||||
export * from "./utils"
|
||||
@@ -5,8 +5,7 @@ import {
|
||||
createMedusaContainer,
|
||||
} from "@medusajs/utils"
|
||||
import { asValue } from "awilix"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
import { getDatabaseURL } from "./database"
|
||||
import { dbTestUtilFactory, getDatabaseURL } from "./database"
|
||||
import { startApp } from "./medusa-test-runner-utils/bootstrap-app"
|
||||
import { clearInstances } from "./medusa-test-runner-utils/clear-instances"
|
||||
import { configLoaderOverride } from "./medusa-test-runner-utils/config"
|
||||
@@ -17,60 +16,7 @@ import {
|
||||
} from "./medusa-test-runner-utils/use-db"
|
||||
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 pgGodCredentials = {
|
||||
user: DB_USERNAME,
|
||||
password: DB_PASSWORD,
|
||||
host: DB_HOST,
|
||||
}
|
||||
|
||||
export const dbTestUtilFactory = (): any => ({
|
||||
pgConnection_: null,
|
||||
|
||||
create: async function (dbName: string) {
|
||||
await createDatabase(
|
||||
{ databaseName: dbName, errorIfExist: false },
|
||||
pgGodCredentials
|
||||
)
|
||||
},
|
||||
|
||||
teardown: async function ({ schema }: { schema?: string } = {}) {
|
||||
if (!this.pgConnection_) {
|
||||
return
|
||||
}
|
||||
|
||||
const runRawQuery = this.pgConnection_.raw.bind(this.pgConnection_)
|
||||
|
||||
schema ??= "public"
|
||||
|
||||
await runRawQuery(`SET session_replication_role = 'replica';`)
|
||||
const { rows: tableNames } = await runRawQuery(`SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = '${schema}';`)
|
||||
|
||||
for (const { table_name } of tableNames) {
|
||||
await runRawQuery(`DELETE
|
||||
FROM ${schema}."${table_name}";`)
|
||||
}
|
||||
|
||||
await runRawQuery(`SET session_replication_role = 'origin';`)
|
||||
},
|
||||
|
||||
shutdown: async function (dbName: string) {
|
||||
await this.pgConnection_?.context?.destroy()
|
||||
await this.pgConnection_?.destroy()
|
||||
|
||||
return await dropDatabase(
|
||||
{ databaseName: dbName, errorIfNonExist: false },
|
||||
pgGodCredentials
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
export interface MedusaSuiteOptions<TService = unknown> {
|
||||
export interface MedusaSuiteOptions {
|
||||
dbConnection: any // knex instance
|
||||
getContainer: () => MedusaContainer
|
||||
api: any
|
||||
@@ -106,7 +52,7 @@ export function medusaIntegrationTestRunner({
|
||||
schema?: string
|
||||
debug?: boolean
|
||||
inApp?: boolean
|
||||
testSuite: <TService = unknown>(options: MedusaSuiteOptions<TService>) => void
|
||||
testSuite: (options: MedusaSuiteOptions) => void
|
||||
}) {
|
||||
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
||||
moduleName = moduleName ?? Math.random().toString(36).substring(7)
|
||||
|
||||
Reference in New Issue
Block a user