@naturalcycles/backend-lib 3.0.0 → 3.1.0
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.
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Got } from '@naturalcycles/nodejs-lib';
|
|
1
|
+
import { GetGotOptions, Got } from '@naturalcycles/nodejs-lib';
|
|
2
2
|
import { BackendApplication } from '../index';
|
|
3
3
|
import { BackendRequestHandlerCfg } from '../server/createDefaultApp.model';
|
|
4
4
|
export interface ExpressApp extends Got {
|
|
5
5
|
close(): Promise<void>;
|
|
6
6
|
}
|
|
7
7
|
declare class ExpressTestService {
|
|
8
|
-
createAppFromResource(resource: BackendRequestHandlerCfg): ExpressApp;
|
|
9
|
-
createAppFromResources(resources: BackendRequestHandlerCfg[]): ExpressApp;
|
|
10
|
-
createApp(app: BackendApplication): ExpressApp;
|
|
8
|
+
createAppFromResource(resource: BackendRequestHandlerCfg, opt?: GetGotOptions): ExpressApp;
|
|
9
|
+
createAppFromResources(resources: BackendRequestHandlerCfg[], opt?: GetGotOptions): ExpressApp;
|
|
10
|
+
createApp(app: BackendApplication, opt?: GetGotOptions): ExpressApp;
|
|
11
11
|
/**
|
|
12
12
|
* Creates a "Default Express App" with provided resources.
|
|
13
13
|
* Starts an http server on '127.0.0.1' and random available port.
|
|
@@ -9,17 +9,17 @@ const index_1 = require("../index");
|
|
|
9
9
|
// await app.close()
|
|
10
10
|
// })
|
|
11
11
|
class ExpressTestService {
|
|
12
|
-
createAppFromResource(resource) {
|
|
12
|
+
createAppFromResource(resource, opt) {
|
|
13
13
|
return this.createApp((0, index_1.createDefaultApp)({
|
|
14
14
|
resources: [resource],
|
|
15
|
-
}));
|
|
15
|
+
}), opt);
|
|
16
16
|
}
|
|
17
|
-
createAppFromResources(resources) {
|
|
17
|
+
createAppFromResources(resources, opt) {
|
|
18
18
|
return this.createApp((0, index_1.createDefaultApp)({
|
|
19
19
|
resources,
|
|
20
|
-
}));
|
|
20
|
+
}), opt);
|
|
21
21
|
}
|
|
22
|
-
createApp(app) {
|
|
22
|
+
createApp(app, opt) {
|
|
23
23
|
const server = this.createTestServer(app);
|
|
24
24
|
const { port } = server.address();
|
|
25
25
|
const prefixUrl = `http://127.0.0.1:${port}`;
|
|
@@ -27,6 +27,9 @@ class ExpressTestService {
|
|
|
27
27
|
prefixUrl,
|
|
28
28
|
responseType: 'json',
|
|
29
29
|
retry: 0,
|
|
30
|
+
logStart: true,
|
|
31
|
+
logFinished: true,
|
|
32
|
+
...opt,
|
|
30
33
|
});
|
|
31
34
|
got.close = async () => {
|
|
32
35
|
await new Promise(resolve => server.close(resolve));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Server } from 'http'
|
|
2
2
|
import { AddressInfo } from 'net'
|
|
3
|
-
import { getGot, Got } from '@naturalcycles/nodejs-lib'
|
|
3
|
+
import { getGot, GetGotOptions, Got } from '@naturalcycles/nodejs-lib'
|
|
4
4
|
import { BackendApplication, createDefaultApp } from '../index'
|
|
5
5
|
import { BackendRequestHandlerCfg } from '../server/createDefaultApp.model'
|
|
6
6
|
|
|
@@ -15,23 +15,25 @@ export interface ExpressApp extends Got {
|
|
|
15
15
|
// })
|
|
16
16
|
|
|
17
17
|
class ExpressTestService {
|
|
18
|
-
createAppFromResource(resource: BackendRequestHandlerCfg): ExpressApp {
|
|
18
|
+
createAppFromResource(resource: BackendRequestHandlerCfg, opt?: GetGotOptions): ExpressApp {
|
|
19
19
|
return this.createApp(
|
|
20
20
|
createDefaultApp({
|
|
21
21
|
resources: [resource],
|
|
22
22
|
}),
|
|
23
|
+
opt,
|
|
23
24
|
)
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
createAppFromResources(resources: BackendRequestHandlerCfg[]): ExpressApp {
|
|
27
|
+
createAppFromResources(resources: BackendRequestHandlerCfg[], opt?: GetGotOptions): ExpressApp {
|
|
27
28
|
return this.createApp(
|
|
28
29
|
createDefaultApp({
|
|
29
30
|
resources,
|
|
30
31
|
}),
|
|
32
|
+
opt,
|
|
31
33
|
)
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
createApp(app: BackendApplication): ExpressApp {
|
|
36
|
+
createApp(app: BackendApplication, opt?: GetGotOptions): ExpressApp {
|
|
35
37
|
const server = this.createTestServer(app)
|
|
36
38
|
const { port } = server.address() as AddressInfo
|
|
37
39
|
const prefixUrl = `http://127.0.0.1:${port}`
|
|
@@ -40,6 +42,9 @@ class ExpressTestService {
|
|
|
40
42
|
prefixUrl,
|
|
41
43
|
responseType: 'json',
|
|
42
44
|
retry: 0,
|
|
45
|
+
logStart: true,
|
|
46
|
+
logFinished: true,
|
|
47
|
+
...opt,
|
|
43
48
|
}) as ExpressApp
|
|
44
49
|
|
|
45
50
|
got.close = async () => {
|