@serenity-js/rest 3.25.4 → 3.26.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 +23 -0
- package/lib/io/axiosProxyOverridesFor.js +1 -1
- package/lib/io/axiosProxyOverridesFor.js.map +1 -1
- package/lib/io/createUrl.js +1 -1
- package/lib/io/createUrl.js.map +1 -1
- package/lib/screenplay/abilities/CallAnApi.d.ts +3 -1
- package/lib/screenplay/abilities/CallAnApi.d.ts.map +1 -1
- package/lib/screenplay/abilities/CallAnApi.js +66 -2
- package/lib/screenplay/abilities/CallAnApi.js.map +1 -1
- package/package.json +8 -8
- package/src/io/axiosProxyOverridesFor.ts +1 -1
- package/src/io/createUrl.ts +1 -1
- package/src/screenplay/abilities/CallAnApi.ts +95 -8
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,29 @@
|
|
|
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
|
+
# [3.26.0](https://github.com/serenity-js/serenity-js/compare/v3.25.5...v3.26.0) (2024-08-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **core:** new event ActorEntersStage is emitted upon invoking actorCalled for the first time ([1498c21](https://github.com/serenity-js/serenity-js/commit/1498c2103e5ab4dc3958a4236a8e26ff2848e6c0))
|
|
12
|
+
* **rest:** final state of the actor's ability to CallAnApi is included in Serenity BDD report ([e000a16](https://github.com/serenity-js/serenity-js/commit/e000a1687780b0789728e0e0ef11864d1c14e532))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## [3.25.5](https://github.com/serenity-js/serenity-js/compare/v3.25.4...v3.25.5) (2024-08-18)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* **deps:** update dependency tiny-types to v1.23.0 ([1c9a897](https://github.com/serenity-js/serenity-js/commit/1c9a897c100398632366bdef84d9dfde03f1af3c))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
6
29
|
## [3.25.4](https://github.com/serenity-js/serenity-js/compare/v3.25.3...v3.25.4) (2024-08-07)
|
|
7
30
|
|
|
8
31
|
**Note:** Version bump only for package @serenity-js/rest
|
|
@@ -14,7 +14,7 @@ function axiosProxyOverridesFor(options) {
|
|
|
14
14
|
password: options.proxy?.auth?.password,
|
|
15
15
|
protocol: options.proxy?.protocol,
|
|
16
16
|
hostname: (0, tiny_types_1.ensure)('proxy.host', options.proxy?.host, (0, tiny_types_1.isDefined)()),
|
|
17
|
-
port: options.proxy?.port
|
|
17
|
+
port: options.proxy?.port ? Number(options.proxy?.port) : undefined,
|
|
18
18
|
}).toString();
|
|
19
19
|
const agent = new ProxyAgent_1.ProxyAgent({
|
|
20
20
|
httpAgent: options.httpAgent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axiosProxyOverridesFor.js","sourceRoot":"","sources":["../../src/io/axiosProxyOverridesFor.ts"],"names":[],"mappings":";;AAUA,wDA4BC;AArCD,2CAA+C;AAG/C,2CAAwC;AACxC,6CAA0C;AAE1C;;GAEG;AACH,SAAgB,sBAAsB,CAAa,OAAyC;IAGxF,MAAM,gBAAgB,GAAmB,OAAO,CAAC,KAAK;WAC/C,IAAA,qBAAS,EAAC;YACT,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ;YACvC,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ;YACvC,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,QAAQ;YACjC,QAAQ,EAAE,IAAA,mBAAM,EAAC,YAAY,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAA,sBAAS,GAAE,CAAC;YAChE,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI;
|
|
1
|
+
{"version":3,"file":"axiosProxyOverridesFor.js","sourceRoot":"","sources":["../../src/io/axiosProxyOverridesFor.ts"],"names":[],"mappings":";;AAUA,wDA4BC;AArCD,2CAA+C;AAG/C,2CAAwC;AACxC,6CAA0C;AAE1C;;GAEG;AACH,SAAgB,sBAAsB,CAAa,OAAyC;IAGxF,MAAM,gBAAgB,GAAmB,OAAO,CAAC,KAAK;WAC/C,IAAA,qBAAS,EAAC;YACT,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ;YACvC,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ;YACvC,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,QAAQ;YACjC,QAAQ,EAAE,IAAA,mBAAM,EAAC,YAAY,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAA,sBAAS,GAAE,CAAC;YAChE,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SACtE,CAAC,CAAC,QAAQ,EAAE,CAAC;IAElB,MAAM,KAAK,GAAG,IAAI,uBAAU,CAAC;QACzB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,UAAU,EAAE,OAAO,CAAC,UAAU;QAE9B,0DAA0D;QAC1D,6DAA6D;QAC7D,cAAc,EAAE,gBAAgB;YAC5B,CAAC,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,gBAAgB;YACpC,CAAC,CAAC,SAAS;KAClB,CAAC,CAAC;IAEH,OAAO;QACH,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,KAAK;QAChB,UAAU,EAAE,KAAK;KACpB,CAAC;AACN,CAAC"}
|
package/lib/io/createUrl.js
CHANGED
|
@@ -8,7 +8,7 @@ function createUrl(options) {
|
|
|
8
8
|
? ':' + options?.port
|
|
9
9
|
: (options?.protocol ? undefined : ':80');
|
|
10
10
|
return new URL([
|
|
11
|
-
options?.protocol
|
|
11
|
+
options?.protocol ? protocolFrom(options?.protocol) : 'http://',
|
|
12
12
|
(options?.username || options?.password) && credentialsFrom(options.username, options.password),
|
|
13
13
|
hostname,
|
|
14
14
|
port,
|
package/lib/io/createUrl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createUrl.js","sourceRoot":"","sources":["../../src/io/createUrl.ts"],"names":[],"mappings":";;AAUA,8BAYC;AAtBD,2CAAqE;AAUrE,SAAgB,SAAS,CAAC,OAAyB;IAC/C,MAAM,QAAQ,GAAI,IAAA,mBAAM,EAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAA,qBAAQ,GAAE,EAAE,IAAA,uBAAU,GAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACzF,MAAM,IAAI,GAAQ,OAAO,EAAE,IAAI;QAC3B,CAAC,CAAC,GAAG,GAAG,OAAO,EAAE,IAAI;QACrB,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAE9C,OAAO,IAAI,GAAG,CAAC;QACX,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"createUrl.js","sourceRoot":"","sources":["../../src/io/createUrl.ts"],"names":[],"mappings":";;AAUA,8BAYC;AAtBD,2CAAqE;AAUrE,SAAgB,SAAS,CAAC,OAAyB;IAC/C,MAAM,QAAQ,GAAI,IAAA,mBAAM,EAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAA,qBAAQ,GAAE,EAAE,IAAA,uBAAU,GAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACzF,MAAM,IAAI,GAAQ,OAAO,EAAE,IAAI;QAC3B,CAAC,CAAC,GAAG,GAAG,OAAO,EAAE,IAAI;QACrB,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAE9C,OAAO,IAAI,GAAG,CAAC;QACX,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;QAC/D,CAAC,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,QAAQ,CAAC,IAAI,eAAe,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC;QAC/F,QAAQ;QACR,IAAI;KACP,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,YAAY,CAAC,QAAiB;IACnC,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3D,IAAA,mBAAM,EAAC,UAAU,EAAE,YAAY,EAAE,IAAA,sBAAS,GAAE,CAAC,CAAC;IAE9C,OAAO,YAAY,GAAG,KAAK,CAAC;AAChC,CAAC;AAED,SAAS,eAAe,CAAC,QAAiB,EAAE,QAAiB;IACzD,OAAO;QACH,QAAQ,IAAI,kBAAkB,CAAC,QAAQ,CAAC;QACxC,QAAQ,IAAI,GAAG,GAAG,kBAAkB,CAAC,QAAQ,CAAC;QAC9C,GAAG;KACN,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Ability } from '@serenity-js/core';
|
|
1
|
+
import { Ability, type SerialisedAbility } from '@serenity-js/core';
|
|
2
2
|
import { type AxiosDefaults, type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios';
|
|
3
|
+
import { URL } from 'url';
|
|
3
4
|
import type { AxiosRequestConfigDefaults } from '../../io';
|
|
4
5
|
/**
|
|
5
6
|
* An [ability](https://serenity-js.org/api/core/class/Ability/) that wraps [axios client](https://axios-http.com/docs/api_intro) and enables
|
|
@@ -393,5 +394,6 @@ export declare class CallAnApi extends Ability {
|
|
|
393
394
|
* @param mappingFunction
|
|
394
395
|
*/
|
|
395
396
|
mapLastResponse<T>(mappingFunction: (response: AxiosResponse) => T): T;
|
|
397
|
+
toJSON(): SerialisedAbility;
|
|
396
398
|
}
|
|
397
399
|
//# sourceMappingURL=CallAnApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CallAnApi.d.ts","sourceRoot":"","sources":["../../../src/screenplay/abilities/CallAnApi.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"CallAnApi.d.ts","sourceRoot":"","sources":["../../../src/screenplay/abilities/CallAnApi.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EAGP,KAAK,iBAAiB,EAEzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACH,KAAK,aAAa,EAElB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EACrB,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,KAAK,EAAE,0BAA0B,EAAmC,MAAM,UAAU,CAAC;AAG5F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqTG;AACH,qBAAa,SAAU,SAAQ,OAAO;IA+CtB,OAAO,CAAC,QAAQ,CAAC,aAAa;IA7C1C,OAAO,CAAC,YAAY,CAAgB;IAEpC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS;IAQ3C;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,aAAa,GAAG,0BAA0B,GAAG,SAAS;IAI1F;;;;;;OAMG;gBAC0B,aAAa,EAAE,aAAa;IAIzD;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,GAAG,GAAG,IAAI;IAI7D;;;;;;;;;;;;OAYG;IACG,OAAO,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC;IA+BjE;;;;;;;;OAQG;IACH,UAAU,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM;IAQ9C;;;;;;;;OAQG;IACH,eAAe,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,CAAC,GAAG,CAAC;IAQtE,MAAM,IAAI,iBAAiB;CAkB9B"}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CallAnApi = void 0;
|
|
4
4
|
const core_1 = require("@serenity-js/core");
|
|
5
|
+
const agent_base_1 = require("agent-base");
|
|
6
|
+
const objects_1 = require("tiny-types/lib/objects");
|
|
7
|
+
const url_1 = require("url");
|
|
5
8
|
const io_1 = require("../../io");
|
|
6
9
|
/**
|
|
7
10
|
* An [ability](https://serenity-js.org/api/core/class/Ability/) that wraps [axios client](https://axios-http.com/docs/api_intro) and enables
|
|
@@ -325,7 +328,7 @@ class CallAnApi extends core_1.Ability {
|
|
|
325
328
|
*/
|
|
326
329
|
static at(baseURL) {
|
|
327
330
|
return CallAnApi.using({
|
|
328
|
-
baseURL: baseURL instanceof URL
|
|
331
|
+
baseURL: baseURL instanceof url_1.URL
|
|
329
332
|
? baseURL.toString()
|
|
330
333
|
: baseURL
|
|
331
334
|
});
|
|
@@ -426,7 +429,7 @@ class CallAnApi extends core_1.Ability {
|
|
|
426
429
|
resolveUrl(config) {
|
|
427
430
|
const baseURL = this.axiosInstance.defaults.baseURL || config.baseURL;
|
|
428
431
|
return baseURL
|
|
429
|
-
? new URL(config.url, baseURL).toString()
|
|
432
|
+
? new url_1.URL(config.url, baseURL).toString()
|
|
430
433
|
: config.url;
|
|
431
434
|
}
|
|
432
435
|
/**
|
|
@@ -444,6 +447,67 @@ class CallAnApi extends core_1.Ability {
|
|
|
444
447
|
}
|
|
445
448
|
return mappingFunction(this.lastResponse);
|
|
446
449
|
}
|
|
450
|
+
toJSON() {
|
|
451
|
+
const simplifiedConfig = {
|
|
452
|
+
baseURL: this.axiosInstance.defaults.baseURL,
|
|
453
|
+
headers: this.axiosInstance.defaults.headers,
|
|
454
|
+
timeout: this.axiosInstance.defaults.timeout,
|
|
455
|
+
proxy: proxyConfigFrom(this.axiosInstance.defaults),
|
|
456
|
+
};
|
|
457
|
+
return {
|
|
458
|
+
...super.toJSON(),
|
|
459
|
+
options: {
|
|
460
|
+
...recursivelyRemove([isUndefined, isEmptyObject], simplifiedConfig),
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
447
464
|
}
|
|
448
465
|
exports.CallAnApi = CallAnApi;
|
|
466
|
+
function proxyConfigFrom(defaults) {
|
|
467
|
+
if (defaults.proxy === undefined) {
|
|
468
|
+
return undefined;
|
|
469
|
+
}
|
|
470
|
+
if (!(defaults.proxy === false && defaults.httpAgent instanceof agent_base_1.Agent)) {
|
|
471
|
+
return undefined;
|
|
472
|
+
}
|
|
473
|
+
const proxyUrl = defaults.httpAgent.getProxyForUrl(defaults.baseURL);
|
|
474
|
+
if (!proxyUrl) {
|
|
475
|
+
return undefined;
|
|
476
|
+
}
|
|
477
|
+
const url = new url_1.URL(proxyUrl);
|
|
478
|
+
return {
|
|
479
|
+
protocol: url.protocol?.replace(/:$/, ''),
|
|
480
|
+
host: url.hostname,
|
|
481
|
+
port: url.port ? Number(url.port) : undefined,
|
|
482
|
+
auth: url.username
|
|
483
|
+
? {
|
|
484
|
+
username: url.username || undefined,
|
|
485
|
+
password: url.password || undefined,
|
|
486
|
+
}
|
|
487
|
+
: undefined,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function isUndefined(value) {
|
|
491
|
+
return value === undefined;
|
|
492
|
+
}
|
|
493
|
+
function isEmptyObject(value) {
|
|
494
|
+
return (0, objects_1.isObject)(value) && Object.keys(value).length === 0;
|
|
495
|
+
}
|
|
496
|
+
function recursivelyRemove(matchers, value) {
|
|
497
|
+
if (Array.isArray(value)) {
|
|
498
|
+
return value.map(item => recursivelyRemove(matchers, item));
|
|
499
|
+
}
|
|
500
|
+
if (typeof value === 'object' && value !== null) {
|
|
501
|
+
return Object.keys(value).reduce((acc, key) => {
|
|
502
|
+
if (matchers.some(matcher => matcher(value[key]))) {
|
|
503
|
+
return acc;
|
|
504
|
+
}
|
|
505
|
+
return {
|
|
506
|
+
...acc,
|
|
507
|
+
[key]: recursivelyRemove(matchers, value[key]),
|
|
508
|
+
};
|
|
509
|
+
}, {});
|
|
510
|
+
}
|
|
511
|
+
return value;
|
|
512
|
+
}
|
|
449
513
|
//# sourceMappingURL=CallAnApi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CallAnApi.js","sourceRoot":"","sources":["../../../src/screenplay/abilities/CallAnApi.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"CallAnApi.js","sourceRoot":"","sources":["../../../src/screenplay/abilities/CallAnApi.ts"],"names":[],"mappings":";;;AAAA,4CAM2B;AAC3B,2CAAmC;AASnC,oDAAkD;AAClD,6BAA0B;AAG1B,iCAAuC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;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C;YACf,CAAC;YAED,OAAO;gBACH,GAAG,GAAG;gBACN,CAAC,GAAG,CAAC,EAAE,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;aACjD,CAAC;QACN,CAAC,EAAE,EAAE,CAAC,CAAC;IACX,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenity-js/rest",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.26.0",
|
|
4
4
|
"description": "Serenity/JS Screenplay Pattern library for interacting with REST and other HTTP-based services, supporting comprehensive API testing and blended testing scenarios",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jan Molak",
|
|
@@ -46,26 +46,26 @@
|
|
|
46
46
|
"node": "^16.13 || ^18.12 || ^20"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@serenity-js/core": "3.
|
|
49
|
+
"@serenity-js/core": "3.26.0",
|
|
50
50
|
"agent-base": "7.1.1",
|
|
51
|
-
"axios": "1.7.
|
|
51
|
+
"axios": "1.7.5",
|
|
52
52
|
"http-proxy-agent": "7.0.2",
|
|
53
53
|
"https-proxy-agent": "7.0.5",
|
|
54
54
|
"lru-cache": "11.0.0",
|
|
55
55
|
"proxy-from-env": "1.1.0",
|
|
56
|
-
"tiny-types": "1.
|
|
56
|
+
"tiny-types": "1.23.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@integration/testing-tools": "3.0.0",
|
|
60
|
-
"@serenity-js/assertions": "3.
|
|
61
|
-
"@types/chai": "4.3.
|
|
60
|
+
"@serenity-js/assertions": "3.26.0",
|
|
61
|
+
"@types/chai": "4.3.18",
|
|
62
62
|
"@types/mocha": "10.0.7",
|
|
63
63
|
"axios-mock-adapter": "2.0.0",
|
|
64
64
|
"c8": "10.1.2",
|
|
65
|
-
"mocha": "10.7.
|
|
65
|
+
"mocha": "10.7.3",
|
|
66
66
|
"mocha-multi": "1.1.7",
|
|
67
67
|
"ts-node": "10.9.2",
|
|
68
68
|
"typescript": "5.5.4"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "bd5ea6b04d1fd1d9576a0fc28509f3f947365b35"
|
|
71
71
|
}
|
|
@@ -17,7 +17,7 @@ export function axiosProxyOverridesFor<Data = any>(options: AxiosRequestConfigDe
|
|
|
17
17
|
password: options.proxy?.auth?.password,
|
|
18
18
|
protocol: options.proxy?.protocol,
|
|
19
19
|
hostname: ensure('proxy.host', options.proxy?.host, isDefined()),
|
|
20
|
-
port: options.proxy?.port
|
|
20
|
+
port: options.proxy?.port ? Number(options.proxy?.port) : undefined,
|
|
21
21
|
}).toString();
|
|
22
22
|
|
|
23
23
|
const agent = new ProxyAgent({
|
package/src/io/createUrl.ts
CHANGED
|
@@ -15,7 +15,7 @@ export function createUrl(options: CreateUrlOptions): URL {
|
|
|
15
15
|
: (options?.protocol ? undefined : ':80');
|
|
16
16
|
|
|
17
17
|
return new URL([
|
|
18
|
-
options?.protocol
|
|
18
|
+
options?.protocol ? protocolFrom(options?.protocol) : 'http://',
|
|
19
19
|
(options?.username || options?.password) && credentialsFrom(options.username, options.password),
|
|
20
20
|
hostname,
|
|
21
21
|
port,
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Ability,
|
|
3
|
+
ConfigurationError,
|
|
4
|
+
LogicError,
|
|
5
|
+
type SerialisedAbility,
|
|
6
|
+
TestCompromisedError
|
|
7
|
+
} from '@serenity-js/core';
|
|
8
|
+
import { Agent } from 'agent-base';
|
|
2
9
|
import {
|
|
3
10
|
type AxiosDefaults,
|
|
4
11
|
type AxiosError,
|
|
@@ -6,8 +13,11 @@ import {
|
|
|
6
13
|
type AxiosRequestConfig,
|
|
7
14
|
type AxiosResponse,
|
|
8
15
|
} from 'axios';
|
|
16
|
+
import { type JSONObject } from 'tiny-types';
|
|
17
|
+
import { isObject } from 'tiny-types/lib/objects';
|
|
18
|
+
import { URL } from 'url';
|
|
9
19
|
|
|
10
|
-
import type { AxiosRequestConfigDefaults} from '../../io';
|
|
20
|
+
import type { AxiosRequestConfigDefaults, AxiosRequestConfigProxyDefaults } from '../../io';
|
|
11
21
|
import { createAxios } from '../../io';
|
|
12
22
|
|
|
13
23
|
/**
|
|
@@ -409,19 +419,18 @@ export class CallAnApi extends Ability {
|
|
|
409
419
|
});
|
|
410
420
|
|
|
411
421
|
return this.lastResponse;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
const description = `${ config.method.toUpperCase() } ${ url || config.url }`;
|
|
422
|
+
} catch (error) {
|
|
423
|
+
const description = `${config.method.toUpperCase()} ${url || config.url}`;
|
|
415
424
|
|
|
416
425
|
switch (true) {
|
|
417
426
|
case /timeout.*exceeded/.test(error.message):
|
|
418
|
-
throw new TestCompromisedError(`The request has timed out: ${
|
|
427
|
+
throw new TestCompromisedError(`The request has timed out: ${description}`, error);
|
|
419
428
|
case /Network Error/.test(error.message):
|
|
420
|
-
throw new TestCompromisedError(`A network error has occurred: ${
|
|
429
|
+
throw new TestCompromisedError(`A network error has occurred: ${description}`, error);
|
|
421
430
|
case error instanceof TypeError:
|
|
422
431
|
throw new ConfigurationError(`Looks like there was an issue with Axios configuration`, error);
|
|
423
432
|
case !(error as AxiosError).response:
|
|
424
|
-
throw new TestCompromisedError(`The API call has failed: ${
|
|
433
|
+
throw new TestCompromisedError(`The API call has failed: ${description}`, error);
|
|
425
434
|
default:
|
|
426
435
|
this.lastResponse = error.response;
|
|
427
436
|
|
|
@@ -463,4 +472,82 @@ export class CallAnApi extends Ability {
|
|
|
463
472
|
|
|
464
473
|
return mappingFunction(this.lastResponse);
|
|
465
474
|
}
|
|
475
|
+
|
|
476
|
+
toJSON(): SerialisedAbility {
|
|
477
|
+
const simplifiedConfig: JSONObject = {
|
|
478
|
+
baseURL: this.axiosInstance.defaults.baseURL,
|
|
479
|
+
headers: this.axiosInstance.defaults.headers,
|
|
480
|
+
timeout: this.axiosInstance.defaults.timeout,
|
|
481
|
+
proxy: proxyConfigFrom(this.axiosInstance.defaults),
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
return {
|
|
485
|
+
...super.toJSON(),
|
|
486
|
+
options: {
|
|
487
|
+
...recursivelyRemove(
|
|
488
|
+
[isUndefined, isEmptyObject],
|
|
489
|
+
simplifiedConfig
|
|
490
|
+
),
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function proxyConfigFrom(defaults: AxiosDefaults): AxiosRequestConfigProxyDefaults | undefined {
|
|
497
|
+
if (defaults.proxy === undefined) {
|
|
498
|
+
return undefined;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (! (defaults.proxy === false && defaults.httpAgent instanceof Agent)) {
|
|
502
|
+
return undefined;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const proxyUrl = (defaults.httpAgent as any).getProxyForUrl(defaults.baseURL);
|
|
506
|
+
|
|
507
|
+
if (! proxyUrl) {
|
|
508
|
+
return undefined;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const url = new URL(proxyUrl);
|
|
512
|
+
|
|
513
|
+
return {
|
|
514
|
+
protocol: url.protocol?.replace(/:$/, ''),
|
|
515
|
+
host: url.hostname,
|
|
516
|
+
port: url.port ? Number(url.port) : undefined,
|
|
517
|
+
auth: url.username
|
|
518
|
+
? {
|
|
519
|
+
username: url.username || undefined,
|
|
520
|
+
password: url.password || undefined,
|
|
521
|
+
}
|
|
522
|
+
: undefined,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function isUndefined(value: any): value is undefined {
|
|
527
|
+
return value === undefined;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function isEmptyObject(value: any): value is object {
|
|
531
|
+
return isObject(value) && Object.keys(value).length === 0;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function recursivelyRemove(matchers: Array<(value: any) => boolean>, value: any): any {
|
|
535
|
+
if (Array.isArray(value)) {
|
|
536
|
+
return value.map(item => recursivelyRemove(matchers, item));
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
if (typeof value === 'object' && value !== null) {
|
|
540
|
+
return Object.keys(value).reduce((acc, key) => {
|
|
541
|
+
if (matchers.some(matcher => matcher(value[key]))) {
|
|
542
|
+
return acc;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return {
|
|
546
|
+
...acc,
|
|
547
|
+
[key]: recursivelyRemove(matchers, value[key]),
|
|
548
|
+
};
|
|
549
|
+
}, {});
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
return value;
|
|
466
553
|
}
|