@flink-app/test-utils 0.4.2 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/index.ts +56 -72
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare type HttpOpts = {
|
|
|
12
12
|
* Should be invoked prior to using test methods.
|
|
13
13
|
*/
|
|
14
14
|
export declare function init(_app: FlinkApp<any>, host?: string): void;
|
|
15
|
-
export declare function get<
|
|
16
|
-
export declare function post<
|
|
17
|
-
export declare function put<
|
|
18
|
-
export declare function del<
|
|
15
|
+
export declare function get<Res = any>(path: string, opts?: HttpOpts): Promise<FlinkResponse<Res>>;
|
|
16
|
+
export declare function post<Req = any, Res = any>(path: string, body: Req, opts?: HttpOpts): Promise<FlinkResponse<Res>>;
|
|
17
|
+
export declare function put<Req = any, Res = any>(path: string, body: Req, opts?: HttpOpts): Promise<FlinkResponse<Res>>;
|
|
18
|
+
export declare function del<Res = any>(path: string, opts?: HttpOpts): Promise<FlinkResponse<Res>>;
|
package/dist/index.js
CHANGED
|
@@ -140,7 +140,7 @@ function del(path, opts) {
|
|
|
140
140
|
exports.del = del;
|
|
141
141
|
function validateApp() {
|
|
142
142
|
if (!app) {
|
|
143
|
-
throw new Error("App not initialized, run `init(app)
|
|
143
|
+
throw new Error("App not initialized, run `init(app)` prior to invoking get/post/put/del");
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
function getUrl(path, queryString) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/test-utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "Test utils for Flink",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\"",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"qs": "^6.7.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@flink-app/flink": "^0.4.
|
|
22
|
+
"@flink-app/flink": "^0.4.5",
|
|
23
23
|
"@types/express": "^4.17.12",
|
|
24
24
|
"@types/got": "^9.6.12",
|
|
25
25
|
"@types/node": "^15.6.2",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"tsc-watch": "^4.2.9",
|
|
30
30
|
"typescript": "^4.2.4"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "38a0ca4c987f280accc5f4c7f408e51f7b076587"
|
|
33
33
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,14 +6,14 @@ let app: FlinkApp<any>;
|
|
|
6
6
|
let baseUrl: string;
|
|
7
7
|
|
|
8
8
|
const gotOpts: GotJSONOptions = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
throwHttpErrors: false,
|
|
10
|
+
json: true,
|
|
11
|
+
retry: 0,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export type HttpOpts = {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
qs?: { [x: string]: string | string[] };
|
|
16
|
+
headers?: { [x: string]: string };
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -21,86 +21,70 @@ export type HttpOpts = {
|
|
|
21
21
|
* Should be invoked prior to using test methods.
|
|
22
22
|
*/
|
|
23
23
|
export function init(_app: FlinkApp<any>, host = "localhost") {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
app = _app;
|
|
25
|
+
baseUrl = `http://${host}:${app.port}`;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export async function get<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
status: res.statusCode,
|
|
39
|
-
...res.body,
|
|
40
|
-
};
|
|
28
|
+
export async function get<Res = any>(path: string, opts: HttpOpts = {}): Promise<FlinkResponse<Res>> {
|
|
29
|
+
validateApp();
|
|
30
|
+
const res = await got.get(getUrl(path, opts.qs), {
|
|
31
|
+
...gotOpts,
|
|
32
|
+
headers: opts.headers,
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
status: res.statusCode,
|
|
36
|
+
...res.body,
|
|
37
|
+
};
|
|
41
38
|
}
|
|
42
39
|
|
|
43
|
-
export async function post<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
...gotOpts,
|
|
51
|
-
body,
|
|
52
|
-
headers: opts.headers,
|
|
53
|
-
});
|
|
40
|
+
export async function post<Req = any, Res = any>(path: string, body: Req, opts: HttpOpts = {}): Promise<FlinkResponse<Res>> {
|
|
41
|
+
validateApp();
|
|
42
|
+
const res = await got.post(getUrl(path, opts.qs), {
|
|
43
|
+
...gotOpts,
|
|
44
|
+
body: body as any,
|
|
45
|
+
headers: opts.headers,
|
|
46
|
+
});
|
|
54
47
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
return {
|
|
49
|
+
status: res.statusCode,
|
|
50
|
+
...res.body,
|
|
51
|
+
};
|
|
59
52
|
}
|
|
60
53
|
|
|
61
|
-
export async function put<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
status: res.statusCode,
|
|
74
|
-
...res.body,
|
|
75
|
-
};
|
|
54
|
+
export async function put<Req = any, Res = any>(path: string, body: Req, opts: HttpOpts = {}): Promise<FlinkResponse<Res>> {
|
|
55
|
+
validateApp();
|
|
56
|
+
const res = await got.put(getUrl(path, opts.qs), {
|
|
57
|
+
...gotOpts,
|
|
58
|
+
body: body as any,
|
|
59
|
+
headers: opts.headers,
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
status: res.statusCode,
|
|
63
|
+
...res.body,
|
|
64
|
+
};
|
|
76
65
|
}
|
|
77
66
|
|
|
78
|
-
export async function del<
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
status: res.statusCode,
|
|
89
|
-
...res.body,
|
|
90
|
-
};
|
|
67
|
+
export async function del<Res = any>(path: string, opts: HttpOpts = {}): Promise<FlinkResponse<Res>> {
|
|
68
|
+
validateApp();
|
|
69
|
+
const res = await got.delete(getUrl(path, opts.qs), {
|
|
70
|
+
...gotOpts,
|
|
71
|
+
headers: opts.headers,
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
status: res.statusCode,
|
|
75
|
+
...res.body,
|
|
76
|
+
};
|
|
91
77
|
}
|
|
92
78
|
|
|
93
79
|
function validateApp() {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
);
|
|
98
|
-
}
|
|
80
|
+
if (!app) {
|
|
81
|
+
throw new Error("App not initialized, run `init(app)` prior to invoking get/post/put/del");
|
|
82
|
+
}
|
|
99
83
|
}
|
|
100
84
|
|
|
101
85
|
function getUrl(path: string, queryString?: HttpOpts["qs"]) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
86
|
+
if (queryString) {
|
|
87
|
+
return baseUrl + path + "?" + qs.stringify(queryString);
|
|
88
|
+
}
|
|
89
|
+
return baseUrl + path;
|
|
106
90
|
}
|