New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jest-dynalite

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-dynalite

Run your tests using Jest & Dynalite

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
35K
increased by1.6%
Maintainers
1
Weekly downloads
 
Created
Source

jest-dynalite

Pipeline status Npm version code style: prettier

Enchaned unit testing, with a mock DynamoDB instance

jest-dynalite is a fork of @shelf/jest-dynamodb, and allows unit tests to execute real queries against a local DynamoDB instance.

Behaviour

jest-dynalite runs a dynalite instance per test runner, which means test runners do not interfear.

jest-dynalite clears tables between tests by default.

Installation

yarn add jest-dynalite -D

Config

In your package root, create a jest-dynalite-config.json with the tables schemas, and an optional basePort to run dynalite on:

{
  "tables": [
    {
      "TableName": "table",
      "KeySchema": [{ "AttributeName": "id", "KeyType": "HASH" }],
      "AttributeDefinitions": [{ "AttributeName": "id", "AttributeType": "S" }],
      "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
      }
    }
  ],
  "basePort": 8000 // optional
}

Update your sourcecode

const client = new DocumentClient({
  ...yourConfig,
  ...(process.env.MOCK_DYNAMODB_ENDPOINT && {
    endpoint: process.env.MOCK_DYNAMODB_ENDPOINT,
    sslEnabled: false,
    region: "local"
  })
});

process.env.MOCK_DYNAMODB_ENDPOINT is unqiue to each test runner.

Jest config

Simple usage (preset)

jest.config.js

module.exports = {
  ...
  preset: "jest-dynalite"
}

The simple preset config will use the config and clear tables between tests by default.

This the recommended usage, unless you have custom setupFilesAfterEnv or testEnvironment set.

More advanced

setup.js

require("jest-dynalite/setupTables");

// Optional (but recommended)
require("jest-dynalite/clearAfterEach");

jest.config.js

module.exports = {
  ...
  testEnvironment: "jest-dynalite/environment",
  setupFilesAfterEnv: ["./setup.js"]
}

This setup should be used if you want to override the default config of clearAfterEach.

Most advanced

Specify the config dir

setupBeforeEnv.js

const { setup } = require("jest-dynalite");

setup(__dirname);

setupAfterEnv.js

const {
  startDb,
  stopDb,
  createTables,
  deleteTables
} = require("jest-dynalite");

beforeAll(startDb);

// Create tables but don't delete them after tests
// beforeAll(createTables);

// Optional
beforeEach(createTables);
afterEach(deleteTables);

afterAll(stopDb);

jest.config.js

module.exports = {
  ...
  setupFiles: ["./setupBeforeEnv.js"],
  setupFilesAfterEnv: ["./setupAfterEnv.js"]
}

This is by far the most complicated setup, but provides the ability to specifiy and environment other than jest-dynalite, and allows you to specify a config directory.

License

MIT

Keywords

FAQs

Package last updated on 14 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc