Skip to content

Commit c8c8036

Browse files
Allow jest watch / watchAll
Uses an existence check at startup to avoid attempting to re-instantiate the dynamodb-local server if already defined. Also uses jest's [globalConfig argument at teardown](https://jestjs.io/docs/en/configuration#globalteardown-string) to detect watch state and avoid tearing down the server prematurely.
1 parent cb67d84 commit c8c8036

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

setup.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ module.exports = async function () {
4141
DynamoDbLocal.configureInstaller(installerConfig);
4242
}
4343

44-
global.__DYNAMODB__ = await DynamoDbLocal.launch(port, null, options);
44+
if(!global.__DYNAMODB__) {
45+
global.__DYNAMODB__ = await DynamoDbLocal.launch(port, null, options);
46+
}
4547
}
4648

4749
await createTables(dynamoDB, newTables);

teardown.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
const DynamoDbLocal = require('dynamodb-local');
22
const debug = require('debug')('jest-dynamodb');
33

4-
module.exports = async function () {
4+
module.exports = async function (jestArgs) {
55
// eslint-disable-next-line no-console
66
debug('Teardown DynamoDB');
77

88
if (global.__DYNAMODB__) {
9-
await DynamoDbLocal.stopChild(global.__DYNAMODB__);
9+
const watching = jestArgs.watch || jestArgs.watchAll;
10+
if (!watching) {
11+
await DynamoDbLocal.stopChild(global.__DYNAMODB__);
12+
}
1013
} else {
1114
const dynamoDB = global.__DYNAMODB_CLIENT__;
1215
const {TableNames: tableNames} = await dynamoDB.listTables().promise();

0 commit comments

Comments
 (0)