{"_id":"@0xflick/jest-dynamodb","_rev":"2-a7f1b66e1dd701d2030901abcb1a6b7a","name":"@0xflick/jest-dynamodb","dist-tags":{"latest":"4.0.1-pre.3"},"versions":{"4.0.1-pre.2":{"name":"@0xflick/jest-dynamodb","version":"4.0.1-pre.2","keywords":["dynamodb","dynamodb local","jest","jest environment","jest preset"],"author":{"url":"shelf.io","name":"Vlad Holubiev","email":"vlad@shelf.io"},"license":"MIT","_id":"@0xflick/jest-dynamodb@4.0.1-pre.2","maintainers":[{"name":"0xflick","email":"cmdrnft@protonmail.com"}],"homepage":"https://github.com/shelfio/jest-dynamodb#readme","bugs":{"url":"https://github.com/shelfio/jest-dynamodb/issues"},"dist":{"shasum":"bf65554f053d3592357ad43453b9a8525525e642","tarball":"https://registry.npmjs.org/@0xflick/jest-dynamodb/-/jest-dynamodb-4.0.1-pre.2.tgz","fileCount":22,"integrity":"sha512-2r7j3H4ddQD98dmnTuG/nTyhwJ7BlTaAmOzBi3JrlE5CE6bHqzoA3uDBq/T0iZ4epGmrAbqWDqPaSx/MDd8wJw==","signatures":[{"sig":"MEQCIFY1nFOZ7VTB7qul3fQoGgHv7J4JXyPPTwkEBRUn9QZ7AiA5/32OTN8VDQlpIxdvOmLbWf16KQywa3SVD8SJF6DUAg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":21927},"jest":{"preset":"./jest-preset.js"},"babel":{"extends":"@shelf/babel-config/backend"},"engines":{"node":">=22"},"gitHead":"815249e91b90b67ef6df6b85e3c66334c96d3d37","scripts":{"lint":"yarn lint:ci --fix","test":"export ENVIRONMENT=local && jest tests","build":"rm -rf lib/ && yarn build:types && babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts'","lint:ci":"eslint . --quiet","prepack":"yarn build","coverage":"jest --coverage","type-check":"tsc --noEmit","build:types":"tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib","type-check:watch":"npm run type-check -- --watch"},"_npmUser":{"name":"0xflick","email":"cmdrnft@protonmail.com"},"prettier":"@shelf/prettier-config","repository":{"url":"git+https://github.com/shelfio/jest-dynamodb.git","type":"git"},"_npmVersion":"10.9.2","description":"Run your tests using Jest & DynamoDB local","directories":{},"lint-staged":{"*.{ts,js,json}":["eslint --fix"],"*.{html,md,yml}":["prettier --write"]},"_nodeVersion":"22.14.0","dependencies":{"cwd":"0.10.0","debug":"4.3.4","dynamodb-local":"0.0.34","@aws-sdk/lib-dynamodb":"3.624.0","@aws-sdk/util-dynamodb":"3.624.0","@aws-sdk/client-dynamodb":"3.624.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"29.7.0","husky":"8.0.3","eslint":"9.24.0","prettier":"3.5.3","@babel/cli":"7.27.0","@types/cwd":"^0.10.2","typescript":"5.8.3","@babel/core":"7.26.10","@types/jest":"29.5.14","@types/node":"22","lint-staged":"13.3.0","@types/aws-sdk":"2.7.4","@shelf/tsconfig":"0.1.0","@shelf/babel-config":"1.2.0","@shelf/eslint-config":"4.2.1","@shelf/prettier-config":"1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/jest-dynamodb_4.0.1-pre.2_1744953879419_0.38271024244764185","host":"s3://npm-registry-packages-npm-production"}},"4.0.1-pre.3":{"name":"@0xflick/jest-dynamodb","version":"4.0.1-pre.3","description":"Run your tests using Jest & DynamoDB local","keywords":["dynamodb","dynamodb local","jest","jest environment","jest preset"],"repository":{"type":"git","url":"https://github.com/shelfio/jest-dynamodb.git"},"license":"MIT","author":{"name":"Vlad Holubiev","email":"vlad@shelf.io","url":"shelf.io"},"scripts":{"build":"rm -rf lib/ && yarn build:types && babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts'","build:types":"tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib","coverage":"jest --coverage","lint":"yarn lint:ci --fix","lint:ci":"eslint . --quiet","prepack":"yarn build","test":"export ENVIRONMENT=local && jest tests","type-check":"tsc --noEmit","type-check:watch":"npm run type-check -- --watch"},"lint-staged":{"*.{html,md,yml}":["prettier --write"],"*.{ts,js,json}":["eslint --fix"]},"babel":{"extends":"@shelf/babel-config/backend"},"prettier":"@shelf/prettier-config","jest":{"preset":"./jest-preset.js"},"dependencies":{"@aws-sdk/client-dynamodb":"^3.624.0","@aws-sdk/lib-dynamodb":"^3.624.0","@aws-sdk/util-dynamodb":"^3.624.0","cwd":"0.10.0","debug":"4.3.4","dynamodb-local":"0.0.34"},"devDependencies":{"@babel/cli":"7.27.0","@babel/core":"7.26.10","@shelf/babel-config":"1.2.0","@shelf/eslint-config":"4.2.1","@shelf/prettier-config":"1.0.0","@shelf/tsconfig":"0.1.0","@types/aws-sdk":"2.7.4","@types/cwd":"^0.10.2","@types/jest":"29.5.14","@types/node":"22","eslint":"9.24.0","husky":"8.0.3","jest":"29.7.0","lint-staged":"13.3.0","prettier":"3.5.3","typescript":"5.8.3"},"engines":{"node":">=22"},"publishConfig":{"access":"public"},"licenseText":"MIT License\n\nCopyright (c) Gemshelf Inc. (shelf.io)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"@0xflick/jest-dynamodb@4.0.1-pre.3","dist":{"shasum":"f1ebe9c49b553fe36cfb4ce754c69cd8c9f99804","integrity":"sha512-guPMnHXXUtH86mfNqR1RzmKpEJztMVAaPQ72D3/LXJYWBKK3jaTu0cRPCcd0pmL/OZNrpyZD0HUuMSIPLVQpwg==","tarball":"https://registry.npmjs.org/@0xflick/jest-dynamodb/-/jest-dynamodb-4.0.1-pre.3.tgz","fileCount":29,"unpackedSize":22597,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCyE9WqxGYy5FbzRw3M60BiGBroXCHgp8Vu8uHxW7s8twIhAKFQsevi6j7mfwF+9R63T6zcGPe/DrBCf9Dkh8jzgEit"}]},"_npmUser":{"name":"0xflick","email":"cmdrnft@protonmail.com"},"directories":{},"maintainers":[{"name":"0xflick","email":"cmdrnft@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/jest-dynamodb_4.0.1-pre.3_1745212813323_0.5070645899312576"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-18T05:24:39.342Z","modified":"2025-04-21T05:20:13.683Z","4.0.1-pre.2":"2025-04-18T05:24:39.600Z","4.0.1-pre.3":"2025-04-21T05:20:13.519Z"},"author":{"name":"Vlad Holubiev","email":"vlad@shelf.io","url":"shelf.io"},"license":"MIT","keywords":["dynamodb","dynamodb local","jest","jest environment","jest preset"],"repository":{"type":"git","url":"https://github.com/shelfio/jest-dynamodb.git"},"description":"Run your tests using Jest & DynamoDB local","maintainers":[{"name":"0xflick","email":"cmdrnft@protonmail.com"}],"readme":"# jest-dynamodb [![CircleCI](https://circleci.com/gh/shelfio/jest-dynamodb/tree/master.svg?style=svg)](https://circleci.com/gh/shelfio/jest-dynamodb/tree/master) ![](https://img.shields.io/badge/code_style-prettier-ff69b4.svg) [![npm (scoped)](https://img.shields.io/npm/v/@shelf/jest-dynamodb.svg)](https://www.npmjs.com/package/@shelf/jest-dynamodb)\n\n> Jest preset to run DynamoDB Local\n\n## Usage\n\n### 0. Install\n\n```\n$ yarn add @shelf/jest-dynamodb --dev\n```\n\nMake sure `java` runtime available for running [DynamoDBLocal.jar](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html)\n\n### 1. Create `jest.config.js`\n\n```js\nmodule.exports = {\n  preset: '@shelf/jest-dynamodb',\n};\n```\n\n### 2. Create `jest-dynamodb-config.js`\n\n#### 2.1 Properties\n\n##### tables\n\n- Type: `object[]`\n- Required: `true`\n\nArray of createTable params.\n\n- [Create Table API](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#createTable-property).\n\n##### port\n\n- Type: `number`\n- Required: `false`\n\nPort number. The default port number is `8000`.\n\n##### hostname\n\n- Type: `string`\n- Required: `false`\n\nHostname. The default hostname is `localhost`.\n\n##### options\n\n- Type: `string[]`\n- Required: `false`\n\nAdditional arguments for dynamodb-local. The default value is `['-sharedDb']`.\n\n- [dynamodb-local](https://github.com/rynop/dynamodb-local)\n- [DynamoDB Local Usage Notes](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.UsageNotes.html)\n\n##### clientConfig\n\n- Type: `object`\n- Required: `false`\n\nConstructor params of DynamoDB client.\n\n- [Constructor Property](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#constructor-property)\n\n##### installerConfig\n\n- Type: `{installPath?: string, downloadUrl?: string}`\n- Required: `false`\n\n- `installPath` defines the location where dynamodb-local is installed or will be installed.\n- `downloadUrl` defines the url of dynamodb-local package.\n\nThe default value is defined at https://github.com/rynop/dynamodb-local/blob/2e6c1cb2edde4de0dc51a71c193c510b939d4352/index.js#L16-L19\n\n#### 2.2 Examples\n\nYou can set up tables as an object:\n > Whole list of config properties can be found [here](https://github.com/shelfio/jest-dynamodb/blob/6c64dbd4ee5a68230469ea14cbfb814470521197/src/types.ts#L80-L87)\n```js\n/**\n * @type {import('@shelf/jest-dynamodb/lib').Config}')}\n */\nconst config = {\n  tables: [\n    {\n      TableName: `files`,\n      KeySchema: [{AttributeName: 'id', KeyType: 'HASH'}],\n      AttributeDefinitions: [{AttributeName: 'id', AttributeType: 'S'}],\n      ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1},\n    },\n    // etc\n  ],\n  port: 8000,\n};\nmodule.exports = config;\n```\n\nOr as an async function (particularly useful when resolving DynamoDB setup dynamically from `serverless.yml`):\n\n```js\nmodule.exports = async () => {\n  const serverless = new (require('serverless'))();\n  // If using monorepo where DynamoDB serverless.yml is in another directory\n  // const serverless = new (require('serverless'))({ servicePath: '../../../core/data' });\n\n  await serverless.init();\n  const service = await serverless.variables.populateService();\n  const resources = service.resources.filter(r => Object.keys(r).includes('Resources'))[0];\n\n  const tables = Object.keys(resources)\n    .map(name => resources[name])\n    .filter(r => r.Type === 'AWS::DynamoDB::Table')\n    .map(r => r.Properties);\n\n  return {\n    tables,\n    port: 8000,\n  };\n};\n```\n\nOr read table definitions from a CloudFormation template (example handles a !Sub on TableName, i.e. TableName: !Sub \"\\${env}-users\" ):\n\n```js\nconst yaml = require('js-yaml');\nconst fs = require('fs');\nconst {CLOUDFORMATION_SCHEMA} = require('cloudformation-js-yaml-schema');\n\nmodule.exports = async () => {\n  const cf = yaml.load(fs.readFileSync('../cf-templates/example-stack.yaml', 'utf8'), {\n    schema: CLOUDFORMATION_SCHEMA,\n  });\n  var tables = [];\n  Object.keys(cf.Resources).forEach(item => {\n    tables.push(cf.Resources[item]);\n  });\n\n  tables = tables\n    .filter(r => r.Type === 'AWS::DynamoDB::Table')\n    .map(r => {\n      let table = r.Properties;\n      if (typeof r.TableName === 'object') {\n        table.TableName = table.TableName.data.replace('${env}', 'test');\n      }\n      delete table.TimeToLiveSpecification; //errors on dynamo-local\n      return table;\n    });\n\n  return {\n    tables,\n    port: 8000,\n  };\n};\n```\n\n### 3.1 Configure DynamoDB client (from aws-sdk v2)\n\n```js\nconst {DocumentClient} = require('aws-sdk/clients/dynamodb');\n\nconst isTest = process.env.JEST_WORKER_ID;\nconst config = {\n  convertEmptyValues: true,\n  ...(isTest && {\n    endpoint: 'localhost:8000',\n    sslEnabled: false,\n    region: 'local-env',\n    credentials: {\n      accessKeyId: 'fakeMyKeyId',\n      secretAccessKey: 'fakeSecretAccessKey',\n    },\n  }),\n};\n\nconst ddb = new DocumentClient(config);\n```\n\n### 3.2 Configure DynamoDB client (from aws-sdk v3)\n\n```js\nconst {DynamoDB} = require('@aws-sdk/client-dynamodb');\nconst {DynamoDBDocument} = require('@aws-sdk/lib-dynamodb');\n\nconst isTest = process.env.JEST_WORKER_ID;\n\nconst ddb = DynamoDBDocument.from(\n  new DynamoDB({\n    ...(isTest && {\n      endpoint: 'http://localhost:8000',\n      region: 'local-env',\n      credentials: {\n        accessKeyId: 'fakeMyKeyId',\n        secretAccessKey: 'fakeSecretAccessKey',\n      },\n    }),\n  }),\n  {\n    marshallOptions: {\n      convertEmptyValues: true,\n    },\n  }\n);\n```\n\n### 4. PROFIT! Write tests\n\n```js\nit('should insert item into table', async () => {\n  await ddb.put({TableName: 'files', Item: {id: '1', hello: 'world'}}).promise();\n\n  const {Item} = await ddb.get({TableName: 'files', Key: {id: '1'}}).promise();\n\n  expect(Item).toEqual({\n    id: '1',\n    hello: 'world',\n  });\n});\n```\n\n## Monorepo Support\n\nBy default the `jest-dynamodb-config.js` is read from `cwd` directory, but this might not be suitable for monorepos with nested [jest projects](https://jestjs.io/docs/configuration#projects-arraystring--projectconfig) with nested `jest.config.*` files nested in subdirectories.\n\nIf your `jest-dynamodb-config.js` file is not located at `{cwd}/jest-dynamodb-config.js` or you are using nested `jest projects`, you can define the environment variable `JEST_DYNAMODB_CONFIG` with the absolute path of the respective `jest-dynamodb-config.js` file.\n\n### Example Using `JEST_DYNAMODB_CONFIG` in nested project\n\n```\n// src/nested/project/jest.config.js\nconst path = require('path');\n\n// Define path of project level config - extension not required as file will be imported via `require(process.env.JEST_DYNAMODB_CONFIG)`\nprocess.env.JEST_DYNAMODB_CONFIG = path.resolve(__dirname, './jest-dynamodb-config');\n\nmodule.exports = {\n  preset: '@shelf/jest-dynamodb'\n  displayName: 'nested-project',\n};\n```\n\n## Troubleshooting\n\n<details>\n<summary>UnknownError: Not Found</summary>\n\nPerhaps something is using your port specified in `jest-dynamodb-config.js`.\n\n</details>\n\n<details>\n<summary>com.almworks.sqlite4java.Internal log WARNING: [sqlite] cannot open DB[1]:</summary>\n\nSee https://www.josephso.dev/using-jest-dynamodb-in-apple-silicon-platform-workaround/#community-build\n\n</details>\n\n## Alternatives\n\n- [jest-dynalite](https://github.com/freshollie/jest-dynalite) - a much lighter version which spins up an instance for each runner & doesn't depend on Java\n\n## Read\n\n- [dynamodb-local](https://github.com/rynop/dynamodb-local)\n- [DynamoDB Local Usage Notes](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.UsageNotes.html)\n- [Create Table API](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#createTable-property)\n\n## Used by\n\n- [dynamodb-parallel-scan](https://github.com/shelfio/dynamodb-parallel-scan)\n- [@nasa-gcn/dynamodb-autoincrement](https://github.com/nasa-gcn/dynamodb-autoincrement)\n\n## See Also\n\n- [jest-mongodb](https://github.com/shelfio/jest-mongodb)\n\n## Publish\n\n```sh\n$ git checkout master\n$ yarn version\n$ yarn publish\n$ git push origin master --tags\n```\n\n## License\n\nMIT © [Shelf](https://shelf.io)\n","readmeFilename":"readme.md"}