@loopback/testlab 1.7.2 → 1.8.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.
- package/CHANGELOG.md +38 -0
- package/dist/expect.js +1 -0
- package/dist/expect.js.map +1 -1
- package/dist/http-server-config.d.ts +10 -5
- package/dist/http-server-config.js +5 -2
- package/dist/http-server-config.js.map +1 -1
- package/dist/test-sandbox.d.ts +7 -0
- package/dist/test-sandbox.js +19 -7
- package/dist/test-sandbox.js.map +1 -1
- package/dist/to-json.js.map +1 -1
- package/package.json +8 -8
- package/src/expect.ts +1 -0
- package/src/http-server-config.ts +23 -8
- package/src/test-sandbox.ts +18 -4
- package/src/to-json.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,44 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.8.0](https://github.com/strongloop/loopback-next/compare/@loopback/testlab@1.7.5...@loopback/testlab@1.8.0) (2019-09-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **testlab:** add TestLab.writeJsonFile ([baa993b](https://github.com/strongloop/loopback-next/commit/baa993b))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [1.7.5](https://github.com/strongloop/loopback-next/compare/@loopback/testlab@1.7.4...@loopback/testlab@1.7.5) (2019-09-03)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* make givenHttpServerConfig typing compatible with TypeScript 3.6 ([1edbc0b](https://github.com/strongloop/loopback-next/commit/1edbc0b))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## [1.7.4](https://github.com/strongloop/loopback-next/compare/@loopback/testlab@1.7.3...@loopback/testlab@1.7.4) (2019-08-19)
|
|
29
|
+
|
|
30
|
+
**Note:** Version bump only for package @loopback/testlab
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## [1.7.3](https://github.com/strongloop/loopback-next/compare/@loopback/testlab@1.7.2...@loopback/testlab@1.7.3) (2019-08-15)
|
|
37
|
+
|
|
38
|
+
**Note:** Version bump only for package @loopback/testlab
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
6
44
|
## [1.7.2](https://github.com/strongloop/loopback-next/compare/@loopback/testlab@1.7.1...@loopback/testlab@1.7.2) (2019-07-31)
|
|
7
45
|
|
|
8
46
|
**Note:** Version bump only for package @loopback/testlab
|
package/dist/expect.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
|
7
8
|
/// <reference path="../should-as-function.d.ts" />
|
|
8
9
|
const shouldAsFunction = require('should/as-function');
|
|
9
10
|
shouldAsFunction.use((should, assertion) => {
|
package/dist/expect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../src/expect.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;AAEhE,mDAAmD;AAEnD,MAAM,gBAAgB,GAAa,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEjE,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE;IACzC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC,CAAC,CAAC;AAEU,QAAA,MAAM,GAAG,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../src/expect.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;AAEhE,qEAAqE;AACrE,mDAAmD;AAEnD,MAAM,gBAAgB,GAAa,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEjE,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE;IACzC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC,CAAC,CAAC;AAEU,QAAA,MAAM,GAAG,gBAAgB,CAAC"}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ServerOptions as HttpsServerOptions } from 'https';
|
|
3
|
-
|
|
3
|
+
import { ListenOptions } from 'net';
|
|
4
|
+
export interface HttpOptions extends ListenOptions {
|
|
5
|
+
protocol?: 'http';
|
|
6
|
+
}
|
|
7
|
+
export interface HttpsOptions extends ListenOptions, HttpsServerOptions {
|
|
8
|
+
protocol: 'https';
|
|
9
|
+
}
|
|
10
|
+
export declare type HostPort = {
|
|
4
11
|
host: string;
|
|
5
12
|
port: number;
|
|
6
|
-
}
|
|
13
|
+
};
|
|
7
14
|
/**
|
|
8
15
|
* Create an HTTP-server configuration that works well in test environments.
|
|
9
16
|
* - Ask the operating system to assign a free (ephemeral) port.
|
|
@@ -13,6 +20,4 @@ export declare type ConfigRetval<T extends object> = T & {
|
|
|
13
20
|
*
|
|
14
21
|
* @param customConfig - Additional configuration options to apply.
|
|
15
22
|
*/
|
|
16
|
-
export declare function givenHttpServerConfig<T extends
|
|
17
|
-
protocol?: string;
|
|
18
|
-
}): ConfigRetval<T>;
|
|
23
|
+
export declare function givenHttpServerConfig<T extends HttpOptions | HttpsOptions>(customConfig?: T): HostPort & T;
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const path = require("path");
|
|
8
7
|
const fs_1 = require("fs");
|
|
8
|
+
const path = require("path");
|
|
9
9
|
const FIXTURES = path.resolve(__dirname, '../fixtures');
|
|
10
10
|
const DUMMY_TLS_CONFIG = {
|
|
11
11
|
key: fs_1.readFileSync(path.join(FIXTURES, 'key.pem')),
|
|
@@ -31,7 +31,7 @@ function givenHttpServerConfig(customConfig) {
|
|
|
31
31
|
config.host = defaults.host;
|
|
32
32
|
if (config.port === undefined)
|
|
33
33
|
config.port = defaults.port;
|
|
34
|
-
if (
|
|
34
|
+
if (isHttpsConfig(config)) {
|
|
35
35
|
setupTlsConfig(config);
|
|
36
36
|
}
|
|
37
37
|
return config;
|
|
@@ -44,4 +44,7 @@ function setupTlsConfig(config) {
|
|
|
44
44
|
return;
|
|
45
45
|
Object.assign(config, DUMMY_TLS_CONFIG);
|
|
46
46
|
}
|
|
47
|
+
function isHttpsConfig(config) {
|
|
48
|
+
return config && config.protocol === 'https';
|
|
49
|
+
}
|
|
47
50
|
//# sourceMappingURL=http-server-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-server-config.js","sourceRoot":"","sources":["../src/http-server-config.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;AAEhE,
|
|
1
|
+
{"version":3,"file":"http-server-config.js","sourceRoot":"","sources":["../src/http-server-config.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;AAEhE,2BAAgC;AAGhC,6BAA6B;AAE7B,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;AACxD,MAAM,gBAAgB,GAAG;IACvB,GAAG,EAAE,iBAAY,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACjD,IAAI,EAAE,iBAAY,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;CACpD,CAAC;AAeF;;;;;;;;GAQG;AACH,SAAgB,qBAAqB,CACnC,YAAgB;IAEhB,MAAM,QAAQ,GAAG;QACf,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,CAAC;QACP,QAAQ,EAAE,SAAS;KACpB,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;IACzD,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAAE,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC3D,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAAE,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC3D,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE;QACzB,cAAc,CAAC,MAAM,CAAC,CAAC;KACxB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAfD,sDAeC;AAED,SAAS,cAAc,CAAC,MAA0B;IAChD,IAAI,KAAK,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM;QAAE,OAAO;IAChD,IAAI,KAAK,IAAI,MAAM;QAAE,OAAO;IAC5B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,aAAa,CACpB,MAAkC;IAElC,OAAO,MAAM,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC;AAC/C,CAAC"}
|
package/dist/test-sandbox.d.ts
CHANGED
|
@@ -41,4 +41,11 @@ export declare class TestSandbox {
|
|
|
41
41
|
* (relative to TestSandbox). Original filename used if not specified.
|
|
42
42
|
*/
|
|
43
43
|
copyFile(src: string, dest?: string): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new file and writes the given data serialized as JSON.
|
|
46
|
+
*
|
|
47
|
+
* @param dest - Destination filename, optionally including a relative path.
|
|
48
|
+
* @param data - The data to write.
|
|
49
|
+
*/
|
|
50
|
+
writeJsonFile(dest: string, data: unknown): Promise<void>;
|
|
44
51
|
}
|
package/dist/test-sandbox.js
CHANGED
|
@@ -4,19 +4,13 @@
|
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const path_1 = require("path");
|
|
8
7
|
const fs_extra_1 = require("fs-extra");
|
|
8
|
+
const path_1 = require("path");
|
|
9
9
|
/**
|
|
10
10
|
* TestSandbox class provides a convenient way to get a reference to a
|
|
11
11
|
* sandbox folder in which you can perform operations for testing purposes.
|
|
12
12
|
*/
|
|
13
13
|
class TestSandbox {
|
|
14
|
-
get path() {
|
|
15
|
-
if (!this._path) {
|
|
16
|
-
throw new Error(`TestSandbox instance was deleted. Create a new instance.`);
|
|
17
|
-
}
|
|
18
|
-
return this._path;
|
|
19
|
-
}
|
|
20
14
|
/**
|
|
21
15
|
* Will create a directory if it doesn't already exist. If it exists, you
|
|
22
16
|
* still get an instance of the TestSandbox.
|
|
@@ -28,6 +22,12 @@ class TestSandbox {
|
|
|
28
22
|
this._path = path_1.resolve(path);
|
|
29
23
|
fs_extra_1.ensureDirSync(this.path);
|
|
30
24
|
}
|
|
25
|
+
get path() {
|
|
26
|
+
if (!this._path) {
|
|
27
|
+
throw new Error(`TestSandbox instance was deleted. Create a new instance.`);
|
|
28
|
+
}
|
|
29
|
+
return this._path;
|
|
30
|
+
}
|
|
31
31
|
/**
|
|
32
32
|
* Returns the path of the TestSandbox
|
|
33
33
|
*/
|
|
@@ -83,6 +83,18 @@ class TestSandbox {
|
|
|
83
83
|
await fs_extra_1.appendFile(dest, `\n//# sourceMappingURL=${srcMap}`);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new file and writes the given data serialized as JSON.
|
|
88
|
+
*
|
|
89
|
+
* @param dest - Destination filename, optionally including a relative path.
|
|
90
|
+
* @param data - The data to write.
|
|
91
|
+
*/
|
|
92
|
+
async writeJsonFile(dest, data) {
|
|
93
|
+
dest = path_1.resolve(this.path, dest);
|
|
94
|
+
const destDir = path_1.parse(dest).dir;
|
|
95
|
+
await fs_extra_1.ensureDir(destDir);
|
|
96
|
+
return fs_extra_1.writeJson(dest, data, { spaces: 2 });
|
|
97
|
+
}
|
|
86
98
|
}
|
|
87
99
|
exports.TestSandbox = TestSandbox;
|
|
88
100
|
//# sourceMappingURL=test-sandbox.js.map
|
package/dist/test-sandbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-sandbox.js","sourceRoot":"","sources":["../src/test-sandbox.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;AAEhE,+BAAoC;
|
|
1
|
+
{"version":3,"file":"test-sandbox.js","sourceRoot":"","sources":["../src/test-sandbox.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;AAEhE,uCASkB;AAClB,+BAAoC;AAEpC;;;GAGG;AACH,MAAa,WAAW;IAatB;;;;;OAKG;IACH,YAAY,IAAY;QACtB,2EAA2E;QAC3E,IAAI,CAAC,KAAK,GAAG,cAAO,CAAC,IAAI,CAAC,CAAC;QAC3B,wBAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAnBD,IAAW,IAAI;QACb,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;SACH;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAcD;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,4EAA4E;QAC5E,uEAAuE;QACvE,wCAAwC;QACxC,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,KAAK,EAAE;YAC/B,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBAC7B,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aAC3B;SACF;QAED,MAAM,mBAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM;QACV,MAAM,iBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK,CAAC,GAAW;QACrB,MAAM,oBAAS,CAAC,cAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,QAAQ,CAAC,GAAW,EAAE,IAAa;QACvC,IAAI,GAAG,IAAI;YACT,CAAC,CAAC,cAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC;YAC1B,CAAC,CAAC,cAAO,CAAC,IAAI,CAAC,IAAI,EAAE,YAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;QAExC,MAAM,eAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAEtB,IAAI,YAAK,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,KAAK,IAAI,qBAAU,CAAC,GAAG,GAAG,MAAM,CAAC,EAAE;YACxD,MAAM,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC;YAC5B,MAAM,qBAAU,CAAC,IAAI,EAAE,0BAA0B,MAAM,EAAE,CAAC,CAAC;SAC5D;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,IAAY,EAAE,IAAa;QAC7C,IAAI,GAAG,cAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChC,MAAM,OAAO,GAAG,YAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC;QAChC,MAAM,oBAAS,CAAC,OAAO,CAAC,CAAC;QACzB,OAAO,oBAAS,CAAC,IAAI,EAAE,IAAI,EAAE,EAAC,MAAM,EAAE,CAAC,EAAC,CAAC,CAAC;IAC5C,CAAC;CACF;AApGD,kCAoGC"}
|
package/dist/to-json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-json.js","sourceRoot":"","sources":["../src/to-json.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;
|
|
1
|
+
{"version":3,"file":"to-json.js","sourceRoot":"","sources":["../src/to-json.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;AAgDhE,SAAgB,MAAM,CAAI,KAAQ;IAChC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAC,KAAK,EAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACnD,CAAC;AAFD,wBAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/testlab",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "A collection of test utilities we use to write LoopBack tests.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.9"
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"copyright.owner": "IBM Corp.",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@hapi/shot": "^4.
|
|
20
|
-
"@types/express": "^4.17.
|
|
19
|
+
"@hapi/shot": "^4.1.1",
|
|
20
|
+
"@types/express": "^4.17.1",
|
|
21
21
|
"@types/fs-extra": "^8.0.0",
|
|
22
22
|
"@types/shot": "^4.0.0",
|
|
23
23
|
"@types/sinon": "^7.0.13",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"fs-extra": "^8.1.0",
|
|
27
27
|
"oas-validator": "^3.3.1",
|
|
28
28
|
"should": "^13.2.3",
|
|
29
|
-
"sinon": "^7.
|
|
29
|
+
"sinon": "^7.4.2",
|
|
30
30
|
"supertest": "^4.0.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@loopback/build": "^2.0.
|
|
34
|
-
"@loopback/eslint-config": "^
|
|
35
|
-
"@types/node": "^10.14.
|
|
33
|
+
"@loopback/build": "^2.0.10",
|
|
34
|
+
"@loopback/eslint-config": "^4.0.2",
|
|
35
|
+
"@types/node": "^10.14.17"
|
|
36
36
|
},
|
|
37
37
|
"files": [
|
|
38
38
|
"README.md",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"url": "https://github.com/strongloop/loopback-next.git",
|
|
50
50
|
"directory": "packages/testlab"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "4e653bbff797b26437bd1b0817ed9b8c91f3477b"
|
|
53
53
|
}
|
package/src/expect.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
|
6
7
|
/// <reference path="../should-as-function.d.ts" />
|
|
7
8
|
|
|
8
9
|
const shouldAsFunction: Internal = require('should/as-function');
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
|
-
import * as path from 'path';
|
|
7
6
|
import {readFileSync} from 'fs';
|
|
8
7
|
import {ServerOptions as HttpsServerOptions} from 'https';
|
|
8
|
+
import {ListenOptions} from 'net';
|
|
9
|
+
import * as path from 'path';
|
|
9
10
|
|
|
10
11
|
const FIXTURES = path.resolve(__dirname, '../fixtures');
|
|
11
12
|
const DUMMY_TLS_CONFIG = {
|
|
@@ -13,10 +14,18 @@ const DUMMY_TLS_CONFIG = {
|
|
|
13
14
|
cert: readFileSync(path.join(FIXTURES, 'cert.pem')),
|
|
14
15
|
};
|
|
15
16
|
|
|
16
|
-
export
|
|
17
|
+
export interface HttpOptions extends ListenOptions {
|
|
18
|
+
protocol?: 'http';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface HttpsOptions extends ListenOptions, HttpsServerOptions {
|
|
22
|
+
protocol: 'https';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type HostPort = {
|
|
17
26
|
host: string;
|
|
18
27
|
port: number;
|
|
19
|
-
}
|
|
28
|
+
};
|
|
20
29
|
|
|
21
30
|
/**
|
|
22
31
|
* Create an HTTP-server configuration that works well in test environments.
|
|
@@ -27,18 +36,18 @@ export type ConfigRetval<T extends object> = T & {
|
|
|
27
36
|
*
|
|
28
37
|
* @param customConfig - Additional configuration options to apply.
|
|
29
38
|
*/
|
|
30
|
-
export function givenHttpServerConfig<T extends
|
|
31
|
-
customConfig?: T
|
|
32
|
-
):
|
|
39
|
+
export function givenHttpServerConfig<T extends HttpOptions | HttpsOptions>(
|
|
40
|
+
customConfig?: T,
|
|
41
|
+
): HostPort & T {
|
|
33
42
|
const defaults = {
|
|
34
43
|
host: '127.0.0.1',
|
|
35
44
|
port: 0,
|
|
36
45
|
protocol: undefined,
|
|
37
46
|
};
|
|
38
|
-
const config
|
|
47
|
+
const config = Object.assign({}, defaults, customConfig);
|
|
39
48
|
if (config.host === undefined) config.host = defaults.host;
|
|
40
49
|
if (config.port === undefined) config.port = defaults.port;
|
|
41
|
-
if (
|
|
50
|
+
if (isHttpsConfig(config)) {
|
|
42
51
|
setupTlsConfig(config);
|
|
43
52
|
}
|
|
44
53
|
return config;
|
|
@@ -49,3 +58,9 @@ function setupTlsConfig(config: HttpsServerOptions) {
|
|
|
49
58
|
if ('pfx' in config) return;
|
|
50
59
|
Object.assign(config, DUMMY_TLS_CONFIG);
|
|
51
60
|
}
|
|
61
|
+
|
|
62
|
+
function isHttpsConfig(
|
|
63
|
+
config: HttpOptions | HttpsOptions,
|
|
64
|
+
): config is HttpsOptions {
|
|
65
|
+
return config && config.protocol === 'https';
|
|
66
|
+
}
|
package/src/test-sandbox.ts
CHANGED
|
@@ -3,16 +3,17 @@
|
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
|
-
import {resolve, parse} from 'path';
|
|
7
6
|
import {
|
|
7
|
+
appendFile,
|
|
8
8
|
copy,
|
|
9
|
-
ensureDirSync,
|
|
10
9
|
emptyDir,
|
|
11
|
-
remove,
|
|
12
10
|
ensureDir,
|
|
11
|
+
ensureDirSync,
|
|
13
12
|
pathExists,
|
|
14
|
-
|
|
13
|
+
remove,
|
|
14
|
+
writeJson,
|
|
15
15
|
} from 'fs-extra';
|
|
16
|
+
import {parse, resolve} from 'path';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* TestSandbox class provides a convenient way to get a reference to a
|
|
@@ -105,4 +106,17 @@ export class TestSandbox {
|
|
|
105
106
|
await appendFile(dest, `\n//# sourceMappingURL=${srcMap}`);
|
|
106
107
|
}
|
|
107
108
|
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Creates a new file and writes the given data serialized as JSON.
|
|
112
|
+
*
|
|
113
|
+
* @param dest - Destination filename, optionally including a relative path.
|
|
114
|
+
* @param data - The data to write.
|
|
115
|
+
*/
|
|
116
|
+
async writeJsonFile(dest: string, data: unknown): Promise<void> {
|
|
117
|
+
dest = resolve(this.path, dest);
|
|
118
|
+
const destDir = parse(dest).dir;
|
|
119
|
+
await ensureDir(destDir);
|
|
120
|
+
return writeJson(dest, data, {spaces: 2});
|
|
121
|
+
}
|
|
108
122
|
}
|
package/src/to-json.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
|
+
/* eslint-disable @typescript-eslint/unified-signatures */
|
|
7
|
+
|
|
6
8
|
// Important! Date.prototype.toJSON() returns a string.
|
|
7
9
|
export function toJSON(value: Date): string;
|
|
8
10
|
|