Skip to content

Commit

Permalink
fix!: remove libStorage helper to remove incompatibilities (#105)
Browse files Browse the repository at this point in the history
* fix!: remove libStorage helper

* chore: revert version bump
  • Loading branch information
m-radzikowski authored Jun 26, 2022
1 parent 7ee8044 commit 097d29f
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 224 deletions.
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,16 @@ ddbMock.on(QueryCommand).resolves({

#### Lib Storage Upload

To mock `@aws-sdk/lib-storage` `Upload` you need to call
a helper function `mockLibStorageUpload()`
that will configure required S3Client command mocks:
To mock `@aws-sdk/lib-storage` `Upload` you need to mock
at least two commands: `CreateMultipartUploadCommand` and `UploadPartCommand`
used [under the hood](https://github.com/aws/aws-sdk-js-v3/blob/main/lib/lib-storage/src/Upload.ts):

```typescript
import {mockLibStorageUpload} from 'aws-sdk-client-mock/libStorage';
import {Upload} from '@aws-sdk/lib-storage';
import {S3Client} from '@aws-sdk/client-s3';
import {S3Client, CreateMultipartUploadCommand, UploadPartCommand} from '@aws-sdk/client-s3';

const s3Mock = mockClient(S3Client);
mockLibStorageUpload(s3Mock);
s3Mock.on(CreateMultipartUploadCommand).resolves({UploadId: '1'});
s3Mock.on(UploadPartCommand).resolves({ETag: '1'});

const s3Upload = new Upload({
client: new S3Client({}),
Expand All @@ -283,16 +282,10 @@ s3Upload.on('httpUploadProgress', (progress) => {
await s3Upload.done();
```

When using with Jest, it requires Jest v28.0.0 or higher,
[supporting package exports](https://github.com/facebook/jest/issues/9771).
This way, the `Upload#done()` will complete successfuly.

You can call `mockLibStorageUpload()` without providing an S3Client mock.
In that case, the client mock will be created and returned from the function.
However, you still need to have `@aws-sdk/client-s3` installed as a dependency.

By default, the `@aws-sdk/lib-storage` `Upload#done()` will complete successfuly.
To cause a failure, you need to specify the `rejects()` behavior
of one of the [AWS SDK Commands used under the hood by the `lib-storage`](https://github.com/aws/aws-sdk-js-v3/blob/main/lib/lib-storage/src/Upload.ts).
for one of the AWS SDK Commands used by the `@aws-sdk/lib-storage`.

For uploading a small file (under the defined multipart upload single part size),
`lib-storage` sends a `PutObjectCommand`. To make it fail:
Expand Down
23 changes: 1 addition & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"pretest": "rimraf coverage/",
"test": "jest --coverage",
"test-types": "tsd",
"test-e2e": "ts-node test-e2e/simple/run.ts & ts-node test-e2e/libStorage/run.ts",
"test-e2e": "ts-node test-e2e/simple/run.ts",
"lint": "eslint .",
"typedoc": "typedoc",
"build:cjs": "tsc -p tsconfig.json",
Expand All @@ -36,26 +36,6 @@
"verdaccio": "rimraf verdaccio-storage && verdaccio -c verdaccio.yml",
"local-publish": "npm publish --registry http://localhost:4873/"
},
"exports": {
".": {
"import": "./dist/es/index.js",
"require": "./dist/cjs/index.js"
},
"./libStorage": {
"import": "./dist/es/libStorage.js",
"require": "./dist/cjs/libStorage.js"
}
},
"typesVersions": {
"*": {
"*": [
"dist/types/index.d.ts"
],
"libStorage": [
"dist/types/libStorage.d.ts"
]
}
},
"module": "dist/es/index.js",
"main": "dist/cjs/index.js",
"types": "dist/types/index.d.ts",
Expand All @@ -74,7 +54,6 @@
"@aws-sdk/client-sns": "3.49.0",
"@aws-sdk/client-sqs": "3.49.0",
"@aws-sdk/lib-dynamodb": "3.49.0",
"@aws-sdk/lib-storage": "3.49.0",
"@aws-sdk/types": "3.49.0",
"@commitlint/cli": "13.1.0",
"@commitlint/config-conventional": "13.1.0",
Expand Down
21 changes: 0 additions & 21 deletions src/libStorage.ts

This file was deleted.

5 changes: 0 additions & 5 deletions test-e2e/libStorage/jest.config.js

This file was deleted.

28 changes: 0 additions & 28 deletions test-e2e/libStorage/libStorage.test.ts

This file was deleted.

15 changes: 0 additions & 15 deletions test-e2e/libStorage/run.ts

This file was deleted.

89 changes: 0 additions & 89 deletions test/libStorage.test.ts

This file was deleted.

32 changes: 3 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -564,16 +564,6 @@
"@aws-sdk/util-dynamodb" "3.49.0"
tslib "^2.3.0"

"@aws-sdk/lib-storage@3.49.0":
version "3.49.0"
resolved "https://registry.yarnpkg.com/@aws-sdk/lib-storage/-/lib-storage-3.49.0.tgz#12a0b4afa71604717af6a8c7b8d10d481eb5181c"
integrity sha512-3QIfre3IuAbRKBqqRC6hKQD0caVeP/X/+IlWl205o120MgVPIL8SW/sld6QcLRrrvNjzOT2npfn8i0oPYs8Q+w==
dependencies:
buffer "5.6.0"
events "3.3.0"
stream-browserify "3.0.0"
tslib "^2.3.0"

"@aws-sdk/md5-js@3.49.0":
version "3.49.0"
resolved "https://registry.yarnpkg.com/@aws-sdk/md5-js/-/md5-js-3.49.0.tgz#c9d794c59bb6b7e68b7ff084093c0dafcfd145e4"
Expand Down Expand Up @@ -3310,14 +3300,6 @@ buffer-xor@^1.0.3:
resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9"
integrity sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=

buffer@5.6.0:
version "5.6.0"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.6.0.tgz#a31749dc7d81d84db08abf937b6b8c4033f62786"
integrity sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==
dependencies:
base64-js "^1.0.2"
ieee754 "^1.1.4"

buffer@^4.3.0:
version "4.9.2"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-4.9.2.tgz#230ead344002988644841ab0244af8c44bbe3ef8"
Expand Down Expand Up @@ -4886,7 +4868,7 @@ event-emitter@^0.3.5:
d "1"
es5-ext "~0.10.14"

events@3.3.0, events@^3.0.0:
events@^3.0.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==
Expand Down Expand Up @@ -5839,7 +5821,7 @@ inflight@^1.0.4:
once "^1.3.0"
wrappy "1"

inherits@2, inherits@2.0.4, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.1, inherits@~2.0.3, inherits@~2.0.4:
inherits@2, inherits@2.0.4, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.1, inherits@~2.0.3:
version "2.0.4"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
Expand Down Expand Up @@ -8765,7 +8747,7 @@ read-pkg@^5.2.0:
string_decoder "~1.1.1"
util-deprecate "~1.0.1"

readable-stream@3, readable-stream@^3.0.0, readable-stream@^3.0.2, readable-stream@^3.5.0, readable-stream@^3.6.0:
readable-stream@3, readable-stream@^3.0.0, readable-stream@^3.0.2, readable-stream@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
Expand Down Expand Up @@ -9522,14 +9504,6 @@ steno@^0.4.1:
dependencies:
graceful-fs "^4.1.3"

stream-browserify@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-3.0.0.tgz#22b0a2850cdf6503e73085da1fc7b7d0c2122f2f"
integrity sha512-H73RAHsVBapbim0tU2JwwOiXUj+fikfiaoYAKHF3VJfA0pe2BCzkhAHBlLG6REzE+2WNZcxOXjK7lkso+9euLA==
dependencies:
inherits "~2.0.4"
readable-stream "^3.5.0"

stream-browserify@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.2.tgz#87521d38a44aa7ee91ce1cd2a47df0cb49dd660b"
Expand Down

0 comments on commit 097d29f

Please sign in to comment.