Skip to content

Commit f0d92f8

Browse files
committed
test(client-s3): add client test
1 parent eb15361 commit f0d92f8

File tree

6 files changed

+44
-2
lines changed

6 files changed

+44
-2
lines changed

clients/client-s3/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ package-lock.json
1111

1212
*.d.ts
1313
*.js
14+
!jest.config.js
1415
*.js.map

clients/client-s3/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/docs/
33
tsconfig.test.json
44
*.tsbuildinfo
5+
jest.config.js

clients/client-s3/S3.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { S3 } from "./S3";
2+
import { SerializeMiddleware } from "@aws-sdk/types";
3+
import { HttpRequest } from "@aws-sdk/protocol-http";
4+
5+
describe("endpoint", () => {
6+
it("users can override endpoint from client.", async () => {
7+
//use s3 here but all the clients are generated similarly
8+
const endpointValidator: SerializeMiddleware<any, any> = next => args => {
9+
// middleware intercept the request and return it early
10+
const request = args.request as HttpRequest;
11+
expect(request.protocol).toEqual("http:");
12+
expect(request.hostname).toEqual("localhost");
13+
expect(request.port).toEqual(8080);
14+
expect(request.query).toEqual({ foo: "bar" });
15+
expect(request.path).toEqual("/path");
16+
return Promise.resolve({ output: {} as any, response: {} as any });
17+
};
18+
const client = new S3({ endpoint: "http://localhost:8080/path?foo=bar" });
19+
client.middlewareStack.add(endpointValidator, {
20+
step: "serialize",
21+
name: "endpointValidator",
22+
priority: "low"
23+
});
24+
await client.putObject({ Bucket: "bucket", Key: "key", Body: "body" });
25+
});
26+
});

clients/client-s3/jest.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const base = require("../../jest.config.base.js");
2+
3+
module.exports = {
4+
...base,
5+
// Only test cjs dist, avoid testing the package twice
6+
testPathIgnorePatterns: ["/node_modules/", "/es/"],
7+
coveragePathIgnorePatterns: [
8+
"/node_modules/",
9+
"/commands/",
10+
"/protocols/", // protocols tested in protocol protocol_tests folder
11+
"endpoints" // endpoint tested in tests/functional/endpoints
12+
]
13+
};

clients/client-s3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"remove-documentation": "rimraf ./docs",
1313
"remove-js": "rimraf *.js && rimraf ./commands/*.js && rimraf ./models/*.js && rimraf ./protocols/*.js",
1414
"remove-maps": "rimraf *.js.map && rimraf ./commands/*.js.map && rimraf ./models/*.js.map && rimraf ./protocols/*.js.map",
15-
"test": "exit 0",
15+
"test": "jest --passWithNoTests",
1616
"smoke-test": "npm run pretest && node ./test/smoke/index.spec.js",
1717
"build:es": "tsc -p tsconfig.es.json",
1818
"build": "yarn pretest && yarn build:es"

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module.exports = {
44
...base,
55
projects: [
66
"<rootDir>/protocol_tests/*/jest.config.js",
7-
"<rootDir>/packages/*/jest.config.js"
7+
"<rootDir>/packages/*/jest.config.js",
8+
"<rootDir>/clients/*/jest.config.js"
89
],
910
testPathIgnorePatterns: ["/node_modules/", "<rootDir>/clients/client-.*"],
1011
coveragePathIgnorePatterns: [

0 commit comments

Comments
 (0)