chore(integration-tests): Normalize DB config + use single process (#2077)
This commit is contained in:
@@ -143,7 +143,7 @@ jobs:
|
|||||||
working-directory: integration-tests/api
|
working-directory: integration-tests/api
|
||||||
|
|
||||||
- name: Run integration tests
|
- name: Run integration tests
|
||||||
run: yarn test --maxWorkers=50%
|
run: yarn test --runInBand
|
||||||
working-directory: integration-tests/api
|
working-directory: integration-tests/api
|
||||||
env:
|
env:
|
||||||
DB_PASSWORD: postgres
|
DB_PASSWORD: postgres
|
||||||
@@ -215,6 +215,6 @@ jobs:
|
|||||||
working-directory: integration-tests/plugins
|
working-directory: integration-tests/plugins
|
||||||
|
|
||||||
- name: Run plugin integration tests
|
- name: Run plugin integration tests
|
||||||
run: yarn test:integration:plugins --maxWorkers=50% --silent=false
|
run: yarn test:integration:plugins --silent=false
|
||||||
env:
|
env:
|
||||||
DB_PASSWORD: postgres
|
DB_PASSWORD: postgres
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
# Default postgres credentials
|
# Default postgres credentials
|
||||||
|
DB_HOST=localhost
|
||||||
DB_USERNAME=postgres
|
DB_USERNAME=postgres
|
||||||
DB_PASSWORD=''
|
DB_PASSWORD=''
|
||||||
@@ -2233,7 +2233,6 @@ describe("/admin/discounts", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const cond = discountCondition.data.discount_condition
|
const cond = discountCondition.data.discount_condition
|
||||||
console.log(cond.products)
|
|
||||||
|
|
||||||
expect(discountCondition.status).toEqual(200)
|
expect(discountCondition.status).toEqual(200)
|
||||||
expect(cond).toMatchSnapshot({
|
expect(cond).toMatchSnapshot({
|
||||||
|
|||||||
@@ -101,10 +101,6 @@ describe("Line Item Adjustments", () => {
|
|||||||
await doAfterEach()
|
await doAfterEach()
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await doAfterEach()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("Given an existing line item, a discount, and a line item adjustment for both", () => {
|
describe("Given an existing line item, a discount, and a line item adjustment for both", () => {
|
||||||
describe("When creating an adjustment for another line item w. same discount", () => {
|
describe("When creating an adjustment for another line item w. same discount", () => {
|
||||||
test("Then should create an adjustment", async () => {
|
test("Then should create an adjustment", async () => {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
transformIgnorePatterns: [`/dist`],
|
transformIgnorePatterns: [`/dist`],
|
||||||
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
|
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
|
||||||
|
setupFiles: ["../setup-env.js"],
|
||||||
setupFilesAfterEnv: ["../setup.js"],
|
setupFilesAfterEnv: ["../setup.js"],
|
||||||
globalSetup: "../globalSetup.js",
|
globalSetup: "../globalSetup.js",
|
||||||
globalTeardown: "../globalTeardown.js",
|
globalTeardown: "../globalTeardown.js",
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
const DB_USERNAME = process.env.DB_USERNAME || "postgres"
|
const DB_HOST = process.env.DB_HOST
|
||||||
const DB_PASSWORD = process.env.DB_PASSWORD || ""
|
const DB_USERNAME = process.env.DB_USERNAME
|
||||||
const workerId = parseInt(process.env.JEST_WORKER_ID || "1")
|
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||||
|
const DB_NAME = process.env.DB_TEMP_NAME
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
plugins: [],
|
plugins: [],
|
||||||
projectConfig: {
|
projectConfig: {
|
||||||
redis_url: process.env.REDIS_URL,
|
redis_url: process.env.REDIS_URL,
|
||||||
database_url: `postgres://${DB_USERNAME}:${DB_PASSWORD}@localhost/medusa-integration-${workerId}`,
|
database_url: `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`,
|
||||||
database_type: "postgres",
|
database_type: "postgres",
|
||||||
jwt_secret: "test",
|
jwt_secret: "test",
|
||||||
cookie_secret: "test",
|
cookie_secret: "test",
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
const path = require("path")
|
const path = require("path")
|
||||||
require("dotenv").config({ path: path.join(__dirname, "../.env") })
|
|
||||||
|
|
||||||
const { dropDatabase } = require("pg-god")
|
const { dropDatabase } = require("pg-god")
|
||||||
const { createConnection } = require("typeorm")
|
const { createConnection } = require("typeorm")
|
||||||
const dbFactory = require("./use-template-db")
|
const dbFactory = require("./use-template-db")
|
||||||
|
|
||||||
const workerId = parseInt(process.env.JEST_WORKER_ID || "1")
|
const DB_HOST = process.env.DB_HOST
|
||||||
const DB_USERNAME = process.env.DB_USERNAME || "postgres"
|
const DB_USERNAME = process.env.DB_USERNAME
|
||||||
const DB_PASSWORD = process.env.DB_PASSWORD || ""
|
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||||
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@localhost/medusa-integration-${workerId}`
|
const DB_NAME = process.env.DB_TEMP_NAME
|
||||||
|
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`
|
||||||
|
|
||||||
const pgGodCredentials = {
|
const pgGodCredentials = {
|
||||||
user: DB_USERNAME,
|
user: DB_USERNAME,
|
||||||
password: DB_PASSWORD,
|
password: DB_PASSWORD,
|
||||||
|
host: DB_HOST,
|
||||||
}
|
}
|
||||||
|
|
||||||
const keepTables = [
|
const keepTables = [
|
||||||
@@ -69,8 +70,7 @@ const DbTestUtil = {
|
|||||||
|
|
||||||
shutdown: async function () {
|
shutdown: async function () {
|
||||||
await this.db_.close()
|
await this.db_.close()
|
||||||
const databaseName = `medusa-integration-${workerId}`
|
return await dropDatabase({ DB_NAME }, pgGodCredentials)
|
||||||
return await dropDatabase({ databaseName }, pgGodCredentials)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,9 +117,7 @@ module.exports = {
|
|||||||
instance.setDb(dbConnection)
|
instance.setDb(dbConnection)
|
||||||
return dbConnection
|
return dbConnection
|
||||||
} else {
|
} else {
|
||||||
const databaseName = `medusa-integration-${workerId}`
|
await dbFactory.createFromTemplate(DB_NAME)
|
||||||
|
|
||||||
await dbFactory.createFromTemplate(databaseName)
|
|
||||||
|
|
||||||
// get migraitons with enabled featureflags
|
// get migraitons with enabled featureflags
|
||||||
const migrationDir = path.resolve(
|
const migrationDir = path.resolve(
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
const path = require("path")
|
const path = require("path")
|
||||||
require("dotenv").config({ path: path.join(__dirname, "../.env") })
|
|
||||||
|
require("dotenv").config({ path: path.join(__dirname, "../.env.test") })
|
||||||
|
|
||||||
const { createDatabase, dropDatabase } = require("pg-god")
|
const { createDatabase, dropDatabase } = require("pg-god")
|
||||||
const { createConnection, getConnection } = require("typeorm")
|
const { createConnection, getConnection } = require("typeorm")
|
||||||
|
|
||||||
const DB_USERNAME = process.env.DB_USERNAME || "postgres"
|
const DB_HOST = process.env.DB_HOST
|
||||||
const DB_PASSWORD = process.env.DB_PASSWORD || ""
|
const DB_USERNAME = process.env.DB_USERNAME
|
||||||
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@localhost`
|
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||||
|
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}`
|
||||||
|
|
||||||
const pgGodCredentials = {
|
const pgGodCredentials = {
|
||||||
user: DB_USERNAME,
|
user: DB_USERNAME,
|
||||||
password: DB_PASSWORD,
|
password: DB_PASSWORD,
|
||||||
|
host: DB_HOST,
|
||||||
}
|
}
|
||||||
|
|
||||||
class DatabaseFactory {
|
class DatabaseFactory {
|
||||||
|
|||||||
@@ -25,5 +25,6 @@ module.exports = {
|
|||||||
`.cache`,
|
`.cache`,
|
||||||
],
|
],
|
||||||
transform: { "^.+\\.[jt]s$": `<rootDir>/jest-transformer.js` },
|
transform: { "^.+\\.[jt]s$": `<rootDir>/jest-transformer.js` },
|
||||||
|
setupFiles: ["<rootDir>/integration-tests/setup-env.js"],
|
||||||
setupFilesAfterEnv: ["<rootDir>/integration-tests/setup.js"],
|
setupFilesAfterEnv: ["<rootDir>/integration-tests/setup.js"],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
transformIgnorePatterns: [`/dist`],
|
transformIgnorePatterns: [`/dist`],
|
||||||
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
|
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
|
||||||
|
setupFiles: ["../setup-env.js"],
|
||||||
setupFilesAfterEnv: ["../setup.js"],
|
setupFilesAfterEnv: ["../setup.js"],
|
||||||
globalSetup: "../globalSetup.js",
|
globalSetup: "../globalSetup.js",
|
||||||
globalTeardown: "../globalTeardown.js",
|
globalTeardown: "../globalTeardown.js",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const DB_USERNAME = process.env.DB_USERNAME || "postgres"
|
const DB_HOST = process.env.DB_HOST
|
||||||
const DB_PASSWORD = process.env.DB_PASSWORD || ""
|
const DB_USERNAME = process.env.DB_USERNAME
|
||||||
const workerId = parseInt(process.env.JEST_WORKER_ID || "1")
|
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||||
|
const DB_NAME = process.env.DB_TEMP_NAME
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
plugins: [
|
plugins: [
|
||||||
@@ -22,9 +23,9 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
projectConfig: {
|
projectConfig: {
|
||||||
// redis_url: REDIS_URL,
|
// redis_url: REDIS_URL,
|
||||||
database_url: `postgres://${DB_USERNAME}:${DB_PASSWORD}@localhost/medusa-integration-${workerId}`,
|
database_url: `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`,
|
||||||
database_type: "postgres",
|
database_type: "postgres",
|
||||||
jwt_secret: 'test',
|
jwt_secret: "test",
|
||||||
cookie_secret: 'test'
|
cookie_secret: "test",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest --maxWorkers=50% --silent=false",
|
"test": "jest --runInBand --silent=false",
|
||||||
"build": "babel src -d dist --extensions \".ts,.js\""
|
"build": "babel src -d dist --extensions \".ts,.js\""
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
const path = require("path")
|
||||||
|
|
||||||
|
require("dotenv").config({ path: path.join(__dirname, ".env.test") })
|
||||||
|
|
||||||
|
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}`
|
||||||
|
}
|
||||||
@@ -1,20 +1,16 @@
|
|||||||
const path = require("path")
|
|
||||||
const { dropDatabase } = require("pg-god")
|
const { dropDatabase } = require("pg-god")
|
||||||
|
|
||||||
require("dotenv").config({ path: path.join(__dirname, ".env") })
|
const DB_HOST = process.env.DB_HOST
|
||||||
|
const DB_USERNAME = process.env.DB_USERNAME
|
||||||
const DB_USERNAME = process.env.DB_USERNAME || "postgres"
|
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||||
const DB_PASSWORD = process.env.DB_PASSWORD || ""
|
const DB_NAME = process.env.DB_TEMP_NAME
|
||||||
|
|
||||||
const pgGodCredentials = {
|
const pgGodCredentials = {
|
||||||
user: DB_USERNAME,
|
user: DB_USERNAME,
|
||||||
password: DB_PASSWORD,
|
password: DB_PASSWORD,
|
||||||
|
host: DB_HOST,
|
||||||
}
|
}
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
const workerId = parseInt(process.env.JEST_WORKER_ID || "1")
|
await dropDatabase({ databaseName: DB_NAME }, pgGodCredentials)
|
||||||
await dropDatabase(
|
|
||||||
{ databaseName: `medusa-integration-${workerId}` },
|
|
||||||
pgGodCredentials
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|||||||
+4
-4
@@ -64,10 +64,10 @@
|
|||||||
"jest": "jest",
|
"jest": "jest",
|
||||||
"test": "turbo run test",
|
"test": "turbo run test",
|
||||||
"prettier": "prettier",
|
"prettier": "prettier",
|
||||||
"test:integration": "jest --config=integration-tests/jest.config.js",
|
"test:integration": "NODE_ENV=test jest --runInBand --config=integration-tests/jest.config.js",
|
||||||
"test:integration:api": "jest --config=integration-tests/jest.config.js --projects=integration-tests/api",
|
"test:integration:api": "NODE_ENV=test jest --runInBand --config=integration-tests/jest.config.js --projects=integration-tests/api",
|
||||||
"test:integration:plugins": "jest --config=integration-tests/jest.config.js --projects=integration-tests/plugins",
|
"test:integration:plugins": "NODE_ENV=test jest --runInBand --config=integration-tests/jest.config.js --projects=integration-tests/plugins",
|
||||||
"test:fixtures": "jest --config=docs-util/jest.config.js --runInBand",
|
"test:fixtures": "NODE_ENV=test jest --config=docs-util/jest.config.js --runInBand",
|
||||||
"openapi:generate": "node ./scripts/build-openapi.js",
|
"openapi:generate": "node ./scripts/build-openapi.js",
|
||||||
"generate:services": "typedoc --options typedoc.services.js",
|
"generate:services": "typedoc --options typedoc.services.js",
|
||||||
"generate:js-client": "typedoc --options typedoc.js-client.js",
|
"generate:js-client": "typedoc --options typedoc.js-client.js",
|
||||||
|
|||||||
Reference in New Issue
Block a user