Last active
March 29, 2023 21:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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