@loopback/testlab 4.0.0-alpha.9 → 4.0.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,76 @@
|
|
|
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.givenHttpServerConfig = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const assert_1 = (0, tslib_1.__importDefault)(require("assert"));
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
12
|
+
const FIXTURES = path_1.default.resolve(__dirname, '../fixtures');
|
|
13
|
+
const DUMMY_TLS_CONFIG = {
|
|
14
|
+
key: (0, fs_1.readFileSync)(path_1.default.join(FIXTURES, 'key.pem')),
|
|
15
|
+
cert: (0, fs_1.readFileSync)(path_1.default.join(FIXTURES, 'cert.pem')),
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Assertion type guard for TypeScript to ensure `host` and `port` are set
|
|
19
|
+
* @param config - Host/port configuration
|
|
20
|
+
*/
|
|
21
|
+
function assertHostPort(config) {
|
|
22
|
+
(0, assert_1.default)(config.host != null, 'host is not set');
|
|
23
|
+
(0, assert_1.default)(config.port != null, 'port is not set');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create an HTTP-server configuration that works well in test environments.
|
|
27
|
+
* - Ask the operating system to assign a free (ephemeral) port.
|
|
28
|
+
* - Use IPv4 localhost `127.0.0.1` to avoid known IPv6 issues in Docker-based
|
|
29
|
+
* environments like Travis-CI.
|
|
30
|
+
* - Provide default TLS key & cert when `protocol` is set to `https`.
|
|
31
|
+
*
|
|
32
|
+
* @param customConfig - Additional configuration options to apply.
|
|
33
|
+
*/
|
|
34
|
+
function givenHttpServerConfig(customConfig) {
|
|
35
|
+
const defaults = { host: '127.0.0.1', port: 0 };
|
|
36
|
+
if (isHttpsConfig(customConfig)) {
|
|
37
|
+
const config = { ...customConfig };
|
|
38
|
+
if (config.host == null)
|
|
39
|
+
config.host = defaults.host;
|
|
40
|
+
if (config.port == null)
|
|
41
|
+
config.port = defaults.port;
|
|
42
|
+
setupTlsConfig(config);
|
|
43
|
+
assertHostPort(config);
|
|
44
|
+
return config;
|
|
45
|
+
}
|
|
46
|
+
assertHttpConfig(customConfig);
|
|
47
|
+
const config = { ...customConfig };
|
|
48
|
+
if (config.host == null)
|
|
49
|
+
config.host = defaults.host;
|
|
50
|
+
if (config.port == null)
|
|
51
|
+
config.port = defaults.port;
|
|
52
|
+
assertHostPort(config);
|
|
53
|
+
return config;
|
|
54
|
+
}
|
|
55
|
+
exports.givenHttpServerConfig = givenHttpServerConfig;
|
|
56
|
+
function setupTlsConfig(config) {
|
|
57
|
+
if ('key' in config && 'cert' in config)
|
|
58
|
+
return;
|
|
59
|
+
if ('pfx' in config)
|
|
60
|
+
return;
|
|
61
|
+
Object.assign(config, DUMMY_TLS_CONFIG);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Type guard to check if the parameter is `HttpsOptions`
|
|
65
|
+
*/
|
|
66
|
+
function isHttpsConfig(config) {
|
|
67
|
+
return (config === null || config === void 0 ? void 0 : config.protocol) === 'https';
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Type guard to assert the parameter is `HttpOptions`
|
|
71
|
+
* @param config - Http config
|
|
72
|
+
*/
|
|
73
|
+
function assertHttpConfig(config) {
|
|
74
|
+
(0, assert_1.default)((config === null || config === void 0 ? void 0 : config.protocol) == null || (config === null || config === void 0 ? void 0 : config.protocol) === 'http');
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=http-server-config.js.map
|
|
@@ -0,0 +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,iEAA4B;AAC5B,2BAAgC;AAGhC,6DAAwB;AAExB,MAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;AACxD,MAAM,gBAAgB,GAAG;IACvB,GAAG,EAAE,IAAA,iBAAY,EAAC,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACjD,IAAI,EAAE,IAAA,iBAAY,EAAC,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;CACpD,CAAC;AAkBF;;;GAGG;AACH,SAAS,cAAc,CAAC,MAAyB;IAC/C,IAAA,gBAAM,EAAC,MAAM,CAAC,IAAI,IAAI,IAAI,EAAE,iBAAiB,CAAC,CAA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AACH,SAAS,aAAa,CACpB,MAAmC;IAEnC,OAAO,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,MAAK,OAAO,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CACvB,MAAmC;IAEnC,IAAA,gBAAM,EAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,KAAI,IAAI,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,MAAK,MAAM,CAAC,CAAC;AAClE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A collection of test utilities we use to write LoopBack tests.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Test utilities to help write LoopBack 4 tests:
|
|
6
|
+
*
|
|
7
|
+
* - `expect` - behavior-driven development (BDD) style assertions
|
|
8
|
+
* - `sinon`
|
|
9
|
+
* - test spies: functions recording arguments and other information for all
|
|
10
|
+
* of their calls
|
|
11
|
+
* - stubs: functions (spies) with pre-programmed behavior
|
|
12
|
+
* - mocks: fake methods (like spies) with pre-programmed behavior
|
|
13
|
+
* (like stubs) as well as pre-programmed expectations
|
|
14
|
+
* - Helpers for creating `supertest` clients for LoopBack applications
|
|
15
|
+
* - HTTP request/response stubs for writing tests without a listening HTTP
|
|
16
|
+
* server
|
|
17
|
+
* - Swagger/OpenAPI spec validation
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
*/
|
|
21
|
+
export * from './client';
|
|
22
|
+
export * from './expect';
|
|
23
|
+
export * from './http-error-logger';
|
|
24
|
+
export * from './http-server-config';
|
|
25
|
+
export * from './request';
|
|
26
|
+
export * from './shot';
|
|
27
|
+
export * from './sinon';
|
|
28
|
+
export * from './skip';
|
|
29
|
+
export * from './test-sandbox';
|
|
30
|
+
export * from './to-json';
|
|
31
|
+
export * from './validate-api-spec';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
const tslib_1 = require("tslib");
|
|
8
|
+
/**
|
|
9
|
+
* A collection of test utilities we use to write LoopBack tests.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Test utilities to help write LoopBack 4 tests:
|
|
13
|
+
*
|
|
14
|
+
* - `expect` - behavior-driven development (BDD) style assertions
|
|
15
|
+
* - `sinon`
|
|
16
|
+
* - test spies: functions recording arguments and other information for all
|
|
17
|
+
* of their calls
|
|
18
|
+
* - stubs: functions (spies) with pre-programmed behavior
|
|
19
|
+
* - mocks: fake methods (like spies) with pre-programmed behavior
|
|
20
|
+
* (like stubs) as well as pre-programmed expectations
|
|
21
|
+
* - Helpers for creating `supertest` clients for LoopBack applications
|
|
22
|
+
* - HTTP request/response stubs for writing tests without a listening HTTP
|
|
23
|
+
* server
|
|
24
|
+
* - Swagger/OpenAPI spec validation
|
|
25
|
+
*
|
|
26
|
+
* @packageDocumentation
|
|
27
|
+
*/
|
|
28
|
+
(0, tslib_1.__exportStar)(require("./client"), exports);
|
|
29
|
+
(0, tslib_1.__exportStar)(require("./expect"), exports);
|
|
30
|
+
(0, tslib_1.__exportStar)(require("./http-error-logger"), exports);
|
|
31
|
+
(0, tslib_1.__exportStar)(require("./http-server-config"), exports);
|
|
32
|
+
(0, tslib_1.__exportStar)(require("./request"), exports);
|
|
33
|
+
(0, tslib_1.__exportStar)(require("./shot"), exports);
|
|
34
|
+
(0, tslib_1.__exportStar)(require("./sinon"), exports);
|
|
35
|
+
(0, tslib_1.__exportStar)(require("./skip"), exports);
|
|
36
|
+
(0, tslib_1.__exportStar)(require("./test-sandbox"), exports);
|
|
37
|
+
(0, tslib_1.__exportStar)(require("./to-json"), exports);
|
|
38
|
+
(0, tslib_1.__exportStar)(require("./validate-api-spec"), exports);
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;AAEhE;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,wDAAyB;AACzB,wDAAyB;AACzB,mEAAoC;AACpC,oEAAqC;AACrC,yDAA0B;AAC1B,sDAAuB;AACvB,uDAAwB;AACxB,sDAAuB;AACvB,8DAA+B;AAC/B,yDAA0B;AAC1B,mEAAoC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import http, { IncomingMessage } from 'http';
|
|
3
|
+
import https from 'https';
|
|
4
|
+
/**
|
|
5
|
+
* Async wrapper for making HTTP GET requests
|
|
6
|
+
* @param urlString
|
|
7
|
+
*/
|
|
8
|
+
export declare function httpGetAsync(urlString: string, agent?: http.Agent): Promise<IncomingMessage>;
|
|
9
|
+
/**
|
|
10
|
+
* Async wrapper for making HTTPS GET requests
|
|
11
|
+
* @param urlString
|
|
12
|
+
*/
|
|
13
|
+
export declare function httpsGetAsync(urlString: string, agent?: https.Agent): Promise<IncomingMessage>;
|
package/dist/request.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
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.httpsGetAsync = exports.httpGetAsync = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const http_1 = (0, tslib_1.__importDefault)(require("http"));
|
|
10
|
+
const https_1 = (0, tslib_1.__importDefault)(require("https"));
|
|
11
|
+
const url_1 = (0, tslib_1.__importDefault)(require("url"));
|
|
12
|
+
/**
|
|
13
|
+
* Async wrapper for making HTTP GET requests
|
|
14
|
+
* @param urlString
|
|
15
|
+
*/
|
|
16
|
+
function httpGetAsync(urlString, agent) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const urlOptions = url_1.default.parse(urlString);
|
|
19
|
+
const options = { agent, ...urlOptions };
|
|
20
|
+
http_1.default.get(options, resolve).on('error', reject);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.httpGetAsync = httpGetAsync;
|
|
24
|
+
/**
|
|
25
|
+
* Async wrapper for making HTTPS GET requests
|
|
26
|
+
* @param urlString
|
|
27
|
+
*/
|
|
28
|
+
function httpsGetAsync(urlString, agent) {
|
|
29
|
+
agent =
|
|
30
|
+
agent !== null && agent !== void 0 ? agent : new https_1.default.Agent({
|
|
31
|
+
rejectUnauthorized: false,
|
|
32
|
+
});
|
|
33
|
+
const urlOptions = url_1.default.parse(urlString);
|
|
34
|
+
const options = { agent, ...urlOptions };
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
https_1.default.get(options, resolve).on('error', reject);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.httpsGetAsync = httpsGetAsync;
|
|
40
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,6DAA2C;AAC3C,+DAA0B;AAC1B,2DAAsB;AAEtB;;;GAGG;AACH,SAAgB,YAAY,CAC1B,SAAiB,EACjB,KAAkB;IAElB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,UAAU,GAAG,aAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACxC,MAAM,OAAO,GAAG,EAAC,KAAK,EAAE,GAAG,UAAU,EAAC,CAAC;QACvC,cAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC;AATD,oCASC;AAED;;;GAGG;AACH,SAAgB,aAAa,CAC3B,SAAiB,EACjB,KAAmB;IAEnB,KAAK;QACH,KAAK,aAAL,KAAK,cAAL,KAAK,GACL,IAAI,eAAK,CAAC,KAAK,CAAC;YACd,kBAAkB,EAAE,KAAK;SAC1B,CAAC,CAAC;IAEL,MAAM,UAAU,GAAG,aAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACxC,MAAM,OAAO,GAAG,EAAC,KAAK,EAAE,GAAG,UAAU,EAAC,CAAC;IAEvC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,eAAK,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC;AAhBD,sCAgBC"}
|
package/dist/shot.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
4
|
+
import { Listener as ShotListener, RequestOptions as ShotRequestOptions, ResponseObject } from 'shot';
|
|
5
|
+
declare const inject: (dispatchFunc: ShotListener, options: ShotRequestOptions) => Promise<ResponseObject>;
|
|
6
|
+
export { inject, ShotRequestOptions };
|
|
7
|
+
export declare function stubServerRequest(options: ShotRequestOptions): IncomingMessage;
|
|
8
|
+
export declare type ShotCallback = (response: ResponseObject) => void;
|
|
9
|
+
export declare type ShotResponseCtor = new (request: IncomingMessage, onEnd: ShotCallback) => ServerResponse;
|
|
10
|
+
export declare function stubServerResponse(request: IncomingMessage, onEnd: ShotCallback): ServerResponse;
|
|
11
|
+
export declare type ObservedResponse = ResponseObject;
|
|
12
|
+
export interface HandlerContextStub {
|
|
13
|
+
request: IncomingMessage;
|
|
14
|
+
response: ServerResponse;
|
|
15
|
+
result: Promise<ObservedResponse>;
|
|
16
|
+
}
|
|
17
|
+
export declare function stubHandlerContext(requestOptions?: ShotRequestOptions): HandlerContextStub;
|
|
18
|
+
export interface ExpressContextStub extends HandlerContextStub {
|
|
19
|
+
app: express.Application;
|
|
20
|
+
request: express.Request;
|
|
21
|
+
response: express.Response;
|
|
22
|
+
result: Promise<ObservedResponse>;
|
|
23
|
+
}
|
|
24
|
+
export declare function stubExpressContext(requestOptions?: ShotRequestOptions): ExpressContextStub;
|
package/dist/shot.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
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.stubExpressContext = exports.stubHandlerContext = exports.stubServerResponse = exports.stubServerRequest = exports.inject = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
/*
|
|
10
|
+
* HTTP Request/Response mocks
|
|
11
|
+
* https://github.com/hapijs/shot
|
|
12
|
+
*/
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
14
|
+
const express_1 = (0, tslib_1.__importDefault)(require("express"));
|
|
15
|
+
const util_1 = (0, tslib_1.__importDefault)(require("util"));
|
|
16
|
+
const inject = require('@hapi/shot');
|
|
17
|
+
exports.inject = inject;
|
|
18
|
+
const ShotRequest = require('@hapi/shot/lib/request');
|
|
19
|
+
function stubServerRequest(options) {
|
|
20
|
+
const stub = new ShotRequest(options);
|
|
21
|
+
// Hacky workaround for Express, see
|
|
22
|
+
// https://github.com/expressjs/express/blob/4.16.3/lib/middleware/init.js
|
|
23
|
+
// https://github.com/hapijs/shot/issues/82#issuecomment-247943773
|
|
24
|
+
// https://github.com/jfhbrook/pickleback
|
|
25
|
+
Object.assign(stub, ShotRequest.prototype);
|
|
26
|
+
return stub;
|
|
27
|
+
}
|
|
28
|
+
exports.stubServerRequest = stubServerRequest;
|
|
29
|
+
const ShotResponse = require('@hapi/shot/lib/response');
|
|
30
|
+
function stubServerResponse(request, onEnd) {
|
|
31
|
+
const stub = new ShotResponse(request, onEnd);
|
|
32
|
+
// Hacky workaround for Express, see
|
|
33
|
+
// https://github.com/expressjs/express/blob/4.16.3/lib/middleware/init.js
|
|
34
|
+
// https://github.com/hapijs/shot/issues/82#issuecomment-247943773
|
|
35
|
+
// https://github.com/jfhbrook/pickleback
|
|
36
|
+
Object.assign(stub, ShotResponse.prototype);
|
|
37
|
+
return stub;
|
|
38
|
+
}
|
|
39
|
+
exports.stubServerResponse = stubServerResponse;
|
|
40
|
+
function stubHandlerContext(requestOptions = { url: '/' }) {
|
|
41
|
+
const request = stubServerRequest(requestOptions);
|
|
42
|
+
let response;
|
|
43
|
+
const result = new Promise(resolve => {
|
|
44
|
+
response = new ShotResponse(request, resolve);
|
|
45
|
+
});
|
|
46
|
+
const context = { request, response: response, result };
|
|
47
|
+
defineCustomContextInspect(context, requestOptions);
|
|
48
|
+
return context;
|
|
49
|
+
}
|
|
50
|
+
exports.stubHandlerContext = stubHandlerContext;
|
|
51
|
+
function stubExpressContext(requestOptions = { url: '/' }) {
|
|
52
|
+
const app = (0, express_1.default)();
|
|
53
|
+
const request = new ShotRequest(requestOptions);
|
|
54
|
+
// mix in Express Request API
|
|
55
|
+
const RequestApi = express_1.default.request;
|
|
56
|
+
for (const key of Object.getOwnPropertyNames(RequestApi)) {
|
|
57
|
+
Object.defineProperty(request, key, Object.getOwnPropertyDescriptor(RequestApi, key));
|
|
58
|
+
}
|
|
59
|
+
request.app = app;
|
|
60
|
+
request.originalUrl = request.url;
|
|
61
|
+
parseQuery(request);
|
|
62
|
+
let response;
|
|
63
|
+
const result = new Promise(resolve => {
|
|
64
|
+
response = new ShotResponse(request, resolve);
|
|
65
|
+
// mix in Express Response API
|
|
66
|
+
Object.assign(response, express_1.default.response);
|
|
67
|
+
const ResponseApi = express_1.default.response;
|
|
68
|
+
for (const key of Object.getOwnPropertyNames(ResponseApi)) {
|
|
69
|
+
Object.defineProperty(response, key, Object.getOwnPropertyDescriptor(ResponseApi, key));
|
|
70
|
+
}
|
|
71
|
+
response.app = app;
|
|
72
|
+
response.req = request;
|
|
73
|
+
request.res = response;
|
|
74
|
+
});
|
|
75
|
+
const context = { app, request, response: response, result };
|
|
76
|
+
defineCustomContextInspect(context, requestOptions);
|
|
77
|
+
return context;
|
|
78
|
+
}
|
|
79
|
+
exports.stubExpressContext = stubExpressContext;
|
|
80
|
+
/**
|
|
81
|
+
* Use `express.query` to parse the query string into `request.query` object
|
|
82
|
+
* @param request - Express http request object
|
|
83
|
+
*/
|
|
84
|
+
function parseQuery(request) {
|
|
85
|
+
// Use `express.query` to parse the query string
|
|
86
|
+
// See https://github.com/expressjs/express/blob/master/lib/express.js#L79
|
|
87
|
+
// See https://github.com/expressjs/express/blob/master/lib/middleware/query.js
|
|
88
|
+
express_1.default.query()(request, {}, () => { });
|
|
89
|
+
}
|
|
90
|
+
function defineCustomContextInspect(context, requestOptions) {
|
|
91
|
+
// Setup custom inspect functions to make test error messages easier to read
|
|
92
|
+
const inspectOpts = (depth, opts) => util_1.default.inspect(requestOptions, opts);
|
|
93
|
+
defineCustomInspect(context.request, (depth, opts) => `[RequestStub with options ${inspectOpts(depth, opts)}]`);
|
|
94
|
+
defineCustomInspect(context.response, (depth, opts) => `[ResponseStub for request with options ${inspectOpts(depth, opts)}]`);
|
|
95
|
+
context.result = context.result.then(r => {
|
|
96
|
+
defineCustomInspect(r, (depth, opts) => `[ObservedResponse for request with options ${inspectOpts(depth, opts)}]`);
|
|
97
|
+
return r;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// @types/node@v10.17.29 seems to miss the type definition of `util.inspect.custom`
|
|
101
|
+
// error TS2339: Property 'custom' does not exist on type 'typeof inspect'.
|
|
102
|
+
// Use a workaround for now to access the `custom` symbol for now.
|
|
103
|
+
// https://nodejs.org/api/util.html#util_util_inspect_custom
|
|
104
|
+
const custom = Symbol.for('nodejs.util.inspect.custom');
|
|
105
|
+
function defineCustomInspect(obj, inspectFn) {
|
|
106
|
+
obj[custom] = inspectFn;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=shot.js.map
|
package/dist/shot.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shot.js","sourceRoot":"","sources":["../src/shot.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE;;;GAGG;AAEH,uDAAuD;AAEvD,mEAA8B;AAO9B,6DAAwB;AAExB,MAAM,MAAM,GAGmB,OAAO,CAAC,YAAY,CAAC,CAAC;AAG7C,wBAAM;AAEd,MAAM,WAAW,GAAoB,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAGvE,SAAgB,iBAAiB,CAC/B,OAA2B;IAE3B,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;IACtC,oCAAoC;IACpC,0EAA0E;IAC1E,kEAAkE;IAClE,yCAAyC;IACzC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC;AAVD,8CAUC;AAED,MAAM,YAAY,GAAqB,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAQ1E,SAAgB,kBAAkB,CAChC,OAAwB,EACxB,KAAmB;IAEnB,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,EAAE,EAAE,CAC/C,cAAI,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAErC,mBAAmB,CACjB,OAAO,CAAC,OAAO,EACf,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,6BAA6B,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAC1E,CAAC;IAEF,mBAAmB,CACjB,OAAO,CAAC,QAAQ,EAChB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CACd,0CAA0C,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CACxE,CAAC;IAEF,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;QACvC,mBAAmB,CACjB,CAAC,EACD,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CACd,8CAA8C,WAAW,CACvD,KAAK,EACL,IAAI,CACL,GAAG,CACP,CAAC;QACF,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC;AAED,mFAAmF;AACnF,2EAA2E;AAC3E,kEAAkE;AAClE,4DAA4D;AAC5D,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAExD,SAAS,mBAAmB,CAC1B,GAAQ,EACR,SAA2C;IAE3C,GAAG,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;AAC1B,CAAC"}
|
package/dist/sinon.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import sinon, { SinonSpy } from 'sinon';
|
|
2
|
+
export { sinon, SinonSpy };
|
|
3
|
+
export declare type StubbedInstanceWithSinonAccessor<T> = T & {
|
|
4
|
+
stubs: sinon.SinonStubbedInstance<T>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new object with the given functions as the prototype and stubs all
|
|
8
|
+
* implemented functions.
|
|
9
|
+
*
|
|
10
|
+
* Note: The given constructor function is not invoked. See also the stub API.
|
|
11
|
+
*
|
|
12
|
+
* This is a helper method replacing `sinon.createStubInstance` and working
|
|
13
|
+
* around the limitations of TypeScript and Sinon, where Sinon is not able to
|
|
14
|
+
* list private/protected members in the type definition of the stub instance
|
|
15
|
+
* and therefore the stub instance cannot be assigned to places expecting TType.
|
|
16
|
+
* See also
|
|
17
|
+
* - https://github.com/Microsoft/TypeScript/issues/13543
|
|
18
|
+
* - https://github.com/DefinitelyTyped/DefinitelyTyped/issues/14811
|
|
19
|
+
*
|
|
20
|
+
* @typeParam TType - Type being stubbed.
|
|
21
|
+
* @param constructor - Object or class to stub.
|
|
22
|
+
* @returns A stubbed version of the constructor, with an extra property `stubs`
|
|
23
|
+
* providing access to stub API for individual methods.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createStubInstance<TType>(constructor: sinon.StubbableType<TType>): StubbedInstanceWithSinonAccessor<TType>;
|
package/dist/sinon.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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.createStubInstance = exports.sinon = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const sinon_1 = (0, tslib_1.__importDefault)(require("sinon"));
|
|
10
|
+
exports.sinon = sinon_1.default;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new object with the given functions as the prototype and stubs all
|
|
13
|
+
* implemented functions.
|
|
14
|
+
*
|
|
15
|
+
* Note: The given constructor function is not invoked. See also the stub API.
|
|
16
|
+
*
|
|
17
|
+
* This is a helper method replacing `sinon.createStubInstance` and working
|
|
18
|
+
* around the limitations of TypeScript and Sinon, where Sinon is not able to
|
|
19
|
+
* list private/protected members in the type definition of the stub instance
|
|
20
|
+
* and therefore the stub instance cannot be assigned to places expecting TType.
|
|
21
|
+
* See also
|
|
22
|
+
* - https://github.com/Microsoft/TypeScript/issues/13543
|
|
23
|
+
* - https://github.com/DefinitelyTyped/DefinitelyTyped/issues/14811
|
|
24
|
+
*
|
|
25
|
+
* @typeParam TType - Type being stubbed.
|
|
26
|
+
* @param constructor - Object or class to stub.
|
|
27
|
+
* @returns A stubbed version of the constructor, with an extra property `stubs`
|
|
28
|
+
* providing access to stub API for individual methods.
|
|
29
|
+
*/
|
|
30
|
+
function createStubInstance(constructor) {
|
|
31
|
+
const stub = sinon_1.default.createStubInstance(constructor);
|
|
32
|
+
return Object.assign(stub, { stubs: stub });
|
|
33
|
+
}
|
|
34
|
+
exports.createStubInstance = createStubInstance;
|
|
35
|
+
//# sourceMappingURL=sinon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sinon.js","sourceRoot":"","sources":["../src/sinon.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+DAAsC;AAE9B,gBAFD,eAAK,CAEC;AAMb;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,kBAAkB,CAChC,WAAuC;IAEvC,MAAM,IAAI,GAAG,eAAK,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,MAAM,CAAC,IAAa,EAAE,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAC;AACrD,CAAC;AALD,gDAKC"}
|
package/dist/skip.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function defining a new test case or a test suite, e.g. `it` or `describe`.
|
|
3
|
+
*/
|
|
4
|
+
export declare type TestDefinition<ARGS extends unknown[], RETVAL> = (name: string, ...args: ARGS) => RETVAL;
|
|
5
|
+
/**
|
|
6
|
+
* Helper function for skipping tests when a certain condition is met.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* skipIf(
|
|
11
|
+
* !features.freeFormProperties,
|
|
12
|
+
* describe,
|
|
13
|
+
* 'free-form properties (strict: false)',
|
|
14
|
+
* () => {
|
|
15
|
+
* // the tests
|
|
16
|
+
* }
|
|
17
|
+
* );
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @param skip - Should the test case/suite be skipped?
|
|
21
|
+
* @param verb - The function to invoke to define the test case or the test
|
|
22
|
+
* suite, e.g. `it` or `describe`.
|
|
23
|
+
* @param name - The test name (the first argument of `verb` function).
|
|
24
|
+
* @param args - Additional arguments (framework specific), typically a function
|
|
25
|
+
* implementing the test.
|
|
26
|
+
*/
|
|
27
|
+
export declare function skipIf<ARGS extends unknown[], RETVAL>(skip: boolean, verb: TestDefinition<ARGS, RETVAL> & {
|
|
28
|
+
skip: TestDefinition<ARGS, RETVAL>;
|
|
29
|
+
}, name: string, ...args: ARGS): RETVAL;
|
|
30
|
+
/**
|
|
31
|
+
* Helper function for skipping tests on Travis CI.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* skipOnTravis(it, 'does something when some condition', async () => {
|
|
37
|
+
* // the test
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @param verb - The function to invoke to define the test case or the test
|
|
42
|
+
* suite, e.g. `it` or `describe`.
|
|
43
|
+
* @param name - The test name (the first argument of `verb` function).
|
|
44
|
+
* @param args - Additional arguments (framework specific), typically a function
|
|
45
|
+
* implementing the test.
|
|
46
|
+
*/
|
|
47
|
+
export declare function skipOnTravis<ARGS extends unknown[], RETVAL>(verb: TestDefinition<ARGS, RETVAL> & {
|
|
48
|
+
skip: TestDefinition<ARGS, RETVAL>;
|
|
49
|
+
}, name: string, ...args: ARGS): RETVAL;
|
package/dist/skip.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2019,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.skipOnTravis = exports.skipIf = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Helper function for skipping tests when a certain condition is met.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* skipIf(
|
|
14
|
+
* !features.freeFormProperties,
|
|
15
|
+
* describe,
|
|
16
|
+
* 'free-form properties (strict: false)',
|
|
17
|
+
* () => {
|
|
18
|
+
* // the tests
|
|
19
|
+
* }
|
|
20
|
+
* );
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @param skip - Should the test case/suite be skipped?
|
|
24
|
+
* @param verb - The function to invoke to define the test case or the test
|
|
25
|
+
* suite, e.g. `it` or `describe`.
|
|
26
|
+
* @param name - The test name (the first argument of `verb` function).
|
|
27
|
+
* @param args - Additional arguments (framework specific), typically a function
|
|
28
|
+
* implementing the test.
|
|
29
|
+
*/
|
|
30
|
+
function skipIf(skip, verb, name, ...args) {
|
|
31
|
+
if (skip) {
|
|
32
|
+
return verb.skip(`[SKIPPED] ${name}`, ...args);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return verb(name, ...args);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.skipIf = skipIf;
|
|
39
|
+
/**
|
|
40
|
+
* Helper function for skipping tests on Travis CI.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* skipOnTravis(it, 'does something when some condition', async () => {
|
|
46
|
+
* // the test
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @param verb - The function to invoke to define the test case or the test
|
|
51
|
+
* suite, e.g. `it` or `describe`.
|
|
52
|
+
* @param name - The test name (the first argument of `verb` function).
|
|
53
|
+
* @param args - Additional arguments (framework specific), typically a function
|
|
54
|
+
* implementing the test.
|
|
55
|
+
*/
|
|
56
|
+
function skipOnTravis(verb, name, ...args) {
|
|
57
|
+
if (process.env.TRAVIS) {
|
|
58
|
+
return verb.skip(`[SKIPPED ON TRAVIS] ${name}`, ...args);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return verb(name, ...args);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.skipOnTravis = skipOnTravis;
|
|
65
|
+
//# sourceMappingURL=skip.js.map
|
package/dist/skip.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip.js","sourceRoot":"","sources":["../src/skip.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;AAUhE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,MAAM,CACpB,IAAa,EACb,IAAyE,EACzE,IAAY,EACZ,GAAG,IAAU;IAEb,IAAI,IAAI,EAAE;QACR,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;KAChD;SAAM;QACL,OAAO,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;KAC5B;AACH,CAAC;AAXD,wBAWC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,YAAY,CAC1B,IAAyE,EACzE,IAAY,EACZ,GAAG,IAAU;IAEb,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE;QACtB,OAAO,IAAI,CAAC,IAAI,CAAC,uBAAuB,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;KAC1D;SAAM;QACL,OAAO,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;KAC5B;AACH,CAAC;AAVD,oCAUC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for a test sandbox
|
|
3
|
+
*/
|
|
4
|
+
export interface TestSandboxOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The `subdir` controls if/how the sandbox creates a subdirectory under the
|
|
7
|
+
* root path. It has one of the following values:
|
|
8
|
+
*
|
|
9
|
+
* - `true`: Creates a unique subdirectory. This will be the default behavior.
|
|
10
|
+
* - `false`: Uses the root path as the target directory without creating a
|
|
11
|
+
* subdirectory.
|
|
12
|
+
* - a string such as `sub-dir-1`: creates a subdirectory with the given value.
|
|
13
|
+
*/
|
|
14
|
+
subdir: boolean | string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* TestSandbox class provides a convenient way to get a reference to a
|
|
18
|
+
* sandbox folder in which you can perform operations for testing purposes.
|
|
19
|
+
*/
|
|
20
|
+
export declare class TestSandbox {
|
|
21
|
+
private _path?;
|
|
22
|
+
get path(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Will create a directory if it doesn't already exist. If it exists, you
|
|
25
|
+
* still get an instance of the TestSandbox.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // Create a sandbox as a unique temporary subdirectory under the rootPath
|
|
30
|
+
* const sandbox = new TestSandbox(rootPath);
|
|
31
|
+
* const sandbox = new TestSandbox(rootPath, {subdir: true});
|
|
32
|
+
*
|
|
33
|
+
* // Create a sandbox in the root path directly
|
|
34
|
+
* // This is same as the old behavior
|
|
35
|
+
* const sandbox = new TestSandbox(rootPath, {subdir: false});
|
|
36
|
+
*
|
|
37
|
+
* // Create a sandbox in the `test1` subdirectory of the root path
|
|
38
|
+
* const sandbox = new TestSandbox(rootPath, {subdir: 'test1'});
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @param rootPath - Root path of the TestSandbox. If relative it will be
|
|
42
|
+
* resolved against the current directory.
|
|
43
|
+
* @param options - Options to control if/how the sandbox creates a
|
|
44
|
+
* subdirectory for the sandbox. If not provided, the sandbox
|
|
45
|
+
* will automatically creates a unique temporary subdirectory. This allows
|
|
46
|
+
* sandboxes with the same root path can be used in parallel during testing.
|
|
47
|
+
*/
|
|
48
|
+
constructor(rootPath: string, options?: TestSandboxOptions);
|
|
49
|
+
/**
|
|
50
|
+
* Resets the TestSandbox. (Remove all files in it).
|
|
51
|
+
*/
|
|
52
|
+
reset(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Deletes the TestSandbox.
|
|
55
|
+
*/
|
|
56
|
+
delete(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Makes a directory in the TestSandbox
|
|
59
|
+
*
|
|
60
|
+
* @param dir - Name of directory to create (relative to TestSandbox path)
|
|
61
|
+
*/
|
|
62
|
+
mkdir(dir: string): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Copies a file from src to the TestSandbox. If copying a `.js` file which
|
|
65
|
+
* has an accompanying `.js.map` file in the src file location, the dest file
|
|
66
|
+
* will have its sourceMappingURL updated to point to the original file as
|
|
67
|
+
* an absolute path so you don't need to copy the map file.
|
|
68
|
+
*
|
|
69
|
+
* @param src - Absolute path of file to be copied to the TestSandbox
|
|
70
|
+
* @param dest - Optional. Destination filename of the copy operation
|
|
71
|
+
* (relative to TestSandbox). Original filename used if not specified.
|
|
72
|
+
* @param transform - Optional. A function to transform the file content.
|
|
73
|
+
*/
|
|
74
|
+
copyFile(src: string, dest?: string, transform?: (content: string) => string): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new file and writes the given data serialized as JSON.
|
|
77
|
+
*
|
|
78
|
+
* @param dest - Destination filename, optionally including a relative path.
|
|
79
|
+
* @param data - The data to write.
|
|
80
|
+
*/
|
|
81
|
+
writeJsonFile(dest: string, data: unknown): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Creates a new file and writes the given data as a UTF-8-encoded text.
|
|
84
|
+
*
|
|
85
|
+
* @param dest - Destination filename, optionally including a relative path.
|
|
86
|
+
* @param data - The text to write.
|
|
87
|
+
*/
|
|
88
|
+
writeTextFile(dest: string, data: string): Promise<void>;
|
|
89
|
+
}
|