always npm run post* using trap just trap it { "scripts": { "pretest": "docker-compose up", "test": "trap 'npm run posttest && exit 1' ERR ; jest --coverage", "posttest": "docker-compose down" } }