Skip to content

Commit d9fc691

Browse files
authored
Merge pull request #277 from dwyl/typescript-refactor
[PR] Overall Typescript refactor
2 parents 59421aa + 48f745d commit d9fc691

16 files changed

+5594
-18781
lines changed

.eslintrc.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
"Buffer": true,
88
"escape": true
99
},
10+
"parser": "@typescript-eslint/parser",
11+
"plugins": [
12+
"@typescript-eslint"
13+
],
1014
"parserOptions": {
11-
"ecmaVersion": 2017
15+
"ecmaVersion": 2020,
16+
"sourceType": "module"
1217
},
1318
"rules": {
1419
"quotes": [2, "single"],

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
node-version: ${{ matrix.node-version }}
2121
- run: npm i
2222
- run: npm run lint
23+
- run: npm run build
2324
- run: npm test
2425
- name: Upload coverage to Codecov
2526
uses: codecov/codecov-action@v4

.gitignore

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1+
# Modules
12
node_modules/
3+
4+
#C overage
25
coverage/
6+
7+
# Build bundle
8+
dist/
9+
10+
# Misc
11+
.tap/
312
.DS_Store
4-
.nyc_output
13+
.nyc_output
14+
15+
# Editor
16+
.vscode

.nycrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "@istanbuljs/nyc-config-typescript",
3+
"all": true,
4+
5+
"include": [
6+
"src/**/*.ts"
7+
],
8+
9+
"check-coverage": true,
10+
"branches": 80,
11+
"lines": 100
12+
}

.travis.yml

-6
This file was deleted.

README.md

+61-53
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
<div align="center">
22

3-
# `aws-sdk-mock`
3+
# aws-sdk-mock
44

5-
AWSome mocks for `JavaScript` `aws-sdk` services.
5+
AWSome mocks for `Javascript` `aws-sdk` services.
66

77
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/dwyl/aws-sdk-mock/ci.yml?label=build&style=flat-square&branch=main)](https://github.com/dwyl/aws-sdk-mock/actions/workflows/ci.yml)
88
[![codecov.io](https://img.shields.io/codecov/c/github/dwyl/aws-sdk-mock/main.svg?style=flat-square)](http://codecov.io/github/dwyl/aws-sdk-mock?branch=main)
99
[![Known Vulnerabilities](https://snyk.io/test/github/dwyl/aws-sdk-mock/badge.svg?targetFile=package.json&style=flat-square)](https://snyk.io/test/github/dwyl/aws-sdk-mock?targetFile=package.json)
10-
[![Node.js Version](https://img.shields.io/node/v/aws-sdk-mock.svg?style=flat-square "Node.js 18.x, 20.x & 21.x supported")](http://nodejs.org/download/)
1110
[![npm package version](https://img.shields.io/npm/v/aws-sdk-mock.svg?style=flat-square&color=bright-green)](https://www.npmjs.com/package/aws-sdk-mock)
11+
[![Node.js Version](https://img.shields.io/node/v/aws-sdk-mock.svg?style=flat-square "Node.js 18.x, 20.x & 21.x supported")](http://nodejs.org/download/)
1212
![npm monthly downloads](https://img.shields.io/npm/dm/aws-sdk-mock?style=flat-square)
1313
[![HitCount](https://hits.dwyl.com/dwyl/aws-sdk-mock.svg?style=flat-square)](http://hits.dwyl.com/dwyl/aws-sdk-mock)
1414
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/aws-sdk-mock/issues)
1515

1616
</div>
1717

18+
1819
This module was created to help test AWS Lambda functions but can be used in any situation where the AWS SDK needs to be mocked.
1920

21+
This library is best suited for `AWS SDK for Javascript (v2)` - see the [introductory post on the AWS blog](https://aws.amazon.com/blogs/developer/mocking-modular-aws-sdk-for-javascript-v3-in-unit-tests/) for more context.
22+
If you are using `AWS SDK v3` you might not _need_ this library, see:
23+
[aws-sdk-mock/issues#209](https://github.com/dwyl/aws-sdk-mock/issues/209#issuecomment-764841699)
24+
25+
2026
If you are *new* to Amazon WebServices Lambda
2127
(*or need a refresher*),
2228
please checkout our our
2329
***Beginners Guide to AWS Lambda***:
2430
<https://github.com/dwyl/learn-aws-lambda>
2531

32+
2633
* [Why](#why)
2734
* [What](#what)
2835
* [Getting Started](#how)
@@ -39,6 +46,57 @@ Using stubs means you can prevent a specific method from being called directly.
3946

4047
Uses [Sinon.js](https://sinonjs.org/) under the hood to mock the AWS SDK services and their associated methods.
4148

49+
## Documentation
50+
51+
### `AWS.mock(service, method, replace)`
52+
53+
Replaces a method on an AWS service with a replacement function or string.
54+
55+
| Param | Type | Optional/Required | Description |
56+
| :------------- | :------------- | :------------- | :------------- |
57+
| `service` | string | Required | AWS service to mock e.g. SNS, DynamoDB, S3 |
58+
| `method` | string | Required | method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB' |
59+
| `replace` | string or function | Required | A string or function to replace the method |
60+
61+
### `AWS.restore(service, method)`
62+
63+
Removes the mock to restore the specified AWS service
64+
65+
| Param | Type | Optional/Required | Description |
66+
| :------------- | :------------- | :------------- | :------------- |
67+
| `service` | string | Optional | AWS service to restore - If only the service is specified, all the methods are restored |
68+
| `method` | string | Optional | Method on AWS service to restore |
69+
70+
If `AWS.restore` is called without arguments (`AWS.restore()`) then all the services and their associated methods are restored
71+
i.e. equivalent to a 'restore all' function.
72+
73+
### `AWS.remock(service, method, replace)`
74+
75+
Updates the `replace` method on an existing mocked service.
76+
77+
| Param | Type | Optional/Required | Description |
78+
| :------------- | :------------- | :------------- | :------------- |
79+
| `service` | string | Required | AWS service to mock e.g. SNS, DynamoDB, S3 |
80+
| `method` | string | Required | method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB' |
81+
| `replace` | string or function | Required | A string or function to replace the method |
82+
83+
### `AWS.setSDK(path)`
84+
85+
Explicitly set the require path for the `aws-sdk`
86+
87+
| Param | Type | Optional/Required | Description |
88+
| :------------- | :------------- | :------------- | :------------- |
89+
| `path` | string | Required | Path to a nested AWS SDK node module |
90+
91+
### `AWS.setSDKInstance(sdk)`
92+
93+
Explicitly set the `aws-sdk` instance to use
94+
95+
| Param | Type | Optional/Required | Description |
96+
| :------------- | :------------- | :------------- | :------------- |
97+
| `sdk` | object | Required | The AWS SDK object |
98+
99+
42100
## *How*? (*Usage*)
43101

44102
### *install* `aws-sdk-mock` from NPM
@@ -295,56 +353,6 @@ AWS.Promise = Q.Promise;
295353
**/
296354
```
297355

298-
## Documentation
299-
300-
### `AWS.mock(service, method, replace)`
301-
302-
Replaces a method on an AWS service with a replacement function or string.
303-
304-
| Param | Type | Optional/Required | Description |
305-
| :------------- | :------------- | :------------- | :------------- |
306-
| `service` | string | Required | AWS service to mock e.g. SNS, DynamoDB, S3 |
307-
| `method` | string | Required | method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB' |
308-
| `replace` | string or function | Required | A string or function to replace the method |
309-
310-
### `AWS.restore(service, method)`
311-
312-
Removes the mock to restore the specified AWS service
313-
314-
| Param | Type | Optional/Required | Description |
315-
| :------------- | :------------- | :------------- | :------------- |
316-
| `service` | string | Optional | AWS service to restore - If only the service is specified, all the methods are restored |
317-
| `method` | string | Optional | Method on AWS service to restore |
318-
319-
If `AWS.restore` is called without arguments (`AWS.restore()`) then all the services and their associated methods are restored
320-
i.e. equivalent to a 'restore all' function.
321-
322-
### `AWS.remock(service, method, replace)`
323-
324-
Updates the `replace` method on an existing mocked service.
325-
326-
| Param | Type | Optional/Required | Description |
327-
| :------------- | :------------- | :------------- | :------------- |
328-
| `service` | string | Required | AWS service to mock e.g. SNS, DynamoDB, S3 |
329-
| `method` | string | Required | method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB' |
330-
| `replace` | string or function | Required | A string or function to replace the method |
331-
332-
### `AWS.setSDK(path)`
333-
334-
Explicitly set the require path for the `aws-sdk`
335-
336-
| Param | Type | Optional/Required | Description |
337-
| :------------- | :------------- | :------------- | :------------- |
338-
| `path` | string | Required | Path to a nested AWS SDK node module |
339-
340-
### `AWS.setSDKInstance(sdk)`
341-
342-
Explicitly set the `aws-sdk` instance to use
343-
344-
| Param | Type | Optional/Required | Description |
345-
| :------------- | :------------- | :------------- | :------------- |
346-
| `sdk` | object | Required | The AWS SDK object |
347-
348356
## Background Reading
349357

350358
* [Mocking using Sinon.js](http://sinonjs.org/docs/)

index.d.ts

-64
This file was deleted.

0 commit comments

Comments
 (0)