Jest preset to run LocalStack
$ yarn add @goldsam/jest-localstack --dev
Make sure aws-sdk
is installed as a peer dependency.
module.exports = {
preset: '@goldsam/jest-localstack'
};
// see table below for for additional details
module.exports = {
services: ['dynamodb', 'kinesis'],
showLog: true
};
Property | Type | Default | Description |
---|---|---|---|
image |
string | localstack/localstack |
LocalStack image name. |
readyTimeout |
number | 60000 |
Timeout (ms) to wait for LocalStack to become ready. |
showLog |
boolean | false |
true to output LocalStack log to stdout; false to suppress log output. |
services |
string|string[] | undefined |
Comma delimited list or array of service names to mock; null or undefined mocks all supported services. |
dynamoTables |
Object[] | undefined |
Array of Create Table parameters. |
// This example only uses DynamoDB
const {DocumentClient} = require('aws-sdk/clients/dynamodb');
const isTest = process.env.JEST_WORKER_ID;
const config = {
convertEmptyValues: true,
...(isTest && {endpoint: 'localhost:4569', sslEnabled: false, region: 'local-env'})
};
const ddb = new DocumentClient(config);
it('should insert item into table', async () => {
await ddb.put({TableName: 'files', Item: {id: '1', hello: 'world'}}).promise();
const {Item} = await ddb.get({TableName: 'files', Key: {id: '1'}}).promise();
expect(Item).toEqual({
id: '1',
hello: 'world'
});
});
MIT © Sam Goldmann 2019