chore(integration-tests): Normalize DB config + use single process (#2077)

This commit is contained in:
Carlos R. L. Rodrigues
2022-08-24 07:29:53 -03:00
committed by GitHub
parent 687a6badeb
commit 690ca9e89a
15 changed files with 52 additions and 46 deletions

View File

@@ -143,7 +143,7 @@ jobs:
working-directory: integration-tests/api
- name: Run integration tests
run: yarn test --maxWorkers=50%
run: yarn test --runInBand
working-directory: integration-tests/api
env:
DB_PASSWORD: postgres
@@ -215,6 +215,6 @@ jobs:
working-directory: integration-tests/plugins
- name: Run plugin integration tests
run: yarn test:integration:plugins --maxWorkers=50% --silent=false
run: yarn test:integration:plugins --silent=false
env:
DB_PASSWORD: postgres

View File

@@ -1,3 +1,4 @@
# Default postgres credentials
DB_HOST=localhost
DB_USERNAME=postgres
DB_PASSWORD=''

View File

@@ -2233,7 +2233,6 @@ describe("/admin/discounts", () => {
})
const cond = discountCondition.data.discount_condition
console.log(cond.products)
expect(discountCondition.status).toEqual(200)
expect(cond).toMatchSnapshot({

View File

@@ -101,10 +101,6 @@ describe("Line Item Adjustments", () => {
await doAfterEach()
})
afterEach(async () => {
await doAfterEach()
})
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", () => {
test("Then should create an adjustment", async () => {

View File

@@ -17,6 +17,7 @@ module.exports = {
],
transformIgnorePatterns: [`/dist`],
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
setupFiles: ["../setup-env.js"],
setupFilesAfterEnv: ["../setup.js"],
globalSetup: "../globalSetup.js",
globalTeardown: "../globalTeardown.js",

View File

@@ -1,12 +1,13 @@
const DB_USERNAME = process.env.DB_USERNAME || "postgres"
const DB_PASSWORD = process.env.DB_PASSWORD || ""
const workerId = parseInt(process.env.JEST_WORKER_ID || "1")
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
module.exports = {
plugins: [],
projectConfig: {
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",
jwt_secret: "test",
cookie_secret: "test",

View File

@@ -1,18 +1,19 @@
const path = require("path")
require("dotenv").config({ path: path.join(__dirname, "../.env") })
const { dropDatabase } = require("pg-god")
const { createConnection } = require("typeorm")
const dbFactory = require("./use-template-db")
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 DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@localhost/medusa-integration-${workerId}`
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 DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`
const pgGodCredentials = {
user: DB_USERNAME,
password: DB_PASSWORD,
host: DB_HOST,
}
const keepTables = [
@@ -69,8 +70,7 @@ const DbTestUtil = {
shutdown: async function () {
await this.db_.close()
const databaseName = `medusa-integration-${workerId}`
return await dropDatabase({ databaseName }, pgGodCredentials)
return await dropDatabase({ DB_NAME }, pgGodCredentials)
},
}
@@ -117,9 +117,7 @@ module.exports = {
instance.setDb(dbConnection)
return dbConnection
} else {
const databaseName = `medusa-integration-${workerId}`
await dbFactory.createFromTemplate(databaseName)
await dbFactory.createFromTemplate(DB_NAME)
// get migraitons with enabled featureflags
const migrationDir = path.resolve(

View File

@@ -1,16 +1,19 @@
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 { createConnection, getConnection } = require("typeorm")
const DB_USERNAME = process.env.DB_USERNAME || "postgres"
const DB_PASSWORD = process.env.DB_PASSWORD || ""
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@localhost`
const DB_HOST = process.env.DB_HOST
const DB_USERNAME = process.env.DB_USERNAME
const DB_PASSWORD = process.env.DB_PASSWORD
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}`
const pgGodCredentials = {
user: DB_USERNAME,
password: DB_PASSWORD,
host: DB_HOST,
}
class DatabaseFactory {

View File

@@ -25,5 +25,6 @@ module.exports = {
`.cache`,
],
transform: { "^.+\\.[jt]s$": `<rootDir>/jest-transformer.js` },
setupFiles: ["<rootDir>/integration-tests/setup-env.js"],
setupFilesAfterEnv: ["<rootDir>/integration-tests/setup.js"],
}

View File

@@ -15,6 +15,7 @@ module.exports = {
],
transformIgnorePatterns: [`/dist`],
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
setupFiles: ["../setup-env.js"],
setupFilesAfterEnv: ["../setup.js"],
globalSetup: "../globalSetup.js",
globalTeardown: "../globalTeardown.js",

View File

@@ -1,6 +1,7 @@
const DB_USERNAME = process.env.DB_USERNAME || "postgres"
const DB_PASSWORD = process.env.DB_PASSWORD || ""
const workerId = parseInt(process.env.JEST_WORKER_ID || "1")
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
module.exports = {
plugins: [
@@ -22,9 +23,9 @@ module.exports = {
],
projectConfig: {
// 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",
jwt_secret: 'test',
cookie_secret: 'test'
jwt_secret: "test",
cookie_secret: "test",
},
}

View File

@@ -4,7 +4,7 @@
"main": "index.js",
"license": "MIT",
"scripts": {
"test": "jest --maxWorkers=50% --silent=false",
"test": "jest --runInBand --silent=false",
"build": "babel src -d dist --extensions \".ts,.js\""
},
"dependencies": {

View File

@@ -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}`
}

View File

@@ -1,20 +1,16 @@
const path = require("path")
const { dropDatabase } = require("pg-god")
require("dotenv").config({ path: path.join(__dirname, ".env") })
const DB_USERNAME = process.env.DB_USERNAME || "postgres"
const DB_PASSWORD = process.env.DB_PASSWORD || ""
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,
}
afterAll(async () => {
const workerId = parseInt(process.env.JEST_WORKER_ID || "1")
await dropDatabase(
{ databaseName: `medusa-integration-${workerId}` },
pgGodCredentials
)
await dropDatabase({ databaseName: DB_NAME }, pgGodCredentials)
})

View File

@@ -64,10 +64,10 @@
"jest": "jest",
"test": "turbo run test",
"prettier": "prettier",
"test:integration": "jest --config=integration-tests/jest.config.js",
"test:integration:api": "jest --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:fixtures": "jest --config=docs-util/jest.config.js --runInBand",
"test:integration": "NODE_ENV=test jest --runInBand --config=integration-tests/jest.config.js",
"test:integration:api": "NODE_ENV=test jest --runInBand --config=integration-tests/jest.config.js --projects=integration-tests/api",
"test:integration:plugins": "NODE_ENV=test jest --runInBand --config=integration-tests/jest.config.js --projects=integration-tests/plugins",
"test:fixtures": "NODE_ENV=test jest --config=docs-util/jest.config.js --runInBand",
"openapi:generate": "node ./scripts/build-openapi.js",
"generate:services": "typedoc --options typedoc.services.js",
"generate:js-client": "typedoc --options typedoc.js-client.js",