Improve e2e test watch mode (#5053)

* Improve e2e test watch mode

- run setup only once
- disable teardown

* Add container cleanup for watch mode

* Don't rely on inline exec code

Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
Jakob
2021-04-14 23:54:26 +02:00
committed by GitHub
parent cc868ae60c
commit 9df7b91564
5 changed files with 61 additions and 9 deletions

View File

@@ -3,9 +3,11 @@ import knex, { Knex } from 'knex';
import { awaitDatabaseConnection, awaitDirectusConnection } from './utils/await-connection';
import Listr, { ListrTask } from 'listr';
import { getDBsToTest } from '../get-dbs-to-test';
import config from '../config';
import config, { CONTAINER_PERSISTENCE_FILE } from '../config';
import globby from 'globby';
import path from 'path';
import { GlobalConfigTsJest } from 'ts-jest/dist/types';
import { writeFileSync } from 'fs';
declare module global {
let databaseContainers: { vendor: string; container: Dockerode.Container }[];
@@ -14,8 +16,12 @@ declare module global {
}
const docker = new Dockerode();
let started = false;
export default async (jestConfig: GlobalConfigTsJest) => {
if (started) return;
started = true;
export default async () => {
console.log('\n\n');
console.log(`👮‍♀️ Starting tests!\n`);
@@ -255,6 +261,21 @@ export default async () => {
);
},
},
{
skip: () => !jestConfig.watch,
title: 'Persist container info',
task: () => {
const persistContainer = ({ container, vendor }: { container: Dockerode.Container; vendor: string }) => ({
id: container.id,
vendor,
});
const containers = {
db: global.databaseContainers.map(persistContainer),
directus: global.directusContainers.map(persistContainer),
};
writeFileSync(CONTAINER_PERSISTENCE_FILE, JSON.stringify(containers));
},
},
]).run();
console.log('\n');