Skip to content

Commit e20954c

Browse files
authored
Merge pull request #164 from shelfio/feature/typescript-support
Added typescript support!
2 parents f59e20c + d6894e3 commit e20954c

17 files changed

+273
-114
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jobs:
99
steps:
1010
- checkout
1111
- run: yarn
12+
- run: yarn build
1213
- run: yarn test
1314

1415
test_with_db:
@@ -20,6 +21,7 @@ jobs:
2021
steps:
2122
- checkout
2223
- run: yarn
24+
- run: yarn build
2325
- run: yarn test
2426

2527
workflows:

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lib/
2+
renovate.json
3+
tsconfig.json

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea/
22
coverage/
33
node_modules/
4+
lib/
45
temp
56
yarn.lock
67
*.log

jest-dynamodb-config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = {
1+
/**
2+
* @type {import('./lib/types').Config}
3+
*/
4+
const config = {
25
tables: [
36
{
47
TableName: `files`,
@@ -16,3 +19,5 @@ module.exports = {
1619
port: 8000,
1720
options: ['-sharedDb'],
1821
};
22+
23+
module.exports = config;

jest-preset.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
const {resolve} = require('path');
1+
const preset = require('./lib');
22

3-
module.exports = {
4-
globalSetup: resolve(__dirname, './setup.js'),
5-
globalTeardown: resolve(__dirname, './teardown.js'),
6-
testEnvironment: resolve(__dirname, './environment.js'),
7-
};
3+
module.exports = preset;

package.json

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shelf/jest-dynamodb",
3-
"version": "3.2.0",
3+
"version": "3.3.0",
44
"description": "Run your tests using Jest & DynamoDB local",
55
"keywords": [
66
"dynamodb",
@@ -17,23 +17,25 @@
1717
"url": "shelf.io"
1818
},
1919
"files": [
20-
"environment.js",
2120
"jest-preset.js",
22-
"setup.js",
23-
"teardown.js",
24-
"wait-for-localhost.js"
21+
"lib/"
2522
],
2623
"scripts": {
24+
"build": "rm -rf lib/ && yarn build:types && babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts'",
25+
"build:types": "tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib",
2726
"coverage": "jest --coverage",
2827
"lint": "eslint . --ext .js,.ts,.json --fix",
2928
"lint:ci": "eslint . --ext .js,.ts,.json",
30-
"test": "export ENVIRONMENT=local && jest ."
29+
"prepack": "yarn build",
30+
"test": "export ENVIRONMENT=local && jest tests",
31+
"type-check": "tsc --noEmit",
32+
"type-check:watch": "npm run type-check -- --watch"
3133
},
3234
"lint-staged": {
3335
"*.{html,md,yml}": [
3436
"prettier --write"
3537
],
36-
"*.{js,json}": [
38+
"*.{ts,js,json}": [
3739
"eslint --fix"
3840
]
3941
},
@@ -53,10 +55,17 @@
5355
"dynamodb-local": "0.0.31"
5456
},
5557
"devDependencies": {
56-
"@shelf/babel-config": "1.0.2",
57-
"@shelf/eslint-config": "2.18.0",
58+
"@babel/cli": "7.18.9",
59+
"@babel/core": "7.18.9",
60+
"@shelf/babel-config": "1.2.0",
61+
"@shelf/eslint-config": "2.22.0",
5862
"@shelf/prettier-config": "1.0.0",
59-
"eslint": "8.20.0",
63+
"@shelf/tsconfig": "0.0.8",
64+
"@types/aws-sdk": "2.7.0",
65+
"@types/cwd": "^0.10.0",
66+
"@types/jest": "28.1.3",
67+
"@types/node": "16",
68+
"eslint": "8.21.0",
6069
"husky": "8.0.1",
6170
"jest": "28.1.3",
6271
"lint-staged": "13.0.3",

readme.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ Array of createTable params.
4040

4141
Port number. The default port number is `8000`.
4242

43+
##### hostname
44+
45+
- Type: `string`
46+
- Required: `false`
47+
48+
Port number. The default hostname number is `localhost`.
49+
4350
##### options
4451

4552
- Type: `string[]`
@@ -72,9 +79,12 @@ The default value is defined at https://github.com/rynop/dynamodb-local/blob/2e6
7279
#### 2.2 Examples
7380

7481
You can set up tables as an object:
75-
82+
> Whole list of config properties can be found [here](https://github.com/shelfio/jest-dynamodb/blob/6c64dbd4ee5a68230469ea14cbfb814470521197/src/types.ts#L80-L87)
7683
```js
77-
module.exports = {
84+
/**
85+
* @type {import('@shelf/jest-dynamodb/lib').Config}')}
86+
*/
87+
const config = {
7888
tables: [
7989
{
8090
TableName: `files`,
@@ -86,6 +96,7 @@ module.exports = {
8696
],
8797
port: 8000,
8898
};
99+
module.exports = config;
89100
```
90101

91102
Or as an async function (particularly useful when resolving DynamoDB setup dynamically from `serverless.yml`):

setup.js

Lines changed: 0 additions & 73 deletions
This file was deleted.

environment.js renamed to src/environment.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/* eslint-disable no-console */
2-
const {TestEnvironment} = require('jest-environment-node');
2+
import type {EnvironmentContext} from '@jest/environment';
3+
import type {JestEnvironmentConfig} from '@jest/environment';
4+
import {TestEnvironment} from 'jest-environment-node';
5+
36
const debug = require('debug')('jest-dynamodb');
47

58
module.exports = class DynamoDBEnvironment extends TestEnvironment {
6-
constructor(config) {
7-
super(config);
9+
constructor(config: JestEnvironmentConfig, context: EnvironmentContext) {
10+
super(config, context);
811
}
912

1013
async setup() {
@@ -19,7 +22,9 @@ module.exports = class DynamoDBEnvironment extends TestEnvironment {
1922
await super.teardown();
2023
}
2124

25+
// @ts-ignore
2226
runScript(script) {
27+
// @ts-ignore
2328
return super.runScript(script);
2429
}
2530
};

src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {resolve} from 'path';
2+
3+
export * from './types';
4+
5+
export default {
6+
globalSetup: resolve(__dirname, './setup.js'),
7+
globalTeardown: resolve(__dirname, './teardown.js'),
8+
testEnvironment: resolve(__dirname, './environment.js'),
9+
};

0 commit comments

Comments
 (0)