Skip to content

Commit f4b7dcf

Browse files
committed
test(client-s3): attempt to add e2e test
1 parent 06017c3 commit f4b7dcf

File tree

12 files changed

+160
-18
lines changed

12 files changed

+160
-18
lines changed

clients/client-s3/.gitignore

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

1212
*.d.ts
1313
*.js
14-
!jest.config.js
14+
!karma.conf.js
1515
*.js.map

clients/client-s3/S3.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference types="jest" />
12
import { S3 } from "./S3";
23
import { SerializeMiddleware } from "@aws-sdk/types";
34
import { HttpRequest } from "@aws-sdk/protocol-http";

clients/client-s3/e2e/S3.ispec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/// <reference types="mocha" />
2+
/**
3+
* This is the integration test that make sure the client can make request cross-platform-ly
4+
* in NodeJS, Chromium and Firefox. This test is written in mocha.
5+
*/
6+
import { expect } from "chai";
7+
import { S3Client, PutObjectCommand, DeleteObjectCommand } from "../index";
8+
declare let defaultRegion: string;
9+
declare const credentials: any;
10+
declare const isBrowser: boolean; //undefined by default, used for NodeJS.
11+
12+
const Bucket = "aws-sdk-unit-test"; // this bucket requires enabling CORS
13+
const Key = `${Date.now()}`;
14+
15+
describe("@aws-sdk/client-s3", () => {
16+
const client = new S3Client({
17+
region: defaultRegion,
18+
credentials
19+
});
20+
21+
after(async () => {
22+
await client.send(
23+
new DeleteObjectCommand({
24+
Bucket,
25+
Key
26+
})
27+
);
28+
});
29+
30+
if (isBrowser) {
31+
it("PutObject should succeed when given blob body", async () => {
32+
const smallBody = [];
33+
const result = await client.send(
34+
new PutObjectCommand({
35+
Bucket,
36+
Key,
37+
Body: new Blob(["abc"])
38+
})
39+
);
40+
expect(result.$metadata.httpStatusCode).to.eql(200);
41+
});
42+
}
43+
});

clients/client-s3/jest.config.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

clients/client-s3/karma.conf.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
module.exports = function (config) {
2+
config.set({
3+
basePath: "",
4+
frameworks: ["mocha", "chai"],
5+
files: ["e2e/**/*.ispec.ts"],
6+
preprocessors: {
7+
"e2e/**/*.ispec.ts": ["webpack", "sourcemap", "credentials"]
8+
},
9+
webpackMiddleware: {
10+
stats: "minimal"
11+
},
12+
webpack: {
13+
resolve: {
14+
extensions: [".ts", ".js"]
15+
},
16+
mode: "development",
17+
module: {
18+
rules: [
19+
{
20+
test: /\.tsx?$/,
21+
use: [
22+
{
23+
loader: "ts-loader",
24+
options: {
25+
configFile: "tsconfig.e2e.json",
26+
compilerOptions: {
27+
rootDir: "./"
28+
}
29+
}
30+
}
31+
],
32+
exclude: /node_modules/
33+
}
34+
]
35+
},
36+
// stats: {
37+
// // colors: false,
38+
// // modules: false,
39+
// // reasons: false,
40+
// // assets: false,
41+
// // moduleAssets: false,
42+
// // chunks: false,
43+
// // errorDetails: true
44+
// all: false
45+
// },
46+
devtool: "inline-source-map"
47+
},
48+
plugins: [
49+
"@aws-sdk/karma-credential-loader",
50+
"karma-chrome-launcher",
51+
"karma-firefox-launcher",
52+
"karma-mocha",
53+
"karma-chai",
54+
"karma-webpack",
55+
"karma-coverage",
56+
"karma-sourcemap-loader"
57+
],
58+
port: 9876,
59+
colors: true,
60+
logLevel: config.LOG_WARN,
61+
autoWatch: false,
62+
browsers: ["ChromeHeadless", "FirefoxHeadless"],
63+
customLaunchers: {
64+
FirefoxHeadless: {
65+
base: "Firefox",
66+
flags: ["-headless"]
67+
}
68+
},
69+
singleRun: true,
70+
concurrency: Infinity,
71+
exclude: ["**/*.d.ts", "*.spec.ts"]
72+
});
73+
};

clients/client-s3/package.json

Lines changed: 4 additions & 2 deletions
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": "jest --passWithNoTests",
15+
"test:browser": "karma start karma.conf.js",
1616
"build:es": "tsc -p tsconfig.es.json",
1717
"build": "yarn pretest && yarn build:es"
1818
},
@@ -39,6 +39,7 @@
3939
"@aws-sdk/hash-node": "1.0.0-gamma.1",
4040
"@aws-sdk/hash-stream-node": "1.0.0-gamma.1",
4141
"@aws-sdk/invalid-dependency": "1.0.0-gamma.1",
42+
"@aws-sdk/karma-credential-loader": "1.0.0-gamma.0",
4243
"@aws-sdk/md5-js": "1.0.0-gamma.1",
4344
"@aws-sdk/middleware-apply-body-checksum": "1.0.0-gamma.1",
4445
"@aws-sdk/middleware-bucket-endpoint": "1.0.0-gamma.1",
@@ -74,8 +75,9 @@
7475
"tslib": "^1.8.0"
7576
},
7677
"devDependencies": {
78+
"@types/chai": "^4.2.11",
79+
"@types/mocha": "^7.0.2",
7780
"@types/node": "^12.7.5",
78-
"jest": "^25.1.0",
7981
"rimraf": "^3.0.0",
8082
"tslib": "^1.8.0",
8183
"typedoc": "^0.15.0",

clients/client-s3/tsconfig.e2e.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "..",
5+
"target": "es5",
6+
"lib": ["dom"],
7+
"types": ["mocha"]
8+
},
9+
"exclude": ["./*.spec.ts", "dist", "types"]
10+
}

clients/client-s3/tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"incremental": true,
1313
"resolveJsonModule": true,
1414
"declarationDir": "./types",
15-
"outDir": "dist/cjs"
15+
"outDir": "dist/cjs",
16+
"types": ["jest"]
1617
},
1718
"typedocOptions": {
1819
"exclude": "**/node_modules/**",
@@ -23,5 +24,6 @@
2324
"mode": "file",
2425
"out": "./docs",
2526
"plugin": "@aws-sdk/client-documentation-generator"
26-
}
27+
},
28+
"exclude": ["e2e", "types"]
2729
}

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@commitlint/config-conventional": "^8.3.4",
4141
"@types/fs-extra": "^8.0.1",
4242
"@types/jest": "^25.1.4",
43+
"chai": "^4.2.0",
4344
"codecov": "^3.4.0",
4445
"cucumber": "^6.0.5",
4546
"fs-extra": "^9.0.0",
@@ -49,15 +50,24 @@
4950
"jest": "^25.1.0",
5051
"jmespath": "^0.15.0",
5152
"karma": "^5.1.0",
53+
"karma-chai": "^0.1.0",
5254
"karma-chrome-launcher": "^3.1.0",
5355
"karma-coverage": "^2.0.2",
56+
"karma-firefox-launcher": "^1.3.0",
5457
"karma-jasmine": "^3.3.1",
58+
"karma-mocha": "^2.0.1",
59+
"karma-sourcemap-loader": "^0.3.7",
5560
"karma-typescript": "^5.0.3",
61+
"karma-webpack": "^4.0.2",
5662
"lerna": "3.22.1",
5763
"lint-staged": "^10.0.1",
64+
"mocha": "^8.0.1",
5865
"prettier": "2.0.5",
5966
"puppeteer": "^4.0.0",
67+
"ts-loader": "^7.0.5",
6068
"typescript": "~3.8.3",
69+
"webpack": "^4.43.0",
70+
"webpack-cli": "^3.3.12",
6171
"yarn": "1.22.4"
6272
},
6373
"workspaces": {

tests/functional/smoke/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Smoke Tests
2+
3+
Smoke tests is used to make sure the SDK can make API request correctly to the AWS backend. It does not intended to
4+
integration tests for more abstract interfaces or utilities.

tests/functional/smoke/client-s3.spec.js

Whitespace-only changes.

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,11 @@
17201720
dependencies:
17211721
"@babel/types" "^7.3.0"
17221722

1723+
"@types/chai@^4.2.11":
1724+
version "4.2.11"
1725+
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.2.11.tgz#d3614d6c5f500142358e6ed24e1bf16657536c50"
1726+
integrity sha512-t7uW6eFafjO+qJ3BIV2gGUyZs27egcNRkUdalkud+Qa3+kg//f129iuOFivHDXQ+vnU3fDXuwgv0cqMCbcE8sw==
1727+
17231728
"@types/color-name@^1.1.1":
17241729
version "1.1.1"
17251730
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
@@ -1821,6 +1826,11 @@
18211826
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
18221827
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=
18231828

1829+
"@types/mocha@^7.0.2":
1830+
version "7.0.2"
1831+
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-7.0.2.tgz#b17f16cf933597e10d6d78eae3251e692ce8b0ce"
1832+
integrity sha512-ZvO2tAcjmMi8V/5Z3JsyofMe3hasRcaw88cto5etSVMwVQfeivGAlEYmaQgceUSVYFofVjT+ioHsATjdWcFt1w==
1833+
18241834
"@types/node@*", "@types/node@>= 8":
18251835
version "14.0.13"
18261836
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.13.tgz#ee1128e881b874c371374c1f72201893616417c9"

0 commit comments

Comments
 (0)