Skip to content

Commit 1150c2b

Browse files
committed
test(client-s3): use jest for unit tests
1 parent 67293a9 commit 1150c2b

File tree

3 files changed

+19
-29
lines changed

3 files changed

+19
-29
lines changed

clients/client-s3/S3.spec.ts

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
/// <reference types="mocha" />
1+
/// <reference types="jest" />
22
import { HttpRequest } from "@aws-sdk/protocol-http";
33
import { BuildMiddleware, SerializeMiddleware } from "@aws-sdk/types";
4-
import chai from "chai";
5-
import chaiAsPromised from "chai-as-promised";
64
import { PassThrough } from "stream";
75

86
import { S3 } from "./S3";
97

10-
chai.use(chaiAsPromised);
11-
const { expect } = chai;
12-
138
describe("endpoint", () => {
149
it("users can override endpoint from client.", async () => {
1510
//use s3 here but all the clients are generated similarly
1611
const endpointValidator: SerializeMiddleware<any, any> = (next) => (args) => {
1712
// middleware intercept the request and return it early
1813
const request = args.request as HttpRequest;
19-
expect(request.protocol).to.equal("http:");
20-
expect(request.hostname).to.equal("localhost");
21-
expect(request.port).to.equal(8080);
14+
expect(request.protocol).toEqual("http:");
15+
expect(request.hostname).toEqual("localhost");
16+
expect(request.port).toEqual(8080);
2217
//query and path should not be overwritten
23-
expect(request.query).not.to.contain({ foo: "bar" });
24-
expect(request.path).not.to.equal("/path");
18+
expect(request.query).not.toContainEqual({ foo: "bar" });
19+
expect(request.path).not.toEqual("/path");
2520
return Promise.resolve({ output: {} as any, response: {} as any });
2621
};
2722
const client = new S3({ endpoint: "http://localhost:8080/path?foo=bar" });
@@ -60,7 +55,7 @@ describe("Accesspoint ARN", async () => {
6055
Key: "key",
6156
Body: "body",
6257
});
63-
expect(result.request.hostname).to.eql("myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com");
58+
expect(result.request.hostname).toEqual("myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com");
6459
});
6560

6661
it("should sign request with region from ARN is useArnRegion is set", async () => {
@@ -75,9 +70,9 @@ describe("Accesspoint ARN", async () => {
7570
Key: "key",
7671
Body: "body",
7772
});
78-
expect(result.request.hostname).to.eql("myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com");
73+
expect(result.request.hostname).toEqual("myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com");
7974
// Sign request with us-west-2 region from bucket access point ARN
80-
expect(result.request.headers.authorization).to.contain("/us-west-2/s3/aws4_request, SignedHeaders=");
75+
expect(result.request.headers.authorization).toContain("/us-west-2/s3/aws4_request, SignedHeaders=");
8176
});
8277

8378
it("should succeed with outposts ARN", async () => {
@@ -92,9 +87,9 @@ describe("Accesspoint ARN", async () => {
9287
Key: "key",
9388
Body: "body",
9489
});
95-
expect(result.request.hostname).to.eql(`abc-111-${AccountId}.${OutpostId}.s3-outposts.us-west-2.amazonaws.com`);
90+
expect(result.request.hostname).toEqual(`abc-111-${AccountId}.${OutpostId}.s3-outposts.us-west-2.amazonaws.com`);
9691
const date = new Date().toISOString().substr(0, 10).replace(/-/g, ""); //20201029
97-
expect(result.request.headers["authorization"]).contains(
92+
expect(result.request.headers["authorization"]).toContain(
9893
`Credential=${credentials.accessKeyId}/${date}/${region}/s3-outposts/aws4_request`
9994
);
10095
});
@@ -133,40 +128,36 @@ describe("Throw 200 response", () => {
133128

134129
it("should throw if CopyObject() return with 200 and empty payload", async () => {
135130
response.body.end("");
136-
return expect(client.copyObject(params)).to.eventually.be.rejectedWith("S3 aborted request");
131+
return expect(client.copyObject(params)).rejects.toThrow("S3 aborted request");
137132
});
138133

139134
it("should throw if CopyObject() return with 200 and error preamble", async () => {
140135
response.body.end(errorBody);
141-
return expect(client.copyObject(params)).to.eventually.be.rejectedWith(
142-
"We encountered an internal error. Please try again."
143-
);
136+
return expect(client.copyObject(params)).rejects.toThrow("We encountered an internal error. Please try again.");
144137
});
145138

146139
it("should throw if UploadPartCopy() return with 200 and empty payload", async () => {
147140
response.body.end("");
148-
return expect(client.uploadPartCopy({ ...params, UploadId: "id", PartNumber: 1 })).to.eventually.be.rejectedWith(
141+
return expect(client.uploadPartCopy({ ...params, UploadId: "id", PartNumber: 1 })).rejects.toThrow(
149142
"S3 aborted request"
150143
);
151144
});
152145

153146
it("should throw if UploadPartCopy() return with 200 and error preamble", async () => {
154147
response.body.end(errorBody);
155-
return expect(client.uploadPartCopy({ ...params, UploadId: "id", PartNumber: 1 })).to.eventually.be.rejectedWith(
148+
return expect(client.uploadPartCopy({ ...params, UploadId: "id", PartNumber: 1 })).rejects.toThrow(
156149
"We encountered an internal error. Please try again."
157150
);
158151
});
159152

160153
it("should throw if CompleteMultipartUpload() return with 200 and empty payload", async () => {
161154
response.body.end("");
162-
return expect(client.completeMultipartUpload({ ...params, UploadId: "id" })).to.eventually.be.rejectedWith(
163-
"S3 aborted request"
164-
);
155+
return expect(client.completeMultipartUpload({ ...params, UploadId: "id" })).rejects.toThrow("S3 aborted request");
165156
});
166157

167158
it("should throw if CompleteMultipartUpload() return with 200 and error preamble", async () => {
168159
response.body.end(errorBody);
169-
return expect(client.completeMultipartUpload({ ...params, UploadId: "id" })).to.eventually.be.rejectedWith(
160+
return expect(client.completeMultipartUpload({ ...params, UploadId: "id" })).rejects.toThrow(
170161
"We encountered an internal error. Please try again."
171162
);
172163
});

clients/client-s3/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
"remove-definitions": "rimraf ./types",
1010
"remove-dist": "rimraf ./dist",
1111
"remove-documentation": "rimraf ./docs",
12-
"test:unit": "mocha **/cjs/**/*.spec.js",
1312
"test:e2e": "mocha **/cjs/**/*.ispec.js && karma start karma.conf.js",
14-
"test": "yarn test:unit",
13+
"test": "jest",
1514
"build:cjs": "tsc -p tsconfig.json",
1615
"build:es": "tsc -p tsconfig.es.json",
1716
"build": "yarn build:cjs && yarn build:es",

clients/client-s3/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"esModuleInterop": true,
1515
"declarationDir": "./types",
1616
"outDir": "dist/cjs",
17-
"types": ["mocha", "node"]
17+
"types": ["mocha", "node", "jest"]
1818
},
1919
"typedocOptions": {
2020
"exclude": ["**/node_modules/**", "**/*.spec.ts", "./protocols/*.ts", "./e2e/*.ts", "./endpoints.ts"],

0 commit comments

Comments
 (0)