Skip to content

Commit f810679

Browse files
authored
chore(deps-dev): bump jest to 28.1.1 (#3732)
* chore(deps-dev): bump jest to 28.1.1 * chore(workspaces): nohoist @babel to fix missing dep @babel/traverse error * test: update unit test for jest 28 * test(lib-storage): speed up assertion of 5MB buffer
1 parent d2833dd commit f810679

File tree

7 files changed

+730
-718
lines changed

7 files changed

+730
-718
lines changed

lib/lib-storage/src/Upload.spec.ts

+29-9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jest.mock("@aws-sdk/client-s3", () => ({
5151
}));
5252

5353
import { CompleteMultipartUploadCommandOutput, S3 } from "@aws-sdk/client-s3";
54+
import { createHash } from "crypto";
5455
import { Readable } from "stream";
5556

5657
import { Progress, Upload } from "./index";
@@ -76,6 +77,24 @@ describe(Upload.name, () => {
7677
Body: "this-is-a-sample-payload",
7778
};
7879

80+
expect.extend({
81+
toHaveSameHashAsBuffer: (received: Uint8Array, expected: Uint8Array) => {
82+
const receivedHash = createHash("sha256").update(received).digest("hex");
83+
const expectHash = createHash("sha256").update(expected).digest("hex");
84+
if (expectHash === receivedHash) {
85+
return {
86+
message: () => "received buffer has the correct hash",
87+
pass: true,
88+
};
89+
} else {
90+
return {
91+
message: () => `received buffer hash is incorrect, expect ${expectHash}, got ${receivedHash}.`,
92+
pass: false,
93+
};
94+
}
95+
},
96+
});
97+
7998
it("correctly exposes the event emitter API", () => {
8099
const upload = new Upload({
81100
params,
@@ -237,33 +256,30 @@ describe(Upload.name, () => {
237256
params: actionParams,
238257
client: new S3({}),
239258
});
240-
241259
await upload.done();
242-
243260
expect(sendMock).toHaveBeenCalledTimes(4);
244261
// create multipartMock is called correctly.
245262
expect(createMultipartMock).toHaveBeenCalledTimes(1);
246263
expect(createMultipartMock).toHaveBeenCalledWith({
247264
...actionParams,
248265
Body: undefined,
249266
});
250-
251267
// upload parts is called correctly.
252268
expect(uploadPartMock).toHaveBeenCalledTimes(2);
253269
expect(uploadPartMock).toHaveBeenNthCalledWith(1, {
254270
...actionParams,
255-
Body: firstBuffer,
271+
// @ts-ignore extended custom matcher
272+
Body: expect.toHaveSameHashAsBuffer(firstBuffer),
256273
PartNumber: 1,
257274
UploadId: "mockuploadId",
258275
});
259-
260276
expect(uploadPartMock).toHaveBeenNthCalledWith(2, {
261277
...actionParams,
262-
Body: secondBuffer,
278+
// @ts-ignore extended custom matcher
279+
Body: expect.toHaveSameHashAsBuffer(secondBuffer),
263280
PartNumber: 2,
264281
UploadId: "mockuploadId",
265282
});
266-
267283
// complete multipart upload is called correctly.
268284
expect(completeMultipartMock).toHaveBeenCalledTimes(1);
269285
expect(completeMultipartMock).toHaveBeenLastCalledWith({
@@ -320,14 +336,16 @@ describe(Upload.name, () => {
320336
expect(uploadPartMock).toHaveBeenCalledTimes(2);
321337
expect(uploadPartMock).toHaveBeenNthCalledWith(1, {
322338
...actionParams,
323-
Body: firstBuffer,
339+
// @ts-ignore extended custom matcher
340+
Body: expect.toHaveSameHashAsBuffer(firstBuffer),
324341
PartNumber: 1,
325342
UploadId: "mockuploadId",
326343
});
327344

328345
expect(uploadPartMock).toHaveBeenNthCalledWith(2, {
329346
...actionParams,
330-
Body: secondBuffer,
347+
// @ts-ignore extended custom matcher
348+
Body: expect.toHaveSameHashAsBuffer(secondBuffer),
331349
PartNumber: 2,
332350
UploadId: "mockuploadId",
333351
});
@@ -418,6 +436,8 @@ describe(Upload.name, () => {
418436
expect(putObjectTaggingMock).toHaveBeenCalledTimes(1);
419437
expect(putObjectTaggingMock).toHaveBeenCalledWith({
420438
...actionParams,
439+
// @ts-ignore extended custom matcher
440+
Body: expect.toHaveSameHashAsBuffer(largeBuffer),
421441
Tagging: {
422442
TagSet: tags,
423443
},

package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"@tsconfig/recommended": "1.0.1",
6161
"@types/chai-as-promised": "^7.1.2",
6262
"@types/fs-extra": "^8.0.1",
63-
"@types/jest": "27.4.0",
63+
"@types/jest": "28.1.3",
6464
"@typescript-eslint/eslint-plugin": "5.28.0",
6565
"@typescript-eslint/parser": "5.28.0",
6666
"async": "3.2.4",
@@ -81,7 +81,8 @@
8181
"generate-changelog": "^1.7.1",
8282
"husky": "^4.2.3",
8383
"jasmine-core": "^3.5.0",
84-
"jest": "27.4.5",
84+
"jest": "28.1.1",
85+
"jest-environment-jsdom": "28.1.1",
8586
"jmespath": "^0.15.0",
8687
"json5": "^2.2.0",
8788
"karma": "6.4.0",
@@ -102,7 +103,7 @@
102103
"puppeteer": "^5.1.0",
103104
"rimraf": "3.0.2",
104105
"strip-comments": "2.0.1",
105-
"ts-jest": "27.1.2",
106+
"ts-jest": "28.0.5",
106107
"ts-loader": "^7.0.5",
107108
"ts-mocha": "10.0.0",
108109
"ts-node": "^10.4.0",
@@ -126,7 +127,8 @@
126127
"**/karma*/**",
127128
"**/@types/mocha*",
128129
"**/@types/mocha*/**",
129-
"**/@aws-sdk/client-sso/**"
130+
"**/@aws-sdk/client-sso/**",
131+
"**/@babel/**"
130132
]
131133
},
132134
"husky": {

packages/middleware-retry/src/DefaultRateLimiter.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe(DefaultRateLimiter.name, () => {
1515

1616
describe("getSendToken", () => {
1717
beforeEach(() => {
18-
jest.useFakeTimers("legacy");
18+
jest.useFakeTimers({ legacyFakeTimers: true });
1919
});
2020

2121
afterEach(() => {

packages/node-http-handler/src/set-connection-timeout.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("setConnectionTimeout", () => {
2929
};
3030

3131
beforeEach(() => {
32-
jest.useFakeTimers("legacy");
32+
jest.useFakeTimers({ legacyFakeTimers: true });
3333
setConnectionTimeout(clientRequest, reject, timeoutInMs);
3434
});
3535

packages/util-waiter/src/createWaiter.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { createWaiter } from "./createWaiter";
1111

1212
describe("createWaiter", () => {
1313
beforeEach(() => {
14-
jest.useFakeTimers("legacy");
14+
jest.useFakeTimers({ legacyFakeTimers: true });
1515
});
1616

1717
afterEach(() => {

packages/util-waiter/src/utils/sleep.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { sleep } from "./sleep";
22

33
describe("Sleep Module", () => {
44
beforeEach(() => {
5-
jest.useFakeTimers("legacy");
5+
jest.useFakeTimers({ legacyFakeTimers: true });
66
});
77

88
afterEach(() => {

0 commit comments

Comments
 (0)