Skip to content

Commit 98242b2

Browse files
authored
Allow Port Override (#12)
Allow Port Override
2 parents 6645a32 + 4fed0e2 commit 98242b2

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

jest-dynamodb-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ module.exports = {
66
AttributeDefinitions: [{AttributeName: 'id', AttributeType: 'S'}],
77
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1}
88
}
9-
]
9+
],
10+
port: 8000
1011
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shelf/jest-dynamodb",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "Run your tests using Jest & DynamoDB local",
55
"license": "MIT",
66
"repository": "shelfio/jest-dynamodb",

readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ module.exports = {
3232
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1}
3333
}
3434
// etc
35-
]
35+
],
36+
port: 8000
3637
};
3738
```
3839

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

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

7576
</details>
7677

setup.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@ const {resolve} = require('path');
22
const cwd = require('cwd');
33
const DynamoDB = require('aws-sdk/clients/dynamodb');
44
const DynamoDbLocal = require('dynamodb-local');
5+
const defaultPort = 8000;
6+
let {port} = require(resolve(cwd(), 'jest-dynamodb-config.js'));
7+
if (typeof port === 'undefined' || port === null) {
8+
port = defaultPort;
9+
}
510

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

1015
const dynamoDB = new DynamoDB({
11-
endpoint: 'localhost:8000',
16+
endpoint: 'localhost:' + port,
1217
sslEnabled: false,
1318
region: 'local-env'
1419
});
1520

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

1924
await createTables();
2025
};

0 commit comments

Comments
 (0)