Skip to content

Commit

Permalink
feat: ensure local ddb is up and running before trying to create tables
Browse files Browse the repository at this point in the history
  • Loading branch information
vladholubiev committed Aug 18, 2021
1 parent e83d7d8 commit 6192908
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions index-another-concurrent-test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const {DynamoDBDocument} = require('@aws-sdk/lib-dynamodb');
const ddb = DynamoDBDocument.from(
new DynamoDB({
endpoint: 'http://localhost:8000',
tls: false,
region: 'local-env'
tls: false
}),
{
marshallOptions: {
Expand Down
3 changes: 1 addition & 2 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const {DynamoDBDocument} = require('@aws-sdk/lib-dynamodb');
const ddb = DynamoDBDocument.from(
new DynamoDB({
endpoint: 'http://localhost:8000',
tls: false,
region: 'local-env'
tls: false
}),
{
marshallOptions: {
Expand Down
6 changes: 5 additions & 1 deletion setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const cwd = require('cwd');
const {DynamoDB} = require('@aws-sdk/client-dynamodb');
const DynamoDbLocal = require('dynamodb-local');
const debug = require('debug')('jest-dynamodb');
const waitForLocalhost = require('./wait-for-localhost');

// aws-sdk requires access and secret key to be able to call DDB
process.env.AWS_ACCESS_KEY_ID = 'access-key';
Expand All @@ -24,7 +25,6 @@ module.exports = async function () {
const dynamoDB = new DynamoDB({
endpoint: `http://localhost:${port}`,
tls: false,
region: 'local-env',
...clientConfig
});

Expand All @@ -45,7 +45,11 @@ module.exports = async function () {
}

if (!global.__DYNAMODB__) {
debug('spinning up a local ddb instance');

global.__DYNAMODB__ = await DynamoDbLocal.launch(port, null, options);

await waitForLocalhost({port: DEFAULT_PORT, useGet: true, path: '/'});
}
}

Expand Down

0 comments on commit 6192908

Please sign in to comment.