-
Notifications
You must be signed in to change notification settings - Fork 37
Added typescript support! #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b073618
feat: Added typescript support!
harazdovskiy 6c64dbd
fix: #160 Added hostname property into `jest-dynamodb-config`
harazdovskiy 483ee9f
feat: Simplified check in `teardown.ts`
harazdovskiy 6c9ba54
fix: Minor fixes - update package.json files section, update export t…
harazdovskiy 6c4e3bd
Merge branch 'feature/typescript-support' of https://github.com/shelf…
harazdovskiy a84cfa9
feat: Updated files section in `package.json`
harazdovskiy 1e2e71e
feat: Updated files section in `package.json`, updated babel and eslint
harazdovskiy 4f0e221
fix: Removed prepack command
harazdovskiy d7cfa22
fix: Removed prepack command
harazdovskiy 781b15e
Merge branch 'feature/typescript-support' of https://github.com/shelf…
harazdovskiy ee274b8
fix: Update package.json
harazdovskiy 6639ba6
fix: Update src/teardown.ts
harazdovskiy ae46deb
doc: #160 Added hostname property into Readme.md
harazdovskiy 1875018
doc: #160 Added hostname property into Readme.md, added config jsdoc …
harazdovskiy d6894e3
feat: Bumped version
harazdovskiy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| lib/ | ||
| renovate.json | ||
| tsconfig.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| .idea/ | ||
| coverage/ | ||
| node_modules/ | ||
| lib/ | ||
| temp | ||
| yarn.lock | ||
| *.log | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,3 @@ | ||
| const {resolve} = require('path'); | ||
| const preset = require('./lib'); | ||
|
|
||
| module.exports = { | ||
| globalSetup: resolve(__dirname, './setup.js'), | ||
| globalTeardown: resolve(__dirname, './teardown.js'), | ||
| testEnvironment: resolve(__dirname, './environment.js'), | ||
| }; | ||
| module.exports = preset; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import {resolve} from 'path'; | ||
|
|
||
| export * from './types'; | ||
|
|
||
| export default { | ||
| globalSetup: resolve(__dirname, './setup.js'), | ||
| globalTeardown: resolve(__dirname, './teardown.js'), | ||
| testEnvironment: resolve(__dirname, './environment.js'), | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import type {ListTablesCommandOutput} from '@aws-sdk/client-dynamodb/dist-types/commands/ListTablesCommand'; | ||
| import type {argValues} from 'dynamodb-local'; | ||
| import DynamoDbLocal from 'dynamodb-local'; | ||
| import {resolve} from 'path'; | ||
| import cwd from 'cwd'; | ||
| import {DynamoDB} from '@aws-sdk/client-dynamodb'; | ||
| import type {CreateTableCommandInput} from '@aws-sdk/client-dynamodb'; | ||
| import type {Config} from './types'; | ||
| import waitForLocalhost from './utils/wait-for-localhost'; | ||
|
|
||
| const debug = require('debug')('jest-dynamodb'); | ||
|
|
||
| const DEFAULT_PORT = 8000; | ||
| const DEFAULT_HOST = 'localhost'; | ||
| const DEFAULT_OPTIONS: argValues[] = ['-sharedDb']; | ||
|
|
||
| export default async function () { | ||
| const { | ||
| tables: newTables, | ||
| clientConfig, | ||
| installerConfig, | ||
| port: port = DEFAULT_PORT, | ||
| hostname: hostname = DEFAULT_HOST, | ||
| options: options = DEFAULT_OPTIONS, | ||
| } = await getConfig(); | ||
|
|
||
| const dynamoDB = new DynamoDB({ | ||
| endpoint: `http://${hostname}:${port}`, | ||
| tls: false, | ||
| region: 'local-env', | ||
| credentials: { | ||
| accessKeyId: 'fakeMyKeyId', | ||
| secretAccessKey: 'fakeSecretAccessKey', | ||
| }, | ||
| ...clientConfig, | ||
| }); | ||
|
|
||
| global.__DYNAMODB_CLIENT__ = dynamoDB; | ||
|
|
||
| try { | ||
| const promises: (Promise<ListTablesCommandOutput> | Promise<void>)[] = [ | ||
| dynamoDB.listTables({}), | ||
| ]; | ||
|
|
||
| if (!global.__DYNAMODB__) { | ||
| promises.push(waitForLocalhost(port, hostname)); | ||
| } | ||
|
|
||
| const [TablesList] = await Promise.all(promises); | ||
| const tableNames = TablesList?.TableNames; | ||
|
|
||
| if (tableNames) { | ||
| await deleteTables(dynamoDB, tableNames); | ||
| } | ||
| } catch (err) { | ||
| // eslint-disable-next-line no-console | ||
| debug(`fallback to launch DB due to ${err}`); | ||
|
|
||
| if (installerConfig) { | ||
| DynamoDbLocal.configureInstaller(installerConfig); | ||
| } | ||
|
|
||
| if (!global.__DYNAMODB__) { | ||
| debug('spinning up a local ddb instance'); | ||
|
|
||
| global.__DYNAMODB__ = await DynamoDbLocal.launch(port, null, options); | ||
| debug(`dynamodb-local started on port ${port}`); | ||
|
|
||
| await waitForLocalhost(port, hostname); | ||
| } | ||
| } | ||
| debug(`dynamodb-local is ready on port ${port}`); | ||
|
|
||
| await createTables(dynamoDB, newTables); | ||
| } | ||
|
|
||
| function createTables(dynamoDB: DynamoDB, tables: CreateTableCommandInput[]) { | ||
| return Promise.all(tables.map(table => dynamoDB.createTable(table))); | ||
| } | ||
|
|
||
| function deleteTables(dynamoDB: DynamoDB, tableNames: string[]) { | ||
| return Promise.all(tableNames.map(tableName => dynamoDB.deleteTable({TableName: tableName}))); | ||
| } | ||
|
|
||
| async function getConfig(): Promise<Config> { | ||
| const path = process.env.JEST_DYNAMODB_CONFIG || resolve(cwd(), 'jest-dynamodb-config.js'); | ||
| const config = require(path); | ||
| debug('config:', config); | ||
|
|
||
| return typeof config === 'function' ? await config() : config; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.