@loopback/testlab 4.0.0-alpha.8 → 4.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.
- package/LICENSE +25 -0
- package/README.md +411 -20
- package/dist/client.d.ts +25 -0
- package/dist/client.js +40 -0
- package/dist/client.js.map +1 -0
- package/dist/expect.d.ts +2 -0
- package/{lib/testlab.js → dist/expect.js} +4 -11
- package/dist/expect.js.map +1 -0
- package/dist/http-error-logger.d.ts +9 -0
- package/dist/http-error-logger.js +23 -0
- package/dist/http-error-logger.js.map +1 -0
- package/dist/http-server-config.d.ts +26 -0
- package/dist/http-server-config.js +76 -0
- package/dist/http-server-config.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/request.d.ts +13 -0
- package/dist/request.js +40 -0
- package/dist/request.js.map +1 -0
- package/dist/shot.d.ts +24 -0
- package/dist/shot.js +108 -0
- package/dist/shot.js.map +1 -0
- package/dist/sinon.d.ts +25 -0
- package/dist/sinon.js +35 -0
- package/dist/sinon.js.map +1 -0
- package/dist/skip.d.ts +49 -0
- package/dist/skip.js +65 -0
- package/dist/skip.js.map +1 -0
- package/dist/test-sandbox.d.ts +89 -0
- package/dist/test-sandbox.js +139 -0
- package/dist/test-sandbox.js.map +1 -0
- package/dist/to-json.d.ts +23 -0
- package/dist/to-json.js +12 -0
- package/dist/to-json.js.map +1 -0
- package/dist/validate-api-spec.d.ts +1 -0
- package/dist/validate-api-spec.js +16 -0
- package/dist/validate-api-spec.js.map +1 -0
- package/fixtures/README.md +9 -0
- package/fixtures/cert.pem +21 -0
- package/fixtures/copy-me.txt +1 -0
- package/fixtures/key.pem +28 -0
- package/fixtures/pfx.pfx +0 -0
- package/package.json +46 -32
- package/should-as-function.d.ts +12 -3
- package/src/client.ts +57 -0
- package/src/expect.ts +15 -0
- package/src/http-error-logger.ts +35 -0
- package/src/http-server-config.ts +97 -0
- package/src/index.ts +37 -0
- package/src/request.ts +45 -0
- package/src/shot.ts +191 -0
- package/src/sinon.ts +38 -0
- package/src/skip.ts +76 -0
- package/src/test-sandbox.ts +181 -0
- package/src/to-json.ts +54 -0
- package/src/validate-api-spec.ts +14 -0
- package/index.d.ts +0 -6
- package/index.js +0 -9
- package/lib/client.d.ts +0 -19
- package/lib/client.js +0 -31
- package/lib/client.js.map +0 -1
- package/lib/shot.d.ts +0 -17
- package/lib/shot.js +0 -36
- package/lib/shot.js.map +0 -1
- package/lib/testlab.d.ts +0 -9
- package/lib/testlab.js.map +0 -1
- package/lib/validate-api-spec.d.ts +0 -2
- package/lib/validate-api-spec.js +0 -29
- package/lib/validate-api-spec.js.map +0 -1
- package/lib6/client.d.ts +0 -19
- package/lib6/client.js +0 -41
- package/lib6/client.js.map +0 -1
- package/lib6/shot.d.ts +0 -17
- package/lib6/shot.js +0 -36
- package/lib6/shot.js.map +0 -1
- package/lib6/testlab.d.ts +0 -9
- package/lib6/testlab.js +0 -22
- package/lib6/testlab.js.map +0 -1
- package/lib6/validate-api-spec.d.ts +0 -2
- package/lib6/validate-api-spec.js +0 -39
- package/lib6/validate-api-spec.js.map +0 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/testlab
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.TestSandbox = void 0;
|
|
8
|
+
const fs_extra_1 = require("fs-extra");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
/**
|
|
11
|
+
* TestSandbox class provides a convenient way to get a reference to a
|
|
12
|
+
* sandbox folder in which you can perform operations for testing purposes.
|
|
13
|
+
*/
|
|
14
|
+
class TestSandbox {
|
|
15
|
+
/**
|
|
16
|
+
* Will create a directory if it doesn't already exist. If it exists, you
|
|
17
|
+
* still get an instance of the TestSandbox.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* // Create a sandbox as a unique temporary subdirectory under the rootPath
|
|
22
|
+
* const sandbox = new TestSandbox(rootPath);
|
|
23
|
+
* const sandbox = new TestSandbox(rootPath, {subdir: true});
|
|
24
|
+
*
|
|
25
|
+
* // Create a sandbox in the root path directly
|
|
26
|
+
* // This is same as the old behavior
|
|
27
|
+
* const sandbox = new TestSandbox(rootPath, {subdir: false});
|
|
28
|
+
*
|
|
29
|
+
* // Create a sandbox in the `test1` subdirectory of the root path
|
|
30
|
+
* const sandbox = new TestSandbox(rootPath, {subdir: 'test1'});
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param rootPath - Root path of the TestSandbox. If relative it will be
|
|
34
|
+
* resolved against the current directory.
|
|
35
|
+
* @param options - Options to control if/how the sandbox creates a
|
|
36
|
+
* subdirectory for the sandbox. If not provided, the sandbox
|
|
37
|
+
* will automatically creates a unique temporary subdirectory. This allows
|
|
38
|
+
* sandboxes with the same root path can be used in parallel during testing.
|
|
39
|
+
*/
|
|
40
|
+
constructor(rootPath, options) {
|
|
41
|
+
rootPath = (0, path_1.resolve)(rootPath);
|
|
42
|
+
(0, fs_extra_1.ensureDirSync)(rootPath);
|
|
43
|
+
options = { subdir: true, ...options };
|
|
44
|
+
const subdir = typeof options.subdir === 'string' ? options.subdir : '.';
|
|
45
|
+
if (options.subdir !== true) {
|
|
46
|
+
this._path = (0, path_1.resolve)(rootPath, subdir);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// Create a unique temporary directory under the root path
|
|
50
|
+
// See https://nodejs.org/api/fs.html#fs_fs_mkdtempsync_prefix_options
|
|
51
|
+
this._path = (0, fs_extra_1.mkdtempSync)((0, path_1.join)(rootPath, `/${process.pid}`));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
get path() {
|
|
55
|
+
if (!this._path) {
|
|
56
|
+
throw new Error(`TestSandbox instance was deleted. Create a new instance.`);
|
|
57
|
+
}
|
|
58
|
+
return this._path;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Resets the TestSandbox. (Remove all files in it).
|
|
62
|
+
*/
|
|
63
|
+
async reset() {
|
|
64
|
+
// Decache files from require's cache so future tests aren't affected incase
|
|
65
|
+
// a file is recreated in sandbox with the same file name but different
|
|
66
|
+
// contents after resetting the sandbox.
|
|
67
|
+
for (const key in require.cache) {
|
|
68
|
+
if (key.startsWith(this.path)) {
|
|
69
|
+
delete require.cache[key];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
await (0, fs_extra_1.emptyDir)(this.path);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Deletes the TestSandbox.
|
|
76
|
+
*/
|
|
77
|
+
async delete() {
|
|
78
|
+
await (0, fs_extra_1.remove)(this.path);
|
|
79
|
+
delete this._path;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Makes a directory in the TestSandbox
|
|
83
|
+
*
|
|
84
|
+
* @param dir - Name of directory to create (relative to TestSandbox path)
|
|
85
|
+
*/
|
|
86
|
+
async mkdir(dir) {
|
|
87
|
+
await (0, fs_extra_1.ensureDir)((0, path_1.resolve)(this.path, dir));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Copies a file from src to the TestSandbox. If copying a `.js` file which
|
|
91
|
+
* has an accompanying `.js.map` file in the src file location, the dest file
|
|
92
|
+
* will have its sourceMappingURL updated to point to the original file as
|
|
93
|
+
* an absolute path so you don't need to copy the map file.
|
|
94
|
+
*
|
|
95
|
+
* @param src - Absolute path of file to be copied to the TestSandbox
|
|
96
|
+
* @param dest - Optional. Destination filename of the copy operation
|
|
97
|
+
* (relative to TestSandbox). Original filename used if not specified.
|
|
98
|
+
* @param transform - Optional. A function to transform the file content.
|
|
99
|
+
*/
|
|
100
|
+
async copyFile(src, dest, transform) {
|
|
101
|
+
dest = dest
|
|
102
|
+
? (0, path_1.resolve)(this.path, dest)
|
|
103
|
+
: (0, path_1.resolve)(this.path, (0, path_1.parse)(src).base);
|
|
104
|
+
if (transform == null) {
|
|
105
|
+
await (0, fs_extra_1.copy)(src, dest);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
let content = await (0, fs_extra_1.readFile)(src, 'utf-8');
|
|
109
|
+
content = transform(content);
|
|
110
|
+
await (0, fs_extra_1.outputFile)(dest, content, { encoding: 'utf-8' });
|
|
111
|
+
}
|
|
112
|
+
if ((0, path_1.parse)(src).ext === '.js' && (await (0, fs_extra_1.pathExists)(src + '.map'))) {
|
|
113
|
+
const srcMap = src + '.map';
|
|
114
|
+
await (0, fs_extra_1.appendFile)(dest, `\n//# sourceMappingURL=${srcMap}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new file and writes the given data serialized as JSON.
|
|
119
|
+
*
|
|
120
|
+
* @param dest - Destination filename, optionally including a relative path.
|
|
121
|
+
* @param data - The data to write.
|
|
122
|
+
*/
|
|
123
|
+
async writeJsonFile(dest, data) {
|
|
124
|
+
dest = (0, path_1.resolve)(this.path, dest);
|
|
125
|
+
return (0, fs_extra_1.outputJson)(dest, data, { spaces: 2 });
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Creates a new file and writes the given data as a UTF-8-encoded text.
|
|
129
|
+
*
|
|
130
|
+
* @param dest - Destination filename, optionally including a relative path.
|
|
131
|
+
* @param data - The text to write.
|
|
132
|
+
*/
|
|
133
|
+
async writeTextFile(dest, data) {
|
|
134
|
+
dest = (0, path_1.resolve)(this.path, dest);
|
|
135
|
+
return (0, fs_extra_1.outputFile)(dest, data, 'utf-8');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.TestSandbox = TestSandbox;
|
|
139
|
+
//# sourceMappingURL=test-sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-sand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AAM,GAAG,GAAG,GAAG,MAAM,CAAC;YAC5B,MAAM,IAAA,qBAAU,EAAC,IAAI,EAAE,0BAA0B,MAAM,EAAE,CAAC,CAAC;SAC5D;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,IAAY,EAAE,IAAa;QAC7C,IAAI,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChC,OAAO,IAAA,qBAAU,EAAC,IAAI,EAAE,IAAI,EAAE,EAAC,MAAM,EAAE,CAAC,EAAC,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,IAAY,EAAE,IAAY;QAC5C,IAAI,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChC,OAAO,IAAA,qBAAU,EAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;CACF;AA5ID,kCA4IC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare function toJSON(value: Date): string;
|
|
2
|
+
export declare function toJSON(value: Function): undefined;
|
|
3
|
+
export declare function toJSON(value: unknown[]): unknown[];
|
|
4
|
+
/**
|
|
5
|
+
* JSON encoding does not preserve properties that are undefined
|
|
6
|
+
* As a result, deepEqual checks fail because the expected model
|
|
7
|
+
* value contains these undefined property values, while the actual
|
|
8
|
+
* result returned by REST API does not.
|
|
9
|
+
* Use this function to convert a model instance into a data object
|
|
10
|
+
* as returned by REST API
|
|
11
|
+
*/
|
|
12
|
+
export declare function toJSON(value: object): object;
|
|
13
|
+
export declare function toJSON(value: undefined): undefined;
|
|
14
|
+
export declare function toJSON(value: null): null;
|
|
15
|
+
export declare function toJSON(value: number): number;
|
|
16
|
+
export declare function toJSON(value: boolean): boolean;
|
|
17
|
+
export declare function toJSON(value: string): string;
|
|
18
|
+
export declare function toJSON(value: unknown[] | null): unknown[] | null;
|
|
19
|
+
export declare function toJSON(value: unknown[] | undefined): unknown[] | undefined;
|
|
20
|
+
export declare function toJSON(value: unknown[] | null | undefined): unknown[] | null | undefined;
|
|
21
|
+
export declare function toJSON(value: object | null): object | null;
|
|
22
|
+
export declare function toJSON(value: object | undefined): object | undefined;
|
|
23
|
+
export declare function toJSON(value: object | null | undefined): object | null | undefined;
|
package/dist/to-json.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,2019. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/testlab
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.toJSON = void 0;
|
|
8
|
+
function toJSON(value) {
|
|
9
|
+
return JSON.parse(JSON.stringify({ value })).value;
|
|
10
|
+
}
|
|
11
|
+
exports.toJSON = toJSON;
|
|
12
|
+
//# sourceMappingURL=to-json.js.map
|
|
@@ -0,0 +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;;;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validateApiSpec(spec: any): Promise<void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2017,2019. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/testlab
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.validateApiSpec = void 0;
|
|
8
|
+
const validator = require('oas-validator');
|
|
9
|
+
const util_1 = require("util");
|
|
10
|
+
const validateAsync = (0, util_1.promisify)(validator.validate);
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
async function validateApiSpec(spec) {
|
|
13
|
+
await validateAsync(spec, {});
|
|
14
|
+
}
|
|
15
|
+
exports.validateApiSpec = validateApiSpec;
|
|
16
|
+
//# sourceMappingURL=validate-api-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-api-spec.js","sourceRoot":"","sources":["../src/validate-api-spec.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,MAAM,SAAS,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAC3C,+BAA+B;AAE/B,MAAM,aAAa,GAAG,IAAA,gBAAS,EAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AAEpD,8DAA8D;AACvD,KAAK,UAAU,eAAe,CAAC,IAAS;IAC7C,MAAM,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAChC,CAAC;AAFD,0CAEC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIIDaDCCAlACCQDSmMwp5CM+CzANBgkqhkiG9w0BAQUFADB2MQswCQYDVQQGEwJV
|
|
3
|
+
UzELMAkGA1UECAwCQ0ExCzAJBgNVBAcMAlNGMQswCQYDVQQKDAJMQjEMMAoGA1UE
|
|
4
|
+
CwwDTEI0MRIwEAYDVQQDDAlsb2NhbGhvc3QxHjAcBgkqhkiG9w0BCQEWD2xiNEBl
|
|
5
|
+
eGFtcGxlLmNvbTAeFw0xODA2MjgxNDMwNTdaFw0xOTA2MjgxNDMwNTdaMHYxCzAJ
|
|
6
|
+
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sy//Ok7xSCTXgE09iouZsjaP9r6nSKlG3SO18Hvy4CI
|
|
15
|
+
whRzu95Z2vZQLYHuCCwLnqIhpM7xnFL93ueud7ATiE3fGFhJNUMGTYTQ+ZmwFuFQ
|
|
16
|
+
7eddWrqVOEqezy2btpnsIVkINwKBgQDgIl4sZ7fl98S64+K0fcB0rCnrciL7OBap
|
|
17
|
+
aucHuzmjydaVWW5WkzUOMxh+er2Zeqt1+0cTjnV6J7DJ96d/R8eWkNjTVtULJezf
|
|
18
|
+
z91titYbB3O6TwYLx4IzXoweHuC/uLhE27Jxnvgz2IZacK1fKvql1lM5MaP7GDZ8
|
|
19
|
+
VPvmiUFrfwKBgEABs+4JKzJ0/Hwr7pcmALUCi+GtbmpxzGJDALUj2dAe6J55A8Ze
|
|
20
|
+
j6tKxEJBACeOo5027z3vdyVvVJ0aCF9tmD25f0PhGuQFM5JJWN/sryoPH15eZ8M0
|
|
21
|
+
4ehinGmvlP+8YLLBywvRiMAnxQRMH6aG7B/n9tAXCSaPSgzMrGiF1qttAoGBAJ51
|
|
22
|
+
Dbk9FpFZ6tbqF7PdF7wkn3padgq/q53Y+z7HCcgXAUMTN+OzLRY933pD0ll4lVHS
|
|
23
|
+
9XwJAlr7RoxzLxLYL23uN6yqPfIkvOO6dGRmfFodmZ7FEZQwV4dzt4Hv+JrywCvG
|
|
24
|
+
WtDjP7x/vvSfpqKaoxute6b6xmDVzGd4OaLRtNOHAoGAUyockJhGQEkUG9A21DXv
|
|
25
|
+
hqR343WeUne1tqwfxkg0DQIBAaaFgGkeL1DjdHhE5ZNz+F/t5LRcvMkZDShRK0u3
|
|
26
|
+
Ytnw2XtSJYtCrPlnDrt1/59dBr7S1nbhStI5xfPojctd0DbVvhC5UfQMKSNHOLCs
|
|
27
|
+
tUWwM07FtltvXMoC0xXf5sI=
|
|
28
|
+
-----END PRIVATE KEY-----
|
package/fixtures/pfx.pfx
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,43 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/testlab",
|
|
3
|
-
"version": "4.0.0-alpha.8",
|
|
4
3
|
"description": "A collection of test utilities we use to write LoopBack tests.",
|
|
4
|
+
"version": "4.1.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"author": "IBM Corp.",
|
|
9
|
+
"copyright.owner": "IBM Corp.",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/loopbackio/loopback-next.git",
|
|
13
|
+
"directory": "packages/testlab"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": "12 || 14 || 16 || 17"
|
|
17
|
+
},
|
|
5
18
|
"scripts": {
|
|
6
|
-
"build": "
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"clean": "rm -rf loopback-testlab*.tgz lib* package",
|
|
11
|
-
"prepublish": "npm run build",
|
|
12
|
-
"pretest": "npm run build:current",
|
|
13
|
-
"test": "mocha",
|
|
19
|
+
"build": "lb-tsc",
|
|
20
|
+
"clean": "lb-clean loopback-testlab*.tgz dist *.tsbuildinfo package",
|
|
21
|
+
"pretest": "npm run build",
|
|
22
|
+
"test": "lb-mocha \"dist/__tests__/**/*.js\"",
|
|
14
23
|
"verify": "npm pack && tar xf loopback-testlab*.tgz && tree package && npm run clean"
|
|
15
24
|
},
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"@loopback/openapi-spec": "^4.0.0-alpha.10",
|
|
20
|
-
"@types/shot": "^3.4.0",
|
|
21
|
-
"@types/sinon": "^2.3.2",
|
|
22
|
-
"@types/supertest": "^2.0.0",
|
|
23
|
-
"@types/swagger-parser": "^4.0.1",
|
|
24
|
-
"shot": "^3.4.0",
|
|
25
|
-
"should": "^11.2.1",
|
|
26
|
-
"should-sinon": "0.0.5",
|
|
27
|
-
"sinon": "^2.4.0",
|
|
28
|
-
"supertest": "^3.0.0",
|
|
29
|
-
"swagger-parser": "^3.4.1"
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
30
27
|
},
|
|
31
28
|
"files": [
|
|
32
29
|
"README.md",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
30
|
+
"dist",
|
|
31
|
+
"fixtures",
|
|
32
|
+
"should-as-function.d.ts",
|
|
33
|
+
"src",
|
|
34
|
+
"!*/__tests__"
|
|
38
35
|
],
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@hapi/shot": "^5.0.5",
|
|
38
|
+
"@types/express": "^4.17.13",
|
|
39
|
+
"@types/fs-extra": "^9.0.13",
|
|
40
|
+
"@types/shot": "^4.0.1",
|
|
41
|
+
"@types/sinon": "^10.0.11",
|
|
42
|
+
"@types/supertest": "^2.0.11",
|
|
43
|
+
"express": "^4.17.2",
|
|
44
|
+
"fs-extra": "^10.0.0",
|
|
45
|
+
"oas-validator": "^5.0.8",
|
|
46
|
+
"should": "^13.2.3",
|
|
47
|
+
"sinon": "^11.1.2",
|
|
48
|
+
"supertest": "^6.2.2",
|
|
49
|
+
"tslib": "^2.3.1"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@loopback/build": "^8.1.0",
|
|
53
|
+
"@loopback/eslint-config": "^12.0.2",
|
|
54
|
+
"@types/node": "^12.20.43"
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "e16818ccb01edc0269ef6c45b022c5f1b67f852c"
|
|
43
57
|
}
|
package/should-as-function.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2017,2019. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/testlab
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
1
6
|
// Type definitions for should.js v8.1.1
|
|
2
7
|
// Project: https://github.com/shouldjs/should.js
|
|
3
8
|
// Definitions by: Alex Varju <https://github.com/varju/>, Maxime LUCE <https://github.com/SomaticIT/>
|
|
@@ -19,6 +24,9 @@ interface Object {
|
|
|
19
24
|
}
|
|
20
25
|
*/
|
|
21
26
|
|
|
27
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
28
|
+
/* eslint-disable @typescript-eslint/unified-signatures */
|
|
29
|
+
|
|
22
30
|
interface ShouldAssertion {
|
|
23
31
|
// basic grammar
|
|
24
32
|
a: ShouldAssertion;
|
|
@@ -113,7 +121,8 @@ interface ShouldAssertion {
|
|
|
113
121
|
enumerables(...properties: string[]): ShouldAssertion;
|
|
114
122
|
startWith(expected: string, message?: any): ShouldAssertion;
|
|
115
123
|
endWith(expected: string, message?: any): ShouldAssertion;
|
|
116
|
-
throw(
|
|
124
|
+
throw(propereties?: {}): ShouldAssertion;
|
|
125
|
+
throw(message: Function | string | RegExp, properties?: {}): ShouldAssertion;
|
|
117
126
|
|
|
118
127
|
//promises
|
|
119
128
|
eventually: ShouldAssertion;
|
|
@@ -121,7 +130,8 @@ interface ShouldAssertion {
|
|
|
121
130
|
fulfilled(): Promise<any>;
|
|
122
131
|
fulfilledWith(value: any): Promise<any>;
|
|
123
132
|
rejected(): Promise<any>;
|
|
124
|
-
rejectedWith(err:
|
|
133
|
+
rejectedWith(err: Function | string | RegExp, properties?: {}): Promise<any>;
|
|
134
|
+
rejectedWith(properties: {}): Promise<any>;
|
|
125
135
|
|
|
126
136
|
//http
|
|
127
137
|
header(field: string, val?: string): ShouldAssertion;
|
|
@@ -204,7 +214,6 @@ interface Internal extends ShouldInternal {
|
|
|
204
214
|
}
|
|
205
215
|
|
|
206
216
|
declare var should: Internal;
|
|
207
|
-
declare var Should: Internal;
|
|
208
217
|
interface Window {
|
|
209
218
|
Should: Internal;
|
|
210
219
|
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/testlab
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* HTTP client utilities
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import http from 'http';
|
|
11
|
+
import supertest from 'supertest';
|
|
12
|
+
|
|
13
|
+
export {supertest};
|
|
14
|
+
|
|
15
|
+
export type Client = supertest.SuperTest<supertest.Test>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create a SuperTest client connected to an HTTP server listening
|
|
19
|
+
* on an ephemeral port and calling `handler` to handle incoming requests.
|
|
20
|
+
* @param handler
|
|
21
|
+
*/
|
|
22
|
+
export function createClientForHandler(
|
|
23
|
+
handler: (req: http.IncomingMessage, res: http.ServerResponse) => void,
|
|
24
|
+
): Client {
|
|
25
|
+
const server = http.createServer(handler);
|
|
26
|
+
return supertest(server);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create a SuperTest client for a running RestApplication instance.
|
|
31
|
+
* It is the responsibility of the caller to ensure that the app
|
|
32
|
+
* is running and to stop the application after all tests are done.
|
|
33
|
+
* @param app - A running (listening) instance of a RestApplication.
|
|
34
|
+
*/
|
|
35
|
+
export function createRestAppClient(app: RestApplicationLike) {
|
|
36
|
+
const url = app.restServer.rootUrl ?? app.restServer.url;
|
|
37
|
+
if (!url) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Cannot create client for ${app.constructor.name}, it is not listening.`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return supertest(url);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* These interfaces are meant to partially mirror the formats provided
|
|
47
|
+
* in our other libraries to avoid circular imports.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
export interface RestApplicationLike {
|
|
51
|
+
restServer: RestServerLike;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface RestServerLike {
|
|
55
|
+
url?: string;
|
|
56
|
+
rootUrl?: string;
|
|
57
|
+
}
|
package/src/expect.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/testlab
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
|
7
|
+
/// <reference path="../should-as-function.d.ts" />
|
|
8
|
+
|
|
9
|
+
const shouldAsFunction: Internal = require('should/as-function');
|
|
10
|
+
|
|
11
|
+
shouldAsFunction.use((should, assertion) => {
|
|
12
|
+
assertion.addChain('to');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const expect = shouldAsFunction;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2019. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/testlab
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import {Request} from 'express';
|
|
7
|
+
import {IncomingMessage} from 'http';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Logger that logs an Error if the HTTP status code is not expected
|
|
11
|
+
*
|
|
12
|
+
* @param expectedStatusCode - HTTP status code that is expected
|
|
13
|
+
*/
|
|
14
|
+
export function createUnexpectedHttpErrorLogger(
|
|
15
|
+
expectedStatusCode?: number,
|
|
16
|
+
): LogError {
|
|
17
|
+
return function logUnexpectedHttpError(
|
|
18
|
+
err: Error,
|
|
19
|
+
statusCode: number,
|
|
20
|
+
req: IncomingMessage,
|
|
21
|
+
) {
|
|
22
|
+
if (statusCode === expectedStatusCode) return;
|
|
23
|
+
|
|
24
|
+
/* istanbul ignore next */
|
|
25
|
+
console.error(
|
|
26
|
+
'Unhandled error in %s %s: %s %s',
|
|
27
|
+
req.method,
|
|
28
|
+
req.url,
|
|
29
|
+
statusCode,
|
|
30
|
+
err.stack ?? err,
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type LogError = (err: Error, statusCode: number, request: Request) => void;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/testlab
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import assert from 'assert';
|
|
7
|
+
import {readFileSync} from 'fs';
|
|
8
|
+
import {ServerOptions as HttpsServerOptions} from 'https';
|
|
9
|
+
import {ListenOptions} from 'net';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
|
|
12
|
+
const FIXTURES = path.resolve(__dirname, '../fixtures');
|
|
13
|
+
const DUMMY_TLS_CONFIG = {
|
|
14
|
+
key: readFileSync(path.join(FIXTURES, 'key.pem')),
|
|
15
|
+
cert: readFileSync(path.join(FIXTURES, 'cert.pem')),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export interface HttpOptions extends ListenOptions {
|
|
19
|
+
protocol?: 'http';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface HttpsOptions extends ListenOptions, HttpsServerOptions {
|
|
23
|
+
protocol: 'https';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* An object that requires host and port properties
|
|
28
|
+
*/
|
|
29
|
+
export interface HostPort {
|
|
30
|
+
host: string;
|
|
31
|
+
port: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Assertion type guard for TypeScript to ensure `host` and `port` are set
|
|
36
|
+
* @param config - Host/port configuration
|
|
37
|
+
*/
|
|
38
|
+
function assertHostPort(config: Partial<HostPort>): asserts config is HostPort {
|
|
39
|
+
assert(config.host != null, 'host is not set');
|
|
40
|
+
assert(config.port != null, 'port is not set');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create an HTTP-server configuration that works well in test environments.
|
|
45
|
+
* - Ask the operating system to assign a free (ephemeral) port.
|
|
46
|
+
* - Use IPv4 localhost `127.0.0.1` to avoid known IPv6 issues in Docker-based
|
|
47
|
+
* environments like Travis-CI.
|
|
48
|
+
* - Provide default TLS key & cert when `protocol` is set to `https`.
|
|
49
|
+
*
|
|
50
|
+
* @param customConfig - Additional configuration options to apply.
|
|
51
|
+
*/
|
|
52
|
+
export function givenHttpServerConfig<T extends HttpOptions | HttpsOptions>(
|
|
53
|
+
customConfig?: T,
|
|
54
|
+
): HostPort & T {
|
|
55
|
+
const defaults: HostPort = {host: '127.0.0.1', port: 0};
|
|
56
|
+
|
|
57
|
+
if (isHttpsConfig(customConfig)) {
|
|
58
|
+
const config: T = {...customConfig};
|
|
59
|
+
if (config.host == null) config.host = defaults.host;
|
|
60
|
+
if (config.port == null) config.port = defaults.port;
|
|
61
|
+
setupTlsConfig(config);
|
|
62
|
+
assertHostPort(config);
|
|
63
|
+
return config;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
assertHttpConfig(customConfig);
|
|
67
|
+
const config: T = {...customConfig};
|
|
68
|
+
if (config.host == null) config.host = defaults.host;
|
|
69
|
+
if (config.port == null) config.port = defaults.port;
|
|
70
|
+
assertHostPort(config);
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function setupTlsConfig(config: HttpsServerOptions) {
|
|
75
|
+
if ('key' in config && 'cert' in config) return;
|
|
76
|
+
if ('pfx' in config) return;
|
|
77
|
+
Object.assign(config, DUMMY_TLS_CONFIG);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Type guard to check if the parameter is `HttpsOptions`
|
|
82
|
+
*/
|
|
83
|
+
function isHttpsConfig(
|
|
84
|
+
config?: HttpOptions | HttpsOptions,
|
|
85
|
+
): config is HttpsOptions {
|
|
86
|
+
return config?.protocol === 'https';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Type guard to assert the parameter is `HttpOptions`
|
|
91
|
+
* @param config - Http config
|
|
92
|
+
*/
|
|
93
|
+
function assertHttpConfig(
|
|
94
|
+
config?: HttpOptions | HttpsOptions,
|
|
95
|
+
): asserts config is HttpOptions {
|
|
96
|
+
assert(config?.protocol == null || config?.protocol === 'http');
|
|
97
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/testlab
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A collection of test utilities we use to write LoopBack tests.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Test utilities to help write LoopBack 4 tests:
|
|
11
|
+
*
|
|
12
|
+
* - `expect` - behavior-driven development (BDD) style assertions
|
|
13
|
+
* - `sinon`
|
|
14
|
+
* - test spies: functions recording arguments and other information for all
|
|
15
|
+
* of their calls
|
|
16
|
+
* - stubs: functions (spies) with pre-programmed behavior
|
|
17
|
+
* - mocks: fake methods (like spies) with pre-programmed behavior
|
|
18
|
+
* (like stubs) as well as pre-programmed expectations
|
|
19
|
+
* - Helpers for creating `supertest` clients for LoopBack applications
|
|
20
|
+
* - HTTP request/response stubs for writing tests without a listening HTTP
|
|
21
|
+
* server
|
|
22
|
+
* - Swagger/OpenAPI spec validation
|
|
23
|
+
*
|
|
24
|
+
* @packageDocumentation
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export * from './client';
|
|
28
|
+
export * from './expect';
|
|
29
|
+
export * from './http-error-logger';
|
|
30
|
+
export * from './http-server-config';
|
|
31
|
+
export * from './request';
|
|
32
|
+
export * from './shot';
|
|
33
|
+
export * from './sinon';
|
|
34
|
+
export * from './skip';
|
|
35
|
+
export * from './test-sandbox';
|
|
36
|
+
export * from './to-json';
|
|
37
|
+
export * from './validate-api-spec';
|