Skip to content

Commit 3c74cc5

Browse files
AllanZhengYPsrchase
authored andcommitted
Support Typescript 3.2 and enable Travis-CI (#155)
* remove .bind() in middleware-stack * fix treemodel deepcopy() * enable travis-ci
1 parent 36bf67c commit 3c74cc5

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

packages/middleware-stack/src/index.spec.ts

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@ import {
33
Handler,
44
HandlerArguments,
55
FinalizeHandlerArguments,
6+
Middleware,
7+
HandlerExecutionContext,
8+
FinalizeMiddleware,
9+
FinalizeHandler
610
} from "@aws-sdk/types";
711

812
type input = Array<string>;
913
type output = object;
1014

11-
function concatMiddleware(
12-
message: string,
13-
next: Handler<input, output>
14-
): Handler<input, output> {
15-
return (args: HandlerArguments<input>): Promise<output> => next({
16-
...args,
17-
input: args.input.concat(message),
18-
});
15+
//return tagged union to make compiler happy
16+
function getConcatMiddleware(message: string): Middleware<input, output> | FinalizeMiddleware<input, output> {
17+
return (
18+
next: Handler<input, output>,
19+
): Handler<input, output> => {
20+
return (args: HandlerArguments<input>): Promise<output> => next({
21+
...args,
22+
input: args.input.concat(message),
23+
});
24+
}
25+
1926
}
20-
2127
function shuffle<T>(arr: Array<T>): Array<T> {
2228
arr = [...arr];
2329
for (let i = arr.length; i > 0; i--) {
@@ -33,22 +39,22 @@ describe('MiddlewareStack', () => {
3339
const stack = new MiddlewareStack<input, output>();
3440

3541
const middleware = shuffle([
36-
[concatMiddleware.bind(null, 'second')],
37-
[concatMiddleware.bind(null, 'first'), {priority: 10}],
38-
[concatMiddleware.bind(null, 'fourth'), {step: 'build'}],
42+
[getConcatMiddleware('second'), {}],
43+
[getConcatMiddleware('first'), {priority: 10}],
44+
[getConcatMiddleware('fourth'), {step: 'build'}],
3945
[
40-
concatMiddleware.bind(null, 'third'),
46+
getConcatMiddleware('third'),
4147
{step: 'build', priority: 1}
4248
],
43-
[concatMiddleware.bind(null, 'fifth'), {step: 'finalize'}],
49+
[getConcatMiddleware('fifth'), {step: 'finalize'}],
4450
[
45-
concatMiddleware.bind(null, 'sixth'),
51+
getConcatMiddleware('sixth'),
4652
{step: 'finalize', priority: -1}
4753
],
4854
]);
4955

5056
for (const [mw, options] of middleware) {
51-
stack.add(mw, options);
57+
stack.add(mw as any, options);
5258
}
5359

5460
const inner = jest.fn(({input}: FinalizeHandlerArguments<input>) => {
@@ -71,8 +77,11 @@ describe('MiddlewareStack', () => {
7177

7278
it('should allow cloning', async () => {
7379
const stack = new MiddlewareStack<input, output>();
74-
stack.add(concatMiddleware.bind(null, 'second'));
75-
stack.add(concatMiddleware.bind(null, 'first'), {priority: 100});
80+
stack.add(getConcatMiddleware('second') as Middleware<input, output>);
81+
stack.add(
82+
getConcatMiddleware('first') as Middleware<input, output>,
83+
{priority: 100}
84+
);
7685

7786
const secondStack = stack.clone();
7887

@@ -89,13 +98,19 @@ describe('MiddlewareStack', () => {
8998

9099
it('should allow combining stacks', async () => {
91100
const stack = new MiddlewareStack<input, output>();
92-
stack.add(concatMiddleware.bind(null, 'second'));
93-
stack.add(concatMiddleware.bind(null, 'first'), {priority: 100});
101+
stack.add(getConcatMiddleware('second') as Middleware<input, output>);
102+
stack.add(
103+
getConcatMiddleware('first') as Middleware<input, output>,
104+
{priority: 100}
105+
);
94106

95107
const secondStack = new MiddlewareStack<input, output>();
96-
secondStack.add(concatMiddleware.bind(null, 'fourth'), {step: 'build'});
97108
secondStack.add(
98-
concatMiddleware.bind(null, 'third'),
109+
getConcatMiddleware('fourth') as FinalizeMiddleware<input, output>,
110+
{step: 'build'}
111+
);
112+
secondStack.add(
113+
getConcatMiddleware('third') as FinalizeMiddleware<input, output>,
99114
{step: 'build', priority: 100}
100115
);
101116

@@ -114,10 +129,10 @@ describe('MiddlewareStack', () => {
114129
});
115130

116131
it('should allow the removal of middleware by constructor identity', async () => {
117-
const MyMiddleware = concatMiddleware.bind(null, 'remove me!');
132+
const MyMiddleware = getConcatMiddleware('remove me!') as Middleware<input, output>;
118133
const stack = new MiddlewareStack<input, output>();
119134
stack.add(MyMiddleware);
120-
stack.add(concatMiddleware.bind(null, "don't remove me"));
135+
stack.add(getConcatMiddleware("don't remove me") as Middleware<input, output>);
121136

122137
await stack.resolve(
123138
({input}: FinalizeHandlerArguments<Array<string>>) => {
@@ -144,11 +159,11 @@ describe('MiddlewareStack', () => {
144159
it('should allow the removal of middleware by tag', async () => {
145160
const stack = new MiddlewareStack<input, output>();
146161
stack.add(
147-
concatMiddleware.bind(null, 'not removed'),
162+
getConcatMiddleware('not removed') as Middleware<input, output>,
148163
{tags: {foo: true, bar: true}}
149164
);
150165
stack.add(
151-
concatMiddleware.bind(null, 'remove me!'),
166+
getConcatMiddleware('remove me!') as Middleware<input, output>,
152167
{tags: {foo: true, bar: true, baz: true}}
153168
);
154169

packages/node-http-handler/src/node-http-handler.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ afterEach(() => {
2727
});
2828

2929
describe('NodeHttpHandler', () => {
30-
let mockHttpServer: HttpServer = createMockHttpServer().listen(5432);
31-
let mockHttpsServer: HttpsServer = createMockHttpsServer().listen(5433);
30+
let mockHttpServer: HttpServer = createMockHttpServer().listen(54321);
31+
let mockHttpsServer: HttpsServer = createMockHttpsServer().listen(54322);
3232

3333
afterEach(() => {
3434
mockHttpServer.removeAllListeners('request');

0 commit comments

Comments
 (0)