Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion jest-dynamodb-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
AttributeDefinitions: [{AttributeName: 'id', AttributeType: 'S'}],
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1}
}
]
],
port: 8000
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shelf/jest-dynamodb",
"version": "1.0.2",
"version": "1.1.0",
"description": "Run your tests using Jest & DynamoDB local",
"license": "MIT",
"repository": "shelfio/jest-dynamodb",
Expand Down
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module.exports = {
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1}
}
// etc
]
],
port: 8000
};
```

Expand Down Expand Up @@ -70,7 +71,7 @@ it('should insert item into table', async () => {
<details>
<summary>UnknownError: Not Found</summary>

Perhaps something is using your port 8000.
Perhaps something is using your port specified in `jest-dynamodb-config.js`.

</details>

Expand Down
9 changes: 7 additions & 2 deletions setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ const {resolve} = require('path');
const cwd = require('cwd');
const DynamoDB = require('aws-sdk/clients/dynamodb');
const DynamoDbLocal = require('dynamodb-local');
const defaultPort = 8000;
let {port} = require(resolve(cwd(), 'jest-dynamodb-config.js'));
if (typeof port === 'undefined' || port === null) {
port = defaultPort;
}

// aws-sdk requires access and secret key to be able to call DDB
process.env.AWS_ACCESS_KEY_ID = 'access-key';
process.env.AWS_SECRET_ACCESS_KEY = 'secret-key';

const dynamoDB = new DynamoDB({
endpoint: 'localhost:8000',
endpoint: 'localhost:' + port,
sslEnabled: false,
region: 'local-env'
});

module.exports = async function() {
global.__DYNAMODB__ = await DynamoDbLocal.launch(8000, null, ['-sharedDb']);
global.__DYNAMODB__ = await DynamoDbLocal.launch(port, null, ['-sharedDb']);

await createTables();
};
Expand Down