feat(medusa): Cache modules (#3187)

This commit is contained in:
Frane Polić
2023-03-10 15:09:26 +01:00
committed by GitHub
parent f43f03badb
commit f97b3d7cce
42 changed files with 783 additions and 186 deletions
@@ -23,7 +23,6 @@ module.exports = ({ cwd, redisUrl, uploadDir, verbose, env }) => {
COOKIE_SECRET: "test",
REDIS_URL: redisUrl ? redisUrlWithDatabase : undefined, // If provided, will use a real instance, otherwise a fake instance
UPLOAD_DIR: uploadDir, // If provided, will be used for the fake local file service
CACHE_TTL: 0, // By default the cache service is disabled and 0 means that none of the cache key/value will be stored.
...env,
},
stdio: verbose
-58
View File
@@ -1,58 +0,0 @@
const path = require("path")
const Redis = require("ioredis")
const { GenericContainer } = require("testcontainers")
require("dotenv").config({ path: path.join(__dirname, "../.env") })
const workerId = parseInt(process.env.JEST_WORKER_ID || "1")
const DB_USERNAME = process.env.DB_USERNAME || "postgres"
const DB_PASSWORD = process.env.DB_PASSWORD || ""
const DbTestUtil = {
db_: null,
setDb: function (connection) {
this.db_ = connection
},
clear: async function () {
/* noop */
},
teardown: async function () {
/* noop */
},
shutdown: async function () {
/* noop */
// TODO: stop container
},
}
const instance = DbTestUtil
module.exports = {
initRedis: async function ({ cwd }) {
// const configPath = path.resolve(path.join(cwd, `medusa-config.js`))
// const { projectConfig } = require(configPath)
const container = await new GenericContainer("redis")
.withExposedPorts(6379)
.start()
const redisClient = new Redis({
host: container.getHost(),
port: container.getMappedPort(6379),
db: workerId,
})
instance.setDb(redisClient)
return redisClient
},
useRedis: function () {
return instance
},
}