Skip to content
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

[PR] Overall Typescript refactor #277

Merged
merged 107 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
0619525
feat: Starting to get types rolling out (in-progress).
LuchoTurtle Oct 19, 2022
1648c96
feat: Almost finished typing mock function.
LuchoTurtle Oct 20, 2022
c37eecb
feat: Typing mock function.
LuchoTurtle Oct 24, 2022
5bcbc2e
feat: Typing `remock` function.
LuchoTurtle Oct 24, 2022
075a4a1
feat: Typing `mockService` function.
LuchoTurtle Oct 25, 2022
33fb7d0
fix: Adding stub to type (incomplete)
LuchoTurtle Nov 3, 2022
e407ff3
chore: Attempting to type "wrapTestSTubReplaceFn".
LuchoTurtle Sep 27, 2023
53c0a6b
chore: Add script to run Jest files.
LuchoTurtle Sep 27, 2023
4808cf8
chore: wrapTestStubReplaceFn i snow typed.
LuchoTurtle Sep 27, 2023
705a8d6
chore: Typing `restore` method.
LuchoTurtle Oct 13, 2023
f848b47
chore: Restore all services is now typable.
LuchoTurtle Oct 14, 2023
1aed9f7
chore: `restoreService` is now typed.
LuchoTurtle Oct 14, 2023
b66d92b
chore: Typing `restoreAllMethods`.
LuchoTurtle Oct 14, 2023
5534757
chore: Typing restoreMethod methods.
LuchoTurtle Oct 16, 2023
e112494
chore: Removing "or" string types in functions.
LuchoTurtle Oct 19, 2023
5d24206
chore: Typing promises and operations.
LuchoTurtle Oct 20, 2023
c741259
fix: Typing normal function of `mockServiceMethod`.
LuchoTurtle Oct 21, 2023
ac25ac9
chore: Typing rest of function.
LuchoTurtle Oct 21, 2023
b63747e
chore: Typing promise properly.
LuchoTurtle Oct 21, 2023
937e570
Merge branch 'main' into typescript-refactor
LuchoTurtle Oct 21, 2023
82ea0e7
chore: Updating package-lock.json
LuchoTurtle Oct 21, 2023
9560339
chore: Formatting.
LuchoTurtle Oct 22, 2023
8990855
fix: Fixing Eslint.
LuchoTurtle Oct 22, 2023
fbd471a
fix: Fixing warnings of ESM.
LuchoTurtle Oct 25, 2023
4c019eb
chore: Adding tsup to generate js files.
LuchoTurtle Oct 26, 2023
c3e1464
chore: Adding dist to gitignore.
LuchoTurtle Oct 26, 2023
01f35be
chore: Refactoring tsconfig.json and types.
LuchoTurtle Oct 26, 2023
31357bb
chore: Documenting each function.
LuchoTurtle Oct 26, 2023
d21f63e
chore: Restructuring types.
LuchoTurtle Oct 27, 2023
2975451
chore: Adding gitignore file and removing index.test.d.ts
LuchoTurtle Oct 27, 2023
b058b9c
chore: Trying to fix where the bug is. Switching original `setSDK`, `…
LuchoTurtle Oct 27, 2023
63a9fc1
chore: Switching `remock`.
LuchoTurtle Oct 27, 2023
02b0975
chore: Switching `mockService`.
LuchoTurtle Oct 27, 2023
2371352
fix: Fixing `wrapTestStubReplaceFn`.
LuchoTurtle Oct 27, 2023
8066038
chore: Switching rest of functions except `mockServiceMethod`
LuchoTurtle Oct 27, 2023
383a9e3
fix: Fixing `mockServiceMethod`.
LuchoTurtle Oct 27, 2023
9a9decb
fix: Making types not optional on exported AWS.
LuchoTurtle Oct 27, 2023
3c8909d
fix: Changing tests from .js to .ts and pointing files in package.jso…
LuchoTurtle Oct 27, 2023
f07bec8
chore: Removing type so remock works.
LuchoTurtle Oct 28, 2023
6173ab9
chore: Refactoring more tests.
LuchoTurtle Oct 28, 2023
ce7b43a
fix: Fixing tests using mock and single clients.
LuchoTurtle Oct 30, 2023
ad5b9b3
fix: Importing typescript of jest and tap.
LuchoTurtle Oct 31, 2023
2f54a23
fix: Adding types for `concat-stream` and fixing imports in `index.te…
LuchoTurtle Nov 2, 2023
614486d
chore: Commenting non-working types.
LuchoTurtle Nov 3, 2023
fda68cb
feat: Adding branded primitive type for nested classes and methods.
LuchoTurtle Nov 4, 2023
c94971e
feat: Adding nested client and method types to `mock`, `remock` and `…
LuchoTurtle Nov 4, 2023
c72fd26
chore: Formatting comments.
LuchoTurtle Nov 4, 2023
dfc3f02
chore: General formatting.
LuchoTurtle Nov 4, 2023
0301a63
chore: Fixing errors in tests.
LuchoTurtle Nov 5, 2023
c2ead58
fix: Fixing possible return stub from `mock` type and related types. …
LuchoTurtle Nov 5, 2023
e8ff135
chore: Restructuring files.
LuchoTurtle Nov 5, 2023
0fe4d2c
chore: `is-node-stream` doesn't have types. Removing declaration.
LuchoTurtle Nov 5, 2023
e84a6af
chore: Fix `npm run coverage`.
LuchoTurtle Nov 5, 2023
78edfd9
chore: Adding `build` step and removing unused module in `package.json`.
LuchoTurtle Nov 5, 2023
27ba18e
fix: Commenting out undefined guards to maintain the code close to th…
LuchoTurtle Nov 5, 2023
b0bad36
chore: Formatting code.
LuchoTurtle Nov 5, 2023
2d48345
chore: Refactoring README.
LuchoTurtle Nov 5, 2023
8ace80b
Merge branch 'main' into typescript-refactor
LuchoTurtle Nov 5, 2023
a4e5058
chore: Updating package-lock.json
LuchoTurtle Nov 5, 2023
35d865a
fix: Changing mocked error value in test.
LuchoTurtle Nov 9, 2023
431620f
chore: Ignoring file (can't seem to reach it).
LuchoTurtle Nov 9, 2023
47c2786
Merge branch 'main' into typescript-refactor
LuchoTurtle Nov 9, 2023
186c3a0
fix: Updating package-lock.json
LuchoTurtle Nov 9, 2023
7d1e663
chore: Removing console log.
LuchoTurtle Nov 9, 2023
c80d672
chore: Checking type version to see if it's related.
LuchoTurtle Nov 9, 2023
b601093
Revert "chore: Checking type version to see if it's related."
LuchoTurtle Nov 9, 2023
c75a88b
chore: Changing comment so nyc doesn't include comments as part of code.
LuchoTurtle Nov 9, 2023
4ea9ef0
chore: Removing unused ignore and adding it to uncoverable path.
LuchoTurtle Nov 9, 2023
f5f6e3a
chore: Adding `ts` config for `nyc` and checking if configuration wor…
LuchoTurtle Nov 12, 2023
f52d8de
chore: Setting `check-coverage` to true.
LuchoTurtle Nov 12, 2023
9bc239f
chore: Updating tsconfig.json
LuchoTurtle Feb 25, 2024
e1b291f
Merge branch 'main' into typescript-refactor
LuchoTurtle Feb 25, 2024
a8b6797
chore: Adding "type" in package.json to fix import outside module error.
LuchoTurtle Feb 25, 2024
87a21ac
Revert "chore: Adding "type" in package.json to fix import outside mo…
LuchoTurtle Feb 25, 2024
1b8100e
fix: Adding babel settings, fixing ts errors on index and types. Fixi…
LuchoTurtle Feb 25, 2024
dbea548
fix: Fixing tsc problems.
LuchoTurtle Feb 26, 2024
a15d4c0
chore: Adding comment on tsconfig.
LuchoTurtle Feb 26, 2024
4244032
fix: Using mocha and expectations to switch from jest. One test is fa…
LuchoTurtle Feb 28, 2024
049e16e
chore: Formatting and adding nyc to set thresholds
LuchoTurtle Feb 28, 2024
2989eff
chore: Running afterEach callback.
LuchoTurtle Feb 28, 2024
940928d
fix: Back to using require, all tests passing.
LuchoTurtle Feb 28, 2024
6b90131
fix: FIxing tsd errors in some tests.
LuchoTurtle Feb 29, 2024
be6e7e2
chore: Fixing rest of tsd compiler errors.
LuchoTurtle Feb 29, 2024
c128674
chore: Fixing scripts.
LuchoTurtle Feb 29, 2024
05f28c0
fix: Fixing misc tsd errors.
LuchoTurtle Feb 29, 2024
fb1cdd7
chore: Removing unused dependencies.
LuchoTurtle Feb 29, 2024
e25e175
chore: Removing unneeded dependencies and cleaning up package.json
LuchoTurtle Feb 29, 2024
28b86fa
fix: Fixing build script.
LuchoTurtle Feb 29, 2024
411e3be
chore: Adding README section and upgrading package version.
LuchoTurtle Mar 2, 2024
5a9a7f9
chore: Removing unneeded TODOs.
LuchoTurtle Mar 2, 2024
259cb4f
Revert "chore: Removing unneeded TODOs."
LuchoTurtle Mar 2, 2024
f31ae32
chore: Removing unneeded TODOs.
LuchoTurtle Mar 2, 2024
9f467ab
Merge branch 'main' into typescript-refactor
LuchoTurtle Mar 3, 2024
5a09c0a
conflict: Resolving package-lock.json conflict with main.
LuchoTurtle Mar 3, 2024
de2f647
chore: Updating gitignore.
LuchoTurtle Mar 3, 2024
c3cb774
Merge branch 'main' into typescript-refactor
nelsonic Mar 13, 2024
6597623
update master to main #277
nelsonic Mar 13, 2024
941bce0
link to https://github.com/dwyl/aws-sdk-mock/issues/209#issuecomment-…
nelsonic Mar 13, 2024
1a6a11d
link to https://github.com/dwyl/aws-sdk-mock/issues/209#issuecomment-…
nelsonic Mar 13, 2024
991309b
remove .travis.yml as no longer used. see: https://github.com/dwyl/le…
nelsonic Mar 13, 2024
a97ab9a
Merge branch 'main' into typescript-refactor
LuchoTurtle Apr 7, 2024
f476b60
Merge branch 'main' into typescript-refactor
May 13, 2024
7b4e7a1
chore: Updating package-lock.json
May 13, 2024
877cf5e
Merge branch 'main' into typescript-refactor
LuchoTurtle May 13, 2024
eb0871f
chore: Updating package-lock.json
LuchoTurtle May 13, 2024
e746c83
Typescript Refactor. see: https://github.com/dwyl/aws-sdk-mock/pull/277
LuchoTurtle May 13, 2024
48f745d
Merge branch 'typescript-refactor' of https://github.com/dwyl/aws-sdk…
LuchoTurtle May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
"Buffer": true,
"escape": true
},
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"parserOptions": {
"ecmaVersion": 2017
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
"quotes": [2, "single"],
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: npm i
- run: npm run lint
- run: npm run build
- run: npm test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# Modules
node_modules/

#C overage
coverage/

# Build bundle
dist/

# Misc
.tap/
.DS_Store
.nyc_output
.nyc_output

# Editor
.vscode
12 changes: 12 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,

"include": [
"src/**/*.ts"
],

"check-coverage": true,
"branches": 80,
"lines": 100
}
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

114 changes: 61 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
<div align="center">

# `aws-sdk-mock`
# aws-sdk-mock

AWSome mocks for `JavaScript` `aws-sdk` services.
AWSome mocks for `Javascript` `aws-sdk` services.

[![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)
[![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)
[![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)
[![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/)
[![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)
[![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/)
![npm monthly downloads](https://img.shields.io/npm/dm/aws-sdk-mock?style=flat-square)
[![HitCount](https://hits.dwyl.com/dwyl/aws-sdk-mock.svg?style=flat-square)](http://hits.dwyl.com/dwyl/aws-sdk-mock)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/aws-sdk-mock/issues)

</div>


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.

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.
nelsonic marked this conversation as resolved.
Show resolved Hide resolved
If you are using `AWS SDK v3` you might not _need_ this library, see:
[aws-sdk-mock/issues#209](https://github.com/dwyl/aws-sdk-mock/issues/209#issuecomment-764841699)


If you are *new* to Amazon WebServices Lambda
(*or need a refresher*),
please checkout our our
***Beginners Guide to AWS Lambda***:
<https://github.com/dwyl/learn-aws-lambda>


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

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

## Documentation

### `AWS.mock(service, method, replace)`

Replaces a method on an AWS service with a replacement function or string.

| Param | Type | Optional/Required | Description |
| :------------- | :------------- | :------------- | :------------- |
| `service` | string | Required | AWS service to mock e.g. SNS, DynamoDB, S3 |
| `method` | string | Required | method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB' |
| `replace` | string or function | Required | A string or function to replace the method |

### `AWS.restore(service, method)`

Removes the mock to restore the specified AWS service

| Param | Type | Optional/Required | Description |
| :------------- | :------------- | :------------- | :------------- |
| `service` | string | Optional | AWS service to restore - If only the service is specified, all the methods are restored |
| `method` | string | Optional | Method on AWS service to restore |

If `AWS.restore` is called without arguments (`AWS.restore()`) then all the services and their associated methods are restored
i.e. equivalent to a 'restore all' function.

### `AWS.remock(service, method, replace)`

Updates the `replace` method on an existing mocked service.

| Param | Type | Optional/Required | Description |
| :------------- | :------------- | :------------- | :------------- |
| `service` | string | Required | AWS service to mock e.g. SNS, DynamoDB, S3 |
| `method` | string | Required | method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB' |
| `replace` | string or function | Required | A string or function to replace the method |

### `AWS.setSDK(path)`

Explicitly set the require path for the `aws-sdk`

| Param | Type | Optional/Required | Description |
| :------------- | :------------- | :------------- | :------------- |
| `path` | string | Required | Path to a nested AWS SDK node module |

### `AWS.setSDKInstance(sdk)`

Explicitly set the `aws-sdk` instance to use

| Param | Type | Optional/Required | Description |
| :------------- | :------------- | :------------- | :------------- |
| `sdk` | object | Required | The AWS SDK object |


## *How*? (*Usage*)

### *install* `aws-sdk-mock` from NPM
Expand Down Expand Up @@ -295,56 +353,6 @@ AWS.Promise = Q.Promise;
**/
```

## Documentation

### `AWS.mock(service, method, replace)`

Replaces a method on an AWS service with a replacement function or string.

| Param | Type | Optional/Required | Description |
| :------------- | :------------- | :------------- | :------------- |
| `service` | string | Required | AWS service to mock e.g. SNS, DynamoDB, S3 |
| `method` | string | Required | method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB' |
| `replace` | string or function | Required | A string or function to replace the method |

### `AWS.restore(service, method)`

Removes the mock to restore the specified AWS service

| Param | Type | Optional/Required | Description |
| :------------- | :------------- | :------------- | :------------- |
| `service` | string | Optional | AWS service to restore - If only the service is specified, all the methods are restored |
| `method` | string | Optional | Method on AWS service to restore |

If `AWS.restore` is called without arguments (`AWS.restore()`) then all the services and their associated methods are restored
i.e. equivalent to a 'restore all' function.

### `AWS.remock(service, method, replace)`

Updates the `replace` method on an existing mocked service.

| Param | Type | Optional/Required | Description |
| :------------- | :------------- | :------------- | :------------- |
| `service` | string | Required | AWS service to mock e.g. SNS, DynamoDB, S3 |
| `method` | string | Required | method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB' |
| `replace` | string or function | Required | A string or function to replace the method |

### `AWS.setSDK(path)`

Explicitly set the require path for the `aws-sdk`

| Param | Type | Optional/Required | Description |
| :------------- | :------------- | :------------- | :------------- |
| `path` | string | Required | Path to a nested AWS SDK node module |

### `AWS.setSDKInstance(sdk)`

Explicitly set the `aws-sdk` instance to use

| Param | Type | Optional/Required | Description |
| :------------- | :------------- | :------------- | :------------- |
| `sdk` | object | Required | The AWS SDK object |

## Background Reading

* [Mocking using Sinon.js](http://sinonjs.org/docs/)
Expand Down
64 changes: 0 additions & 64 deletions index.d.ts

This file was deleted.