diff --git a/setup.js b/setup.js index 1e8ea8e..e1106cb 100644 --- a/setup.js +++ b/setup.js @@ -41,7 +41,9 @@ module.exports = async function () { DynamoDbLocal.configureInstaller(installerConfig); } - global.__DYNAMODB__ = await DynamoDbLocal.launch(port, null, options); + if(!global.__DYNAMODB__) { + global.__DYNAMODB__ = await DynamoDbLocal.launch(port, null, options); + } } await createTables(dynamoDB, newTables); diff --git a/teardown.js b/teardown.js index c956602..ca46414 100644 --- a/teardown.js +++ b/teardown.js @@ -1,12 +1,15 @@ const DynamoDbLocal = require('dynamodb-local'); const debug = require('debug')('jest-dynamodb'); -module.exports = async function () { +module.exports = async function (jestArgs) { // eslint-disable-next-line no-console debug('Teardown DynamoDB'); if (global.__DYNAMODB__) { - await DynamoDbLocal.stopChild(global.__DYNAMODB__); + const watching = jestArgs.watch || jestArgs.watchAll; + if (!watching) { + await DynamoDbLocal.stopChild(global.__DYNAMODB__); + } } else { const dynamoDB = global.__DYNAMODB_CLIENT__; const {TableNames: tableNames} = await dynamoDB.listTables().promise();