fix: parameterize integration tests' db credentials (#319)
* add: read db credentials from .env * remove: console.log * fix: default to default pg user and password
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# Default postgres credentials
|
||||
DB_USERNAME=postgres
|
||||
DB_PASSWORD=''
|
||||
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
.npm
|
||||
.env
|
||||
@@ -1,8 +1,11 @@
|
||||
const DB_USERNAME = process.env.DB_USERNAME || "postgres";
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD || "";
|
||||
|
||||
module.exports = {
|
||||
plugins: [],
|
||||
projectConfig: {
|
||||
// redis_url: REDIS_URL,
|
||||
database_url: "postgres://localhost/medusa-integration",
|
||||
database_url: `postgres://${DB_USERNAME}:${DB_PASSWORD}@localhost/medusa-integration`,
|
||||
database_type: "postgres",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
"build": "babel src -d dist --extensions \".ts,.js\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/medusa": "1.1.29-dev-1626162503472",
|
||||
"medusa-interfaces": "1.1.17-dev-1626162503472",
|
||||
"@medusajs/medusa": "^1.1.32",
|
||||
"medusa-interfaces": "^1.1.18",
|
||||
"typeorm": "^0.2.31"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.12.10",
|
||||
"@babel/core": "^7.12.10",
|
||||
"@babel/node": "^7.12.10",
|
||||
"babel-preset-medusa-package": "1.1.10-dev-1626162503472",
|
||||
"babel-preset-medusa-package": "^1.1.11",
|
||||
"jest": "^26.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
+1428
-1448
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,16 @@
|
||||
const path = require("path");
|
||||
require("dotenv").config({ path: path.join(__dirname, "../.env") });
|
||||
|
||||
const { dropDatabase, createDatabase } = require("pg-god");
|
||||
const { createConnection } = require("typeorm");
|
||||
|
||||
const path = require("path");
|
||||
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`;
|
||||
const pgGodCredentials = {
|
||||
user: DB_USERNAME,
|
||||
password: DB_PASSWORD,
|
||||
};
|
||||
|
||||
const DbTestUtil = {
|
||||
db_: null,
|
||||
@@ -16,7 +25,7 @@ const DbTestUtil = {
|
||||
|
||||
shutdown: async function () {
|
||||
await this.db_.close();
|
||||
return dropDatabase({ databaseName });
|
||||
return dropDatabase({ databaseName }, pgGodCredentials);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -36,11 +45,11 @@ module.exports = {
|
||||
);
|
||||
|
||||
const databaseName = "medusa-integration";
|
||||
await createDatabase({ databaseName });
|
||||
await createDatabase({ databaseName }, pgGodCredentials);
|
||||
|
||||
const connection = await createConnection({
|
||||
type: "postgres",
|
||||
url: "postgres://localhost/medusa-integration",
|
||||
url: DB_URL,
|
||||
migrations: [`${migrationDir}/*.js`],
|
||||
});
|
||||
|
||||
@@ -60,7 +69,7 @@ module.exports = {
|
||||
const entities = modelsLoader({}, { register: false });
|
||||
const dbConnection = await createConnection({
|
||||
type: "postgres",
|
||||
url: "postgres://localhost/medusa-integration",
|
||||
url: DB_URL,
|
||||
entities,
|
||||
});
|
||||
|
||||
|
||||
Generated
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "integration-tests",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"dotenv": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
|
||||
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "integration-tests",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "jest.config.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Zakaria S. El Asri",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"dotenv": "^10.0.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user