fix(integration): setup (#5511)

* fix(integration): setup
This commit is contained in:
Adrien de Peretti
2023-11-01 18:56:12 +01:00
committed by GitHub
parent 4692f54b49
commit 80fe362f33
45 changed files with 461 additions and 405 deletions

View File

@@ -0,0 +1,6 @@
---
"@medusajs/cache-redis": major
"@medusajs/cache-inmemory": patch
---
Integration tests fixes and ignore ttl 0 on cache modules

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"private": true,
"scripts": {
"test:integration": "jest --silent=false --maxWorkers=50% --bail --detectOpenHandles --forceExit",
"test:integration": "jest --silent=false --maxWorkers=50% --bail --detectOpenHandles --forceExit --logHeapUsage",
"build": "babel src -d dist --extensions \".ts,.js\""
},
"dependencies": {

View File

@@ -2,30 +2,78 @@ const path = require("path")
const express = require("express")
const getPort = require("get-port")
const { isObject } = require("@medusajs/utils")
const { setContainer } = require("./use-container")
const { setPort, setExpressServer } = require("./use-api")
async function bootstrapApp({ cwd, env = {} } = {}) {
const app = express()
if (isObject(env)) {
Object.entries(env).forEach(([k, v]) => (process.env[k] = v))
}
const loaders = require("@medusajs/medusa/dist/loaders").default
const { container, dbConnection, pgConnection } = await loaders({
directory: path.resolve(cwd || process.cwd()),
expressApp: app,
isTest: false,
})
const PORT = await getPort()
return {
container,
db: dbConnection,
pgConnection,
app,
port: PORT,
}
}
module.exports = {
bootstrapApp: async ({ cwd, env = {} } = {}) => {
const app = express()
if (isObject(env)) {
Object.entries(env).forEach(([k, v]) => (process.env[k] = v))
}
const loaders = require("@medusajs/medusa/dist/loaders").default
const { container, dbConnection } = await loaders({
directory: path.resolve(cwd || process.cwd()),
expressApp: app,
isTest: false,
bootstrapApp,
startBootstrapApp: async ({
cwd,
env = {},
skipExpressListen = false,
} = {}) => {
const { app, port, container, db, pgConnection } = await bootstrapApp({
cwd,
env,
})
let expressServer
const PORT = await getPort()
setContainer(container)
return {
container,
db: dbConnection,
app,
port: PORT,
if (skipExpressListen) {
return
}
const shutdown = async () => {
await Promise.all([
expressServer.close(),
db?.destroy(),
pgConnection?.context?.destroy(),
])
if (typeof global !== "undefined" && global?.gc) {
global.gc()
}
}
return await new Promise((resolve, reject) => {
expressServer = app.listen(port, async (err) => {
if (err) {
await shutdown()
return reject(err)
}
setPort(port)
process.send(port)
resolve(shutdown)
})
setExpressServer(expressServer)
})
},
}

View File

@@ -3,20 +3,9 @@ const { spawn } = require("child_process")
const { setPort, useExpressServer } = require("./use-api")
const { setContainer } = require("./use-container")
module.exports = ({
cwd,
redisUrl,
uploadDir,
verbose,
env,
bootstrapApp = false,
}) => {
module.exports = async ({ cwd, redisUrl, uploadDir, verbose, env }) => {
const serverPath = path.join(__dirname, "test-server.js")
if (bootstrapApp) {
require(serverPath)
}
// in order to prevent conflicts in redis, use a different db for each worker
// same fix as for databases (works with up to 15)
// redis dbs are 0-indexed and jest worker ids are indexed from 1
@@ -25,7 +14,7 @@ module.exports = ({
verbose = verbose ?? false
return new Promise((resolve, reject) => {
return await new Promise((resolve, reject) => {
const medusaProcess = spawn("node", [path.resolve(serverPath)], {
cwd,
env: {
@@ -44,11 +33,13 @@ module.exports = ({
medusaProcess.on("error", (err) => {
console.log(err)
reject(err)
process.exit()
})
medusaProcess.on("uncaughtException", (err) => {
console.log(err)
reject(err)
medusaProcess.kill()
})

View File

@@ -1,18 +1,3 @@
const { bootstrapApp } = require("./bootstrap-app")
const { setContainer } = require("./use-container")
const { setPort, setExpressServer } = require("./use-api")
const { startBootstrapApp } = require("./bootstrap-app")
const setup = async () => {
const { app, port, container } = await bootstrapApp()
setContainer(container)
const expressServer = app.listen(port, (err) => {
setPort(port)
process.send(port)
})
setExpressServer(expressServer)
}
setup()
startBootstrapApp()

View File

@@ -1,8 +1,3 @@
const path = require("path")
const express = require("express")
const getPort = require("get-port")
const { isObject } = require("@medusajs/utils")
const AppUtils = {
container_: null,

View File

@@ -1,11 +1,11 @@
const path = require("path")
const { getConfigFile } = require("medusa-core-utils")
const { asValue } = require("awilix")
const { isObject, createMedusaContainer } = require("@medusajs/utils")
const { dropDatabase } = require("pg-god")
const { DataSource } = require("typeorm")
const dbFactory = require("./use-template-db")
const { getContainer } = require("./use-container")
const { ContainerRegistrationKeys } = require("@medusajs/utils")
const DB_HOST = process.env.DB_HOST
@@ -69,10 +69,10 @@ const DbTestUtil = {
},
shutdown: async function () {
await this.db_.destroy()
await this.db_?.destroy()
await this.pgConnection_?.context?.destroy()
return await dropDatabase({ DB_NAME }, pgGodCredentials)
return await dropDatabase({ databaseName: DB_NAME }, pgGodCredentials)
},
}
@@ -157,6 +157,12 @@ module.exports = {
const container = createMedusaContainer()
container.register({
[ContainerRegistrationKeys.CONFIG_MODULE]: asValue(configModule),
[ContainerRegistrationKeys.LOGGER]: asValue(console),
[ContainerRegistrationKeys.MANAGER]: asValue(dbDataSource.manager),
})
const pgConnection = await pgConnectionLoader({ configModule, container })
instance.setPgConnection(pgConnection)
@@ -168,6 +174,7 @@ module.exports = {
const options = {
database: {
clientUrl: DB_URL,
connection: pgConnection,
},
}
await runMigrations(options)

View File

@@ -21,14 +21,13 @@ const pgGodCredentials = {
class DatabaseFactory {
constructor() {
this.dataSource_ = null
this.masterDataSourceName = "master"
this.templateDbName = "medusa-integration-template"
}
async createTemplateDb_({ cwd }) {
const { configModule } = getConfigFile(cwd, `medusa-config`)
const dataSource = await this.getMasterDataSource()
const migrationDir = path.resolve(
path.join(
__dirname,
@@ -80,8 +79,6 @@ class DatabaseFactory {
await templateDbDataSource.runMigrations()
await templateDbDataSource.destroy()
return dataSource
}
async getMasterDataSource() {
@@ -103,7 +100,7 @@ class DatabaseFactory {
async createFromTemplate(dbName) {
const dataSource = await this.getMasterDataSource()
await dataSource.query(`DROP DATABASE IF EXISTS "${dbName}";`)
await dropDatabase({ databaseName: dbName }, pgGodCredentials)
await dataSource.query(
`CREATE DATABASE "${dbName}" TEMPLATE "${this.templateDbName}";`
)

View File

@@ -1,5 +1,24 @@
const dbFactory = require("./environment-helpers/use-template-db")
const { dropDatabase } = require("pg-god")
module.exports = async () => {
await dbFactory.destroy()
const DB_HOST = process.env.DB_HOST
const DB_USERNAME = process.env.DB_USERNAME
const DB_PASSWORD = process.env.DB_PASSWORD
const DB_NAME = process.env.DB_TEMP_NAME
const pgGodCredentials = {
user: DB_USERNAME,
password: DB_PASSWORD,
host: DB_HOST,
}
const teardown = async () => {
try {
await dropDatabase({ databaseName: DB_NAME }, pgGodCredentials)
} catch (e) {
console.error(
`This might fail if it is run during the unit tests since there is no database to drop. Otherwise, please check what is the issue. ${e.message}`
)
}
}
module.exports = teardown

View File

@@ -1,19 +1,20 @@
import { MoneyAmount, PriceList, Region } from "@medusajs/medusa"
import {
MoneyAmount,
PriceList,
ProductVariantMoneyAmount,
Region,
} from "@medusajs/medusa"
import path from "path"
import { ProductVariantMoneyAmount } from "@medusajs/medusa"
import { bootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import setupServer from "../../../../environment-helpers/setup-server"
import { setPort, useApi } from "../../../../environment-helpers/use-api"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { simpleProductFactory } from "../../../../factories"
jest.setTimeout(30000)
describe("/store/carts", () => {
let medusaProcess
let dbConnection
let express
let shutdownServer
const doAfterEach = async () => {
const db = useDb()
@@ -23,18 +24,13 @@ describe("/store/carts", () => {
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
medusaProcess = await setupServer({ cwd })
const { app, port } = await bootstrapApp({ cwd })
setPort(port)
express = app.listen(port, () => {
process.send?.(port)
})
shutdownServer = await startBootstrapApp({ cwd })
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
medusaProcess.kill()
await shutdownServer()
})
describe("POST /store/carts", () => {

View File

@@ -1,22 +1,28 @@
const path = require("path")
const {
bootstrapApp,
startBootstrapApp,
} = require("../../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../../environment-helpers/use-api")
const adminSeeder = require("../../../../helpers/admin-seeder")
const cartSeeder = require("../../../../helpers/cart-seeder")
const { simpleProductFactory } = require("../../../../factories")
const { simpleSalesChannelFactory } = require("../../../../factories")
const {
getContainer,
} = require("../../../../environment-helpers/use-container")
jest.setTimeout(30000)
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
describe("/store/carts", () => {
let express
let shutdownServer
let appContainer
let dbConnection
@@ -32,19 +38,14 @@ describe("/store/carts", () => {
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -2,51 +2,37 @@ const path = require("path")
const { ProductVariantInventoryService } = require("@medusajs/medusa")
const {
bootstrapApp,
startBootstrapApp,
} = require("../../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../../environment-helpers/use-api")
const adminSeeder = require("../../../../helpers/admin-seeder")
jest.setTimeout(30000)
const {
simpleProductFactory,
simpleOrderFactory,
} = require("../../../../factories")
getContainer,
} = require("../../../../environment-helpers/use-container")
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
describe("Inventory Items endpoints", () => {
let appContainer
let dbConnection
let express
let variantId
let inventoryItems
let locationId
let location2Id
let location3Id
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
// Set feature flag
const flagRouter = appContainer.resolve("featureFlagRouter")
flagRouter.setFlag("many_to_many_inventory", true)
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
})
beforeEach(async () => {
await adminSeeder(dbConnection)
})
afterAll(async () => {
@@ -55,7 +41,11 @@ describe("Inventory Items endpoints", () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
beforeEach(async () => {
await adminSeeder(dbConnection)
})
afterEach(async () => {

View File

@@ -1,10 +1,13 @@
const path = require("path")
const {
bootstrapApp,
startBootstrapApp,
} = require("../../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../../environment-helpers/use-api")
const adminSeeder = require("../../../../helpers/admin-seeder")
@@ -14,12 +17,15 @@ const {
simpleProductFactory,
simpleOrderFactory,
} = require("../../../../factories")
const {
getContainer,
} = require("../../../../environment-helpers/use-container")
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
describe("Inventory Items endpoints", () => {
let appContainer
let dbConnection
let express
let shutdownServer
let variantId
let inventoryItems
@@ -30,13 +36,14 @@ describe("Inventory Items endpoints", () => {
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {
@@ -122,7 +129,7 @@ describe("Inventory Items endpoints", () => {
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,10 +1,13 @@
const path = require("path")
const {
bootstrapApp,
startBootstrapApp,
} = require("../../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../../environment-helpers/use-api")
const adminSeeder = require("../../../../helpers/admin-seeder")
const {
@@ -18,31 +21,30 @@ const {
const {
simpleAddressFactory,
} = require("../../../../factories/simple-address-factory")
const {
getContainer,
} = require("../../../../environment-helpers/use-container")
jest.setTimeout(30000)
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
describe("/store/carts", () => {
let express
let shutdownServer
let appContainer
let dbConnection
const doAfterEach = async () => {
const db = useDb()
return await db.teardown()
}
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {})
@@ -51,7 +53,6 @@ describe("/store/carts", () => {
const variantId = "test-variant"
let region
let order
let invItemId
let prodVarInventoryService
let inventoryService

View File

@@ -1,10 +1,14 @@
const path = require("path")
const {
bootstrapApp,
startBootstrapApp,
} = require("../../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../../environment-helpers/use-api")
const {
setPort,
useApi,
useExpressServer,
} = require("../../../../environment-helpers/use-api")
const adminSeeder = require("../../../../helpers/admin-seeder")
const {
@@ -17,32 +21,30 @@ const {
simpleCartFactory,
simpleShippingOptionFactory,
} = require("../../../../factories")
const {
getContainer,
} = require("../../../../environment-helpers/use-container")
jest.setTimeout(150000)
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
describe("/store/carts", () => {
let express
let shutdownServer
let appContainer
let dbConnection
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,10 +1,13 @@
const path = require("path")
const {
bootstrapApp,
startBootstrapApp,
} = require("../../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../../environment-helpers/use-api")
const {
ProductVariantInventoryService,
@@ -16,28 +19,26 @@ const adminSeeder = require("../../../../helpers/admin-seeder")
jest.setTimeout(30000)
const { simpleProductFactory } = require("../../../../factories")
const {
getContainer,
} = require("../../../../environment-helpers/use-container")
describe("Create Variant", () => {
let appContainer
let dbConnection
let express
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,38 +1,39 @@
const path = require("path")
const {
bootstrapApp,
startBootstrapApp,
} = require("../../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../../environment-helpers/use-api")
const adminSeeder = require("../../../../helpers/admin-seeder")
jest.setTimeout(30000)
const { simpleProductFactory } = require("../../../../factories")
const {
getContainer,
} = require("../../../../environment-helpers/use-container")
describe("Delete Variant", () => {
let appContainer
let dbConnection
let express
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,10 +1,13 @@
const path = require("path")
const {
bootstrapApp,
startBootstrapApp,
} = require("../../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../../environment-helpers/use-api")
const adminSeeder = require("../../../../helpers/admin-seeder")
@@ -14,13 +17,16 @@ const {
simpleProductFactory,
simpleSalesChannelFactory,
} = require("../../../../factories")
const {
getContainer,
} = require("../../../../environment-helpers/use-container")
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
describe("Get products", () => {
let appContainer
let dbConnection
let express
let shutdownServer
const productId = "test-product"
const variantId = "test-variant"
let invItem
@@ -28,19 +34,14 @@ describe("Get products", () => {
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,10 +1,13 @@
const path = require("path")
const {
bootstrapApp,
startBootstrapApp,
} = require("../../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../../environment-helpers/use-api")
const adminSeeder = require("../../../../helpers/admin-seeder")
@@ -14,13 +17,16 @@ const {
simpleProductFactory,
simpleSalesChannelFactory,
} = require("../../../../factories")
const {
getContainer,
} = require("../../../../environment-helpers/use-container")
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
describe("Get variant", () => {
let appContainer
let dbConnection
let express
let shutdownServer
const productId = "test-product"
const variantId = "test-variant"
let invItem
@@ -32,19 +38,14 @@ describe("Get variant", () => {
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,10 +1,13 @@
const path = require("path")
const {
bootstrapApp,
startBootstrapApp,
} = require("../../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../../environment-helpers/use-api")
const adminSeeder = require("../../../../helpers/admin-seeder")
@@ -12,30 +15,28 @@ jest.setTimeout(30000)
const { simpleProductFactory } = require("../../../../factories")
const { simpleSalesChannelFactory } = require("../../../../factories")
const {
getContainer,
} = require("../../../../environment-helpers/use-container")
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
describe("Create Variant", () => {
let appContainer
let dbConnection
let express
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,10 +1,13 @@
const path = require("path")
const {
bootstrapApp,
startBootstrapApp,
} = require("../../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../../environment-helpers/use-api")
const adminSeeder = require("../../../../helpers/admin-seeder")
@@ -12,29 +15,27 @@ jest.setTimeout(30000)
const { simpleProductFactory } = require("../../../../factories")
const { simpleSalesChannelFactory } = require("../../../../factories")
const {
getContainer,
} = require("../../../../environment-helpers/use-container")
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
describe("List Variants", () => {
let appContainer
let dbConnection
let express
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,10 +1,13 @@
const path = require("path")
const {
bootstrapApp,
startBootstrapApp,
} = require("../../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../../environment-helpers/use-api")
const adminSeeder = require("../../../../helpers/admin-seeder")
@@ -16,12 +19,15 @@ const {
simpleRegionFactory,
} = require("../../../../factories")
const { simpleSalesChannelFactory } = require("../../../../factories")
const {
getContainer,
} = require("../../../../environment-helpers/use-container")
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
describe("Inventory Items endpoints", () => {
let appContainer
let dbConnection
let express
let shutdownServer
let inventoryItem
let locationId
@@ -41,13 +47,14 @@ describe("Inventory Items endpoints", () => {
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {
@@ -138,12 +145,6 @@ describe("Inventory Items endpoints", () => {
})
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
})
afterEach(async () => {
jest.clearAllMocks()
const db = useDb()

View File

@@ -1,30 +1,30 @@
const path = require("path")
const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app")
const {
startBootstrapApp,
} = require("../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../environment-helpers/use-db")
const { getContainer } = require("../../../environment-helpers/use-container")
const { useExpressServer } = require("../../../environment-helpers/use-api")
jest.setTimeout(50000)
describe("Inventory Module", () => {
let shutdownServer
let appContainer
let dbConnection
let express
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,15 +1,19 @@
const path = require("path")
const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app")
const {
startBootstrapApp,
} = require("../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../environment-helpers/use-db")
const { simpleProductFactory } = require("../../../factories")
const { getContainer } = require("../../../environment-helpers/use-container")
const { useExpressServer } = require("../../../environment-helpers/use-api")
jest.setTimeout(50000)
describe("Inventory Module", () => {
let appContainer
let dbConnection
let express
let shutdownServer
let invItem1
let invItem2
@@ -19,18 +23,14 @@ describe("Inventory Module", () => {
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd, verbose: false })
appContainer = container
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
describe("ProductVariantInventoryService", () => {

View File

@@ -1,8 +1,13 @@
const path = require("path")
const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app")
const {
startBootstrapApp,
} = require("../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../environment-helpers/use-api")
const adminSeeder = require("../../../helpers/admin-seeder")
@@ -14,11 +19,12 @@ const {
simpleProductFactory,
simpleShippingOptionFactory,
} = require("../../../factories")
const { getContainer } = require("../../../environment-helpers/use-container")
describe("medusa-plugin-sendgrid", () => {
let appContainer
let dbConnection
let express
let shutdownServer
const doAfterEach = async () => {
const db = useDb()
@@ -28,19 +34,14 @@ describe("medusa-plugin-sendgrid", () => {
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,11 +1,12 @@
import { setPort, useApi } from "../../../environment-helpers/use-api"
import { useApi } from "../../../environment-helpers/use-api"
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { simpleCartFactory, simpleRegionFactory } from "../../../factories"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { AxiosInstance } from "axios"
import path from "path"
import { bootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { getContainer } from "../../../environment-helpers/use-container"
import adminSeeder from "../../../helpers/admin-seeder"
jest.setTimeout(5000000)
@@ -30,24 +31,19 @@ const env = {
describe("Link Modules", () => {
let medusaContainer
let dbConnection
let express
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
const { container, app, port } = await bootstrapApp({ cwd, env })
medusaContainer = container
setPort(port)
express = app.listen(port)
shutdownServer = await startBootstrapApp({ cwd, env })
medusaContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
beforeEach(async () => {

View File

@@ -3,7 +3,7 @@ import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { Region } from "@medusajs/medusa"
import { AxiosInstance } from "axios"
import path from "path"
import setupServer from "../../../../environment-helpers/setup-server"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import adminSeeder from "../../../../helpers/admin-seeder"
@@ -25,19 +25,19 @@ const env = {
describe.skip("[Product & Pricing Module] POST /admin/products", () => {
let dbConnection
let appContainer
let medusaProcess
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
medusaProcess = await setupServer({ cwd, env, bootstrapApp: true } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
medusaProcess.kill()
await shutdownServer()
})
beforeEach(async () => {

View File

@@ -1,6 +1,6 @@
import path from "path"
import { bootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { setPort, useApi } from "../../../../environment-helpers/use-api"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder"
@@ -9,6 +9,7 @@ import productSeeder from "../../../../helpers/product-seeder"
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
import { Workflows } from "@medusajs/workflows"
import { AxiosInstance } from "axios"
import { getContainer } from "../../../../environment-helpers/use-container"
import {
simpleProductFactory,
simpleSalesChannelFactory,
@@ -24,26 +25,20 @@ const adminHeaders = {
describe("/admin/products", () => {
let dbConnection
let express
let shutdownServer
let medusaContainer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd } as any)
const { app, port, container } = await bootstrapApp({ cwd })
medusaContainer = container
setPort(port)
express = app.listen(port, () => {
process.send?.(port)
})
dbConnection = await initDb({ cwd })
shutdownServer = await startBootstrapApp({ cwd })
medusaContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
it("Should have loaded the product module", function () {

View File

@@ -1,4 +1,3 @@
import setupServer from "../../../../environment-helpers/setup-server"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
@@ -7,11 +6,12 @@ import {
simpleRegionFactory,
} from "../../../../factories"
import { AxiosInstance } from "axios"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { AxiosInstance } from "axios"
jest.setTimeout(50000)
@@ -26,24 +26,24 @@ const env = {
MEDUSA_FF_ISOLATE_PRODUCT_DOMAIN: true,
}
describe("[Product & Pricing Module] POST /admin/products/:id/variants/:id", () => {
describe.skip("[Product & Pricing Module] POST /admin/products/:id/variants/:id", () => {
let dbConnection
let appContainer
let medusaProcess
let shutdownServer
let product
let variant
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
medusaProcess = await setupServer({ cwd, env, bootstrapApp: true } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
medusaProcess.kill()
await shutdownServer()
})
beforeEach(async () => {

View File

@@ -1,4 +1,3 @@
import setupServer from "../../../../environment-helpers/setup-server"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
@@ -7,6 +6,7 @@ import { simpleProductFactory } from "../../../../factories"
import { Region } from "@medusajs/medusa"
import { AxiosInstance } from "axios"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
@@ -27,21 +27,21 @@ const env = {
describe.skip("[Product & Pricing Module] POST /admin/products/:id", () => {
let dbConnection
let appContainer
let medusaProcess
let shutdownServer
let product
let variant
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
medusaProcess = await setupServer({ cwd, env, bootstrapApp: true } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
medusaProcess.kill()
await shutdownServer()
})
beforeEach(async () => {
@@ -80,7 +80,7 @@ describe.skip("[Product & Pricing Module] POST /admin/products/:id", () => {
})
it("should update product variant price sets and prices", async () => {
const api = useApi()
const api = useApi() as any
const data = {
title: "test product update",
variants: [
@@ -102,14 +102,13 @@ describe.skip("[Product & Pricing Module] POST /admin/products/:id", () => {
],
}
let response = await api.post(
await api.post(`/admin/products/${product.id}`, data, adminHeaders)
const response = await api.get(
`/admin/products/${product.id}`,
data,
adminHeaders
)
response = await api.get(`/admin/products/${product.id}`, adminHeaders)
expect(response.status).toEqual(200)
expect(response.data.product).toEqual(
expect.objectContaining({
@@ -150,7 +149,7 @@ describe.skip("[Product & Pricing Module] POST /admin/products/:id", () => {
const moneyAmountToUpdate = priceSet.money_amounts?.[0]
const api = useApi()
const api = useApi() as any
const data = {
title: "test product update",
variants: [
@@ -173,14 +172,15 @@ describe.skip("[Product & Pricing Module] POST /admin/products/:id", () => {
],
}
let response = await api.post(
console.log("I am here first")
await api.post(`/admin/products/${product.id}`, data, adminHeaders)
console.log("I am here")
const response = await api.get(
`/admin/products/${product.id}`,
data,
adminHeaders
)
response = await api.get(`/admin/products/${product.id}`, adminHeaders)
expect(response.status).toEqual(200)
expect(response.data.product).toEqual(
expect.objectContaining({
@@ -248,14 +248,13 @@ describe.skip("[Product & Pricing Module] POST /admin/products/:id", () => {
],
}
let response = await api.post(
await api.post(`/admin/products/${product.id}`, data, adminHeaders)
const response = await api.get(
`/admin/products/${product.id}`,
data,
adminHeaders
)
response = await api.get(`/admin/products/${product.id}`, adminHeaders)
expect(response.status).toEqual(200)
expect(response.data.product).toEqual(
expect.objectContaining({

View File

@@ -1,35 +1,27 @@
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { getContainer } from "../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../environment-helpers/use-db"
import { bootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { setPort } from "../../../environment-helpers/use-api"
jest.setTimeout(30000)
describe("product", () => {
let dbConnection
let medusaContainer
let productService
let express
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd } as any)
const { container, port, app } = await bootstrapApp({ cwd })
setPort(port)
express = app.listen(port, () => {
process.send!(port)
})
medusaContainer = container
await initDb({ cwd })
shutdownServer = shutdownServer = await startBootstrapApp({ cwd })
medusaContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,34 +1,35 @@
const path = require("path")
const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app")
const {
startBootstrapApp,
} = require("../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../environment-helpers/use-api")
const adminSeeder = require("../../../helpers/admin-seeder")
const { getContainer } = require("../../../environment-helpers/use-container")
jest.setTimeout(30000)
describe("Sales channels", () => {
let appContainer
let dbConnection
let express
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,34 +1,35 @@
const path = require("path")
const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app")
const {
startBootstrapApp,
} = require("../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../environment-helpers/use-api")
const adminSeeder = require("../../../helpers/admin-seeder")
const { getContainer } = require("../../../environment-helpers/use-container")
jest.setTimeout(30000)
describe("Sales channels", () => {
let appContainer
let dbConnection
let express
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,10 +1,16 @@
const path = require("path")
const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app")
const {
startBootstrapApp,
} = require("../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../environment-helpers/use-db")
const { setPort, useApi } = require("../../../environment-helpers/use-api")
const {
useApi,
useExpressServer,
} = require("../../../environment-helpers/use-api")
const adminSeeder = require("../../../helpers/admin-seeder")
const { getContainer } = require("../../../environment-helpers/use-container")
jest.setTimeout(30000)
@@ -13,24 +19,19 @@ const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
describe("Sales channels", () => {
let appContainer
let dbConnection
let express
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
setPort(port)
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -1,30 +1,30 @@
const path = require("path")
const { bootstrapApp } = require("../../../environment-helpers/bootstrap-app")
const {
startBootstrapApp,
} = require("../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../environment-helpers/use-db")
const { getContainer } = require("../../../environment-helpers/use-container")
const { useExpressServer } = require("../../../environment-helpers/use-api")
jest.setTimeout(30000)
describe("Inventory Module", () => {
let appContainer
let dbConnection
let express
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd })
const { container, app, port } = await bootstrapApp({ cwd })
appContainer = container
express = app.listen(port, (err) => {
process.send(port)
})
shutdownServer = await startBootstrapApp({ cwd })
appContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
express.close()
await shutdownServer()
})
afterEach(async () => {

View File

@@ -6,24 +6,27 @@ import {
pipe,
} from "@medusajs/workflows"
import path from "path"
import { bootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
jest.setTimeout(30000)
describe("CreateInventoryItem workflow", function () {
let medusaContainer
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
await initDb({ cwd } as any)
const { container } = await bootstrapApp({ cwd })
medusaContainer = container
await initDb({ cwd })
shutdownServer = await startBootstrapApp({ cwd, skipExpressListen: true })
medusaContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
it("should compensate all the invoke if something fails", async () => {

View File

@@ -7,24 +7,29 @@ import {
pipe,
} from "@medusajs/workflows"
import path from "path"
import { bootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
jest.setTimeout(30000)
describe("CreateProduct workflow", function () {
let medusaContainer
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
await initDb({ cwd } as any)
const { container } = await bootstrapApp({ cwd })
medusaContainer = container
await initDb({ cwd })
shutdownServer = await startBootstrapApp({ cwd, skipExpressListen: true })
medusaContainer = getContainer()
})
afterAll(async () => {
console.log("GLOABL GC()", typeof global)
const db = useDb()
await db.shutdown()
await shutdownServer()
})
it("should compensate all the invoke if something fails", async () => {

View File

@@ -7,29 +7,29 @@ import {
} from "@medusajs/workflows"
import path from "path"
import { bootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { simpleProductFactory } from "../../../../factories"
jest.setTimeout(30000)
describe("UpdateProduct workflow", function () {
let medusaProcess
let dbConnection
let medusaContainer
let shutdownServer
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd } as any)
const { container } = await bootstrapApp({ cwd })
medusaContainer = container
dbConnection = await initDb({ cwd })
shutdownServer = await startBootstrapApp({ cwd, skipExpressListen: true })
medusaContainer = getContainer()
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
medusaProcess.kill()
await shutdownServer()
})
beforeEach(async () => {

View File

@@ -58,7 +58,7 @@ module.exports = {
},
[Modules.CACHE]: {
resolve: "@medusajs/cache-inmemory",
options: { ttl: 5 },
options: { ttl: 0 }, // Cache disabled
},
[Modules.PRODUCT]: {
scope: "internal",

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"private": true,
"scripts": {
"test:integration": "jest --silent=false --runInBand --bail --detectOpenHandles --forceExit",
"test:integration": "node --expose-gc ./../../node_modules/.bin/jest --silent=false --runInBand --bail --logHeapUsage --forceExit",
"build": "babel src -d dist --extensions \".ts,.js\""
},
"dependencies": {

View File

@@ -6,3 +6,5 @@ if (typeof process.env.DB_TEMP_NAME === "undefined") {
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
process.env.DB_TEMP_NAME = `medusa-integration-${tempName}`
}
global.performance = require("perf_hooks").performance

View File

@@ -12,5 +12,11 @@ const pgGodCredentials = {
}
afterAll(async () => {
await dropDatabase({ databaseName: DB_NAME }, pgGodCredentials)
try {
await dropDatabase({ databaseName: DB_NAME }, pgGodCredentials)
} catch (e) {
console.error(
`This might fail if it is run during the unit tests since there is no database to drop. Otherwise, please check what is the issue. ${e.message}`
)
}
})

View File

@@ -45,6 +45,10 @@ class InMemoryCacheService implements ICacheService {
* @param ttl - expiration time in seconds
*/
async set<T>(key: string, data: T, ttl: number = this.TTL): Promise<void> {
if (ttl === 0) {
return
}
const record: CacheRecord<T> = { data, expire: ttl * 1000 + Date.now() }
const oldRecord = this.store.get(key)
@@ -54,8 +58,8 @@ class InMemoryCacheService implements ICacheService {
this.timoutRefs.delete(key)
}
const ref = setTimeout(() => {
this.invalidate(key)
const ref = setTimeout(async () => {
await this.invalidate(key)
}, ttl * 1000)
ref.unref()

View File

@@ -35,6 +35,10 @@ class RedisCacheService implements ICacheService {
data: Record<string, unknown>,
ttl: number = this.TTL
): Promise<void> {
if (ttl === 0) {
return
}
await this.redis.set(
this.getCacheKey(key),
JSON.stringify(data),

View File

@@ -1,32 +1,26 @@
import {
MedusaApp,
ModulesDefinition,
moduleLoader,
registerModules,
} from "@medusajs/modules-sdk"
import { moduleLoader, registerModules } from "@medusajs/modules-sdk"
import { Express, NextFunction, Request, Response } from "express"
import databaseLoader, { dataSource } from "./database"
import pluginsLoader, { registerPluginModels } from "./plugins"
import { Connection } from "typeorm"
import { ContainerRegistrationKeys } from "@medusajs/utils"
import { asValue } from "awilix"
import { createMedusaContainer } from "medusa-core-utils"
import { track } from "medusa-telemetry"
import { EOL } from "os"
import requestIp from "request-ip"
import modulesConfig from "../modules-config"
import { Connection } from "typeorm"
import { MedusaContainer } from "../types/global"
import apiLoader from "./api"
import loadConfig from "./config"
import defaultsLoader from "./defaults"
import expressLoader from "./express"
import featureFlagsLoader from "./feature-flags"
import IsolatePricingDomainFeatureFlag from "./feature-flags/isolate-pricing-domain"
import IsolateProductDomainFeatureFlag from "./feature-flags/isolate-product-domain"
import Logger from "./logger"
import { joinerConfig } from "../joiner-config"
import loadConfig from "./config"
import loadMedusaApp from "./medusa-app"
import modelsLoader from "./models"
import passportLoader from "./passport"
import pgConnectionLoader from "./pg-connection"
@@ -36,7 +30,6 @@ import searchIndexLoader from "./search-index"
import servicesLoader from "./services"
import strategiesLoader from "./strategies"
import subscribersLoader from "./subscribers"
import loadMedusaApp from "./medusa-app"
type Options = {
directory: string
@@ -52,6 +45,7 @@ export default async ({
container: MedusaContainer
dbConnection: Connection
app: Express
pgConnection: unknown
}> => {
const configModule = loadConfig(rootDirectory)
@@ -102,7 +96,7 @@ export default async ({
const stratAct = Logger.success(stratActivity, "Strategies initialized") || {}
track("STRATEGIES_INIT_COMPLETED", { duration: stratAct.duration })
await pgConnectionLoader({ container, configModule })
const pgConnection = await pgConnectionLoader({ container, configModule })
const modulesActivity = Logger.activity(`Initializing modules${EOL}`)
@@ -202,5 +196,5 @@ export default async ({
Logger.success(searchActivity, "Indexing event emitted") || {}
track("SEARCH_ENGINE_INDEXING_COMPLETED", { duration: searchAct.duration })
return { container, dbConnection, app: expressApp }
return { container, dbConnection, app: expressApp, pgConnection }
}