Files
directus/tests/e2e/setup/utils/await-connection.ts
Jay Cammarano 00a838f020 Docs for testing the API (#10275)
* mock-knex

* test on the migrations run started.

* test passing for run.up()

* reorganize /tests/ to allow integration tests

* e2e setup changes

* e2e jest.config moved

* e2e paths fixed, integration config

* add nonadmin role and user seed+migration

* auth/login w/ documentation (docs will be moved)

* update user seed

* add postgres10 to the ci?

* argon2 saves the day

* items tests passing with postgres10 support

* removed comments

* move generateHash out of directus_users

Co-authored-by: Jay Cammarano <jaycammarano@gmail.com>
2021-12-10 14:58:51 -05:00

45 lines
1001 B
TypeScript

import { Knex } from 'knex';
import axios from 'axios';
export async function awaitDatabaseConnection(
database: Knex,
checkSQL: string,
currentAttempt = 0
): Promise<void | null> {
try {
await database.raw(checkSQL);
} catch {
if (currentAttempt === 10) {
throw new Error(`Couldn't connect to DB`);
}
return new Promise((resolve) => {
setTimeout(async () => {
await awaitDatabaseConnection(database, checkSQL, currentAttempt + 1);
resolve(null);
}, 5000);
});
}
}
export async function awaitDirectusConnection(port = 6100, currentAttempt = 0): Promise<void | null> {
try {
await axios.get(`http://localhost:${port}/server/ping`);
} catch {
if (currentAttempt === 10) {
throw new Error(`Couldn't connect to Directus`);
}
return new Promise((resolve, reject) => {
setTimeout(async () => {
try {
await awaitDirectusConnection(port, currentAttempt + 1);
resolve(null);
} catch (err) {
reject(err);
}
}, 5000);
});
}
}