mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Tools: Allow running the test units with Postgres
This commit is contained in:
parent
2d0580ff71
commit
bb275e671d
@ -31,7 +31,7 @@ export async function createDb(config: DatabaseConfig, options: CreateDbOptions
|
||||
await dropDb(config, { ignoreIfNotExists: true });
|
||||
}
|
||||
|
||||
await execCommand(cmd.join(' '));
|
||||
await execCommand(cmd.join(' '), { env: { PGPASSWORD: config.password } });
|
||||
} else if (config.client === 'sqlite3') {
|
||||
const filePath = sqliteFilePath(config.name);
|
||||
|
||||
@ -65,7 +65,7 @@ export async function dropDb(config: DatabaseConfig, options: DropDbOptions = nu
|
||||
];
|
||||
|
||||
try {
|
||||
await execCommand(cmd.join(' '));
|
||||
await execCommand(cmd.join(' '), { env: { PGPASSWORD: config.password } });
|
||||
} catch (error) {
|
||||
if (options.ignoreIfNotExists && error.message.includes('does not exist')) return;
|
||||
throw error;
|
||||
|
@ -61,6 +61,18 @@ export async function beforeAllDb(unitName: string) {
|
||||
const tempDir = `${packageRootDir}/temp/test-${unitName}`;
|
||||
await fs.mkdirp(tempDir);
|
||||
|
||||
// Uncomment the code below to run the test units with Postgres. Run first
|
||||
// `docker-compose -f docker-compose.db-dev.yml` to get a dev db.
|
||||
|
||||
// initConfig({
|
||||
// DB_CLIENT: 'pg',
|
||||
// POSTGRES_DATABASE: createdDbName_,
|
||||
// POSTGRES_USER: 'joplin',
|
||||
// POSTGRES_PASSWORD: 'joplin',
|
||||
// }, {
|
||||
// tempDir: tempDir,
|
||||
// });
|
||||
|
||||
initConfig({
|
||||
SQLITE_DATABASE: createdDbName_,
|
||||
}, {
|
||||
|
@ -108,11 +108,13 @@ async function saveGitHubUsernameCache(cache: any) {
|
||||
// Returns the project root dir
|
||||
export const rootDir = require('path').dirname(require('path').dirname(__dirname));
|
||||
|
||||
export function execCommand(command: string) {
|
||||
export function execCommand(command: string, options: any = null) {
|
||||
options = options || {};
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(command, (error: any, stdout: any, stderr: any) => {
|
||||
exec(command, options, (error: any, stdout: any, stderr: any) => {
|
||||
if (error) {
|
||||
if (error.signal == 'SIGTERM') {
|
||||
resolve('Process was killed');
|
||||
|
Loading…
Reference in New Issue
Block a user