Files
directus/e2e-tests/setup/teardown.ts
Rijk van Zanten c7476cedbd End-to-end test setup (#4833)
* First start on test setup

* Setup e2e runner framework

* Use prepublishOnly for docs build

* Setup docker-based e2e test runner

* Spacing

* Setup db-getter + config

* Build image in Dockerode, pull images if needed

* Fix waiting for DB, run test for each running instance

* Get tests running per vendor

* Temp remove oracle

* Close awaiting connections in between
2021-04-05 15:11:02 -04:00

93 lines
2.2 KiB
TypeScript

import Listr from 'listr';
import { Knex } from 'knex';
import Dockerode from 'dockerode';
import { getDBsToTest } from '../get-dbs-to-test';
import config from '../config';
declare module global {
let databaseContainers: { vendor: string; container: Dockerode.Container }[];
let directusContainers: { vendor: string; container: Dockerode.Container }[];
let knexInstances: { vendor: string; knex: Knex }[];
}
export default async () => {
const vendors = getDBsToTest();
console.log('\n');
await new Listr([
{
title: 'Stop Docker containers',
task: () => {
return new Listr(
vendors.map((vendor) => {
return {
title: config.names[vendor]!,
task: () => {
return new Listr(
[
{
title: 'Database',
task: async () =>
await global.databaseContainers
.find((containerInfo) => containerInfo.vendor === vendor)
?.container.stop(),
},
{
title: 'Directus',
task: async () =>
await global.directusContainers
.find((containerInfo) => containerInfo.vendor === vendor)
?.container.stop(),
},
],
{ concurrent: true }
);
},
};
}),
{ concurrent: true }
);
},
},
{
title: 'Remove Docker containers',
task: () => {
return new Listr(
vendors.map((vendor) => {
return {
title: config.names[vendor]!,
task: () => {
return new Listr(
[
{
title: 'Database',
task: async () =>
await global.databaseContainers
.find((containerInfo) => containerInfo.vendor === vendor)
?.container.remove(),
},
{
title: 'Directus',
task: async () =>
await global.directusContainers
.find((containerInfo) => containerInfo.vendor === vendor)
?.container.remove(),
},
],
{ concurrent: true }
);
},
};
}),
{ concurrent: true }
);
},
},
]).run();
console.log('\n');
console.log(`👮‍♀️ Tests complete!\n`);
};