Skip to content

Instantly share code, notes, and snippets.

@ali-kamalizade
Last active March 29, 2023 21:43
Show Gist options
  • Save ali-kamalizade/3a8800206cffe37c48a0d8ca7a3afb77 to your computer and use it in GitHub Desktop.
Save ali-kamalizade/3a8800206cffe37c48a0d8ca7a3afb77 to your computer and use it in GitHub Desktop.
Jest globalTeardown function to stop and remove containers (e.g. Postgres) which were started as part of the test run
// helpful if you use Nx - else you can omit this import
import 'tsconfig-paths/register';
import { getContainerById } from 'testcontainers/dist/docker/functions/container/get-container';
export default async () => {
const containerId = process.env.TEST_POSTGRES_CONTAINER_ID!;
const container = await getContainerById(containerId);
await container.stop();
// deletion of docker volume after running all tests
await container.remove({ v: true }));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment