@serenity-js/local-server 3.35.3 → 3.36.1
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 +27 -0
- package/README.md +23 -14
- package/lib/screenplay/abilities/ManageALocalServer.d.ts +8 -12
- package/lib/screenplay/abilities/ManageALocalServer.d.ts.map +1 -1
- package/lib/screenplay/abilities/ManageALocalServer.js +6 -9
- package/lib/screenplay/abilities/ManageALocalServer.js.map +1 -1
- package/lib/screenplay/interactions/StartLocalServer.js +9 -11
- package/lib/screenplay/interactions/StartLocalServer.js.map +1 -1
- package/package.json +12 -12
- package/src/screenplay/abilities/ManageALocalServer.ts +8 -12
- package/src/screenplay/interactions/StartLocalServer.ts +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
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.36.1](https://github.com/serenity-js/serenity-js/compare/v3.36.0...v3.36.1) (2025-11-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **local-server:** updated examples in API docs ([32f99b0](https://github.com/serenity-js/serenity-js/commit/32f99b0620e91d00252a74ea435e5fed9c060da8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [3.36.0](https://github.com/serenity-js/serenity-js/compare/v3.35.3...v3.36.0) (2025-11-06)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **deps:** update dependency axios to v1.13.2 ([9f8d6cc](https://github.com/serenity-js/serenity-js/commit/9f8d6cc34ecf2cbd121380bd584f509b1416e675))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* **core:** introduced support for Node 24, dropped support for Node 18 (EOL) ([9dd5f88](https://github.com/serenity-js/serenity-js/commit/9dd5f885d8e65cd8ff3429a2af94151fbe9134ed))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
6
33
|
## [3.35.3](https://github.com/serenity-js/serenity-js/compare/v3.35.2...v3.35.3) (2025-10-30)
|
|
7
34
|
|
|
8
35
|
|
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ of complex software systems faster, more collaborative and easier to scale.
|
|
|
25
25
|
[`@serenity-js/local-server`](https://serenity-js.org/api/local-server/) enables Serenity/JS Actors to manage local HTTP or HTTPS test servers powered by [Express](https://expressjs.com/),
|
|
26
26
|
[Hapi](https://hapijs.com/),
|
|
27
27
|
[Koa](https://koajs.com/),
|
|
28
|
-
[Restify](http://restify.com/)
|
|
28
|
+
[Restify](http://restify.com/),
|
|
29
29
|
or raw [Node.js](https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/).
|
|
30
30
|
|
|
31
31
|
### Installation
|
|
@@ -42,42 +42,51 @@ npm install --save-dev @serenity-js/core @serenity-js/local-server
|
|
|
42
42
|
```typescript
|
|
43
43
|
import { actorCalled } from '@serenity-js/core'
|
|
44
44
|
import {
|
|
45
|
-
ManageALocalServer,
|
|
45
|
+
ManageALocalServer, StartLocalServer, StopLocalServer
|
|
46
46
|
} from '@serenity-js/local-server'
|
|
47
47
|
import { CallAnApi, GetRequest, Send } from '@serenity-js/rest'
|
|
48
48
|
import { Ensure, equals } from '@serenity-js/assertions'
|
|
49
49
|
import axios from 'axios'
|
|
50
50
|
|
|
51
|
-
import { requestListener } from './listener'
|
|
51
|
+
import { requestListener } from './listener' // (1)
|
|
52
52
|
|
|
53
53
|
const actor = actorCalled('Apisit').whoCan(
|
|
54
|
-
ManageALocalServer.
|
|
54
|
+
ManageALocalServer.runningAHttpListener(requestListener), // (2)
|
|
55
55
|
CallAnApi.using(axios.create()),
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
await actor.attemptsTo(
|
|
59
|
-
|
|
60
|
-
Send.a(GetRequest.to(LocalServer.url())),
|
|
59
|
+
StartLocalServer.onRandomPort(), // (3)
|
|
60
|
+
Send.a(GetRequest.to(LocalServer.url())), // (4)
|
|
61
61
|
Ensure.that(LastResponse.status(), equals(200)),
|
|
62
62
|
Ensure.that(LastResponse.body(), equals('Hello!')),
|
|
63
|
-
|
|
63
|
+
StopLocalServer.ifRunning(), // (5)
|
|
64
64
|
)
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
In the above example:
|
|
68
68
|
|
|
69
|
-
1.
|
|
70
|
-
2.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
1. Import a [`requestListener`](https://nodejs.org/api/http.html#httpcreateserveroptions-requestlistener) you want to use in your test.
|
|
70
|
+
2. Give the [actor](https://serenity-js.org/handbook/design/screenplay-pattern/#actors) an [ability](https://serenity-js.org/handbook/design/screenplay-pattern/#abilities)
|
|
71
|
+
to [`ManageALocalServer`](https://serenity-js.org/api/local-server/class/ManageALocalServer/).
|
|
72
|
+
This enables the interactions to [`StartLocalServer`](https://serenity-js.org/api/local-server/class/StartLocalServer/)
|
|
73
|
+
and [`StopLocalServer`](https://serenity-js.org/api/local-server/class/StopLocalServer/),
|
|
74
|
+
as well as the [`LocalServer`](https://serenity-js.org/api/local-server/class/LocalServer/) question.
|
|
75
|
+
3. Start the local server on a [random port](https://serenity-js.org/api/local-server/class/StartLocalServer/#onRandomPort),
|
|
76
|
+
[specific port](https://serenity-js.org/api/local-server/class/StartLocalServer/#onPort),
|
|
77
|
+
or a random port within your [preferred port range](https://serenity-js.org/api/local-server/class/StartLocalServer/#onRandomPortBetween).
|
|
78
|
+
4. Use the `LocalServer.url()` question to retrieve the url of the local server and interact with its HTTP API.
|
|
79
|
+
5. Stop the local server is when the test is complete.
|
|
80
|
+
Please note that you probably want to [`StopLocalServer`](https://serenity-js.org/api/local-server/class/StopLocalServer/)
|
|
81
|
+
in an `afterEach` block of your test (or something equivalent)
|
|
82
|
+
to make sure that the server is correctly shut down even when the test fails.
|
|
74
83
|
|
|
75
84
|
### Creating a server
|
|
76
85
|
|
|
77
|
-
Any `requestListener`
|
|
86
|
+
Any `requestListener` accepted by Node's
|
|
78
87
|
[`http.createServer`](https://nodejs.org/api/http.html#http_http_createserver_options_requestlistener)
|
|
79
88
|
or [`https.createServer`](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener)
|
|
80
|
-
|
|
89
|
+
can be used with `ManageALocalServer`.
|
|
81
90
|
|
|
82
91
|
Below are example implementations of a simple HTTP server that would
|
|
83
92
|
satisfy the above test.
|
|
@@ -11,7 +11,7 @@ import type * as net from 'net';
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* import { actorCalled } from '@serenity-js/core'
|
|
13
13
|
* import { CallAnApi, GetRequest, Send } from '@serenity-js/rest'
|
|
14
|
-
* import { ManageALocalServer, LocalTestServer,
|
|
14
|
+
* import { ManageALocalServer, LocalTestServer, StartLocalServer, StopLocalServer } from '@serenity-js/local-server'
|
|
15
15
|
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
16
16
|
*
|
|
17
17
|
* import * as axios from 'axios'
|
|
@@ -24,15 +24,15 @@ import type * as net from 'net';
|
|
|
24
24
|
*
|
|
25
25
|
* await actorCalled('Apisit')
|
|
26
26
|
* .whoCan(
|
|
27
|
-
* ManageALocalServer.
|
|
27
|
+
* ManageALocalServer.runningAHttpListener(server),
|
|
28
28
|
* CallAnApi.using(axios.create()),
|
|
29
29
|
* )
|
|
30
30
|
* .attemptsTo(
|
|
31
|
-
*
|
|
31
|
+
* StartLocalServer.onRandomPort(),
|
|
32
32
|
* Send.a(GetRequest.to(LocalServer.url())),
|
|
33
33
|
* Ensure.that(LastResponse.status(), equals(200)),
|
|
34
34
|
* Ensure.that(LastResponse.body<string>(), equals('Hello!')),
|
|
35
|
-
*
|
|
35
|
+
* StopLocalServer.ifRunning(),
|
|
36
36
|
* )
|
|
37
37
|
* ```
|
|
38
38
|
*
|
|
@@ -52,13 +52,12 @@ export declare class ManageALocalServer extends Ability {
|
|
|
52
52
|
*/
|
|
53
53
|
static runningAHttpListener(listener: RequestListener | net.Server): ManageALocalServer;
|
|
54
54
|
/**
|
|
55
|
-
* An [`Ability`](https://serenity-js.org/api/core/class/Ability/) to manage a Node.js HTTPS server
|
|
55
|
+
* An [`Ability`](https://serenity-js.org/api/core/class/Ability/) to manage a Node.js HTTPS server
|
|
56
|
+
* using the provided [`requestListener`](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener).
|
|
56
57
|
*
|
|
57
58
|
* @param listener
|
|
58
59
|
* @param options
|
|
59
60
|
* Accepts an options object from `tls.createServer()`, `tls.createSecureContext()` and `http.createServer()`.
|
|
60
|
-
*
|
|
61
|
-
* @see https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
|
|
62
61
|
*/
|
|
63
62
|
static runningAHttpsListener(listener: RequestListener | https.Server, options?: https.ServerOptions): ManageALocalServer;
|
|
64
63
|
/**
|
|
@@ -67,8 +66,6 @@ export declare class ManageALocalServer extends Ability {
|
|
|
67
66
|
*
|
|
68
67
|
* @param server
|
|
69
68
|
* A Node.js server requestListener, with support for [server shutdown](https://www.npmjs.com/package/http-shutdown).
|
|
70
|
-
*
|
|
71
|
-
* @see https://www.npmjs.com/package/http-shutdown
|
|
72
69
|
*/
|
|
73
70
|
constructor(protocol: SupportedProtocols, server: net.Server);
|
|
74
71
|
/**
|
|
@@ -95,9 +92,8 @@ export declare class ManageALocalServer extends Ability {
|
|
|
95
92
|
*/
|
|
96
93
|
export type RequestListener = (request: http.IncomingMessage, response: http.ServerResponse) => void;
|
|
97
94
|
/**
|
|
98
|
-
* A [`net.Server`](https://nodejs.org/api/net.html#class-netserver) with
|
|
99
|
-
*
|
|
100
|
-
* @see https://www.npmjs.com/package/http-shutdown
|
|
95
|
+
* A [`net.Server`](https://nodejs.org/api/net.html#class-netserver) with
|
|
96
|
+
* an additional [`shutdown`](https://www.npmjs.com/package/http-shutdown) method.
|
|
101
97
|
*/
|
|
102
98
|
export type ServerWithShutdown = net.Server & {
|
|
103
99
|
shutdown: (callback: (error?: Error) => void) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ManageALocalServer.d.ts","sourceRoot":"","sources":["../../../src/screenplay/abilities/ManageALocalServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAsB,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,KAAK,GAAG,MAAM,KAAK,CAAC;AAGhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,kBAAmB,SAAQ,OAAO;
|
|
1
|
+
{"version":3,"file":"ManageALocalServer.d.ts","sourceRoot":"","sources":["../../../src/screenplay/abilities/ManageALocalServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAsB,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,KAAK,GAAG,MAAM,KAAK,CAAC;AAGhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,kBAAmB,SAAQ,OAAO;IAwC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAtCrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAE5C;;;;OAIG;IACH,MAAM,CAAC,oBAAoB,CAAC,QAAQ,EAAE,eAAe,GAAG,GAAG,CAAC,MAAM,GAAG,kBAAkB;IAQvF;;;;;;;OAOG;IACH,MAAM,CAAC,qBAAqB,CAAC,QAAQ,EAAE,eAAe,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,GAAE,KAAK,CAAC,aAAkB,GAAG,kBAAkB;IAQ7H;;;;;;OAMG;gBAC0B,QAAQ,EAAE,kBAAkB,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM;IAK7E;;;;;;;;OAQG;IACH,MAAM,CAAC,aAAa,SAAO,EAAE,WAAW,SAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBhE;;;;OAIG;IACH,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,kBAAkB,EAAE,QAAQ,CAAC,EAAE,kBAAkB,KAAK,CAAC,GAAG,CAAC;CAG1F;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,EAAE,IAAI,CAAC,cAAc,KAAK,IAAI,CAAC;AAErG;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,GAAG,CAAC,MAAM,GAAG;IAC1C,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,KAAK,IAAI,CAAC;IACtD,aAAa,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,KAAK,IAAI,CAAC;CAC9D,CAAC;AAEF;;;;;;GAMG;AACH,oBAAY,kBAAkB;IAC1B,IAAI,SAAS;IACb,KAAK,UAAU;CAClB"}
|
|
@@ -48,7 +48,7 @@ const portfinder_1 = require("portfinder");
|
|
|
48
48
|
* ```ts
|
|
49
49
|
* import { actorCalled } from '@serenity-js/core'
|
|
50
50
|
* import { CallAnApi, GetRequest, Send } from '@serenity-js/rest'
|
|
51
|
-
* import { ManageALocalServer, LocalTestServer,
|
|
51
|
+
* import { ManageALocalServer, LocalTestServer, StartLocalServer, StopLocalServer } from '@serenity-js/local-server'
|
|
52
52
|
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
53
53
|
*
|
|
54
54
|
* import * as axios from 'axios'
|
|
@@ -61,15 +61,15 @@ const portfinder_1 = require("portfinder");
|
|
|
61
61
|
*
|
|
62
62
|
* await actorCalled('Apisit')
|
|
63
63
|
* .whoCan(
|
|
64
|
-
* ManageALocalServer.
|
|
64
|
+
* ManageALocalServer.runningAHttpListener(server),
|
|
65
65
|
* CallAnApi.using(axios.create()),
|
|
66
66
|
* )
|
|
67
67
|
* .attemptsTo(
|
|
68
|
-
*
|
|
68
|
+
* StartLocalServer.onRandomPort(),
|
|
69
69
|
* Send.a(GetRequest.to(LocalServer.url())),
|
|
70
70
|
* Ensure.that(LastResponse.status(), equals(200)),
|
|
71
71
|
* Ensure.that(LastResponse.body<string>(), equals('Hello!')),
|
|
72
|
-
*
|
|
72
|
+
* StopLocalServer.ifRunning(),
|
|
73
73
|
* )
|
|
74
74
|
* ```
|
|
75
75
|
*
|
|
@@ -94,13 +94,12 @@ class ManageALocalServer extends core_1.Ability {
|
|
|
94
94
|
return new ManageALocalServer(SupportedProtocols.HTTP, server);
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
|
-
* An [`Ability`](https://serenity-js.org/api/core/class/Ability/) to manage a Node.js HTTPS server
|
|
97
|
+
* An [`Ability`](https://serenity-js.org/api/core/class/Ability/) to manage a Node.js HTTPS server
|
|
98
|
+
* using the provided [`requestListener`](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener).
|
|
98
99
|
*
|
|
99
100
|
* @param listener
|
|
100
101
|
* @param options
|
|
101
102
|
* Accepts an options object from `tls.createServer()`, `tls.createSecureContext()` and `http.createServer()`.
|
|
102
|
-
*
|
|
103
|
-
* @see https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
|
|
104
103
|
*/
|
|
105
104
|
static runningAHttpsListener(listener, options = {}) {
|
|
106
105
|
const server = typeof listener === 'function'
|
|
@@ -114,8 +113,6 @@ class ManageALocalServer extends core_1.Ability {
|
|
|
114
113
|
*
|
|
115
114
|
* @param server
|
|
116
115
|
* A Node.js server requestListener, with support for [server shutdown](https://www.npmjs.com/package/http-shutdown).
|
|
117
|
-
*
|
|
118
|
-
* @see https://www.npmjs.com/package/http-shutdown
|
|
119
116
|
*/
|
|
120
117
|
constructor(protocol, server) {
|
|
121
118
|
super();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ManageALocalServer.js","sourceRoot":"","sources":["../../../src/screenplay/abilities/ManageALocalServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAgE;AAChE,2CAA6B;AAC7B,qDAAsD;AACtD,6CAA+B;AAE/B,2CAA4C;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAa,kBAAmB,SAAQ,cAAO;
|
|
1
|
+
{"version":3,"file":"ManageALocalServer.js","sourceRoot":"","sources":["../../../src/screenplay/abilities/ManageALocalServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAgE;AAChE,2CAA6B;AAC7B,qDAAsD;AACtD,6CAA+B;AAE/B,2CAA4C;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAa,kBAAmB,SAAQ,cAAO;IAwCd;IAtCZ,MAAM,CAAqB;IAE5C;;;;OAIG;IACH,MAAM,CAAC,oBAAoB,CAAC,QAAsC;QAC9D,MAAM,MAAM,GAAG,OAAO,QAAQ,KAAK,UAAU;YACzC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC;YAC7B,CAAC,CAAC,QAAQ,CAAC;QAEf,OAAO,IAAI,kBAAkB,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,qBAAqB,CAAC,QAAwC,EAAE,UAA+B,EAAE;QACpG,MAAM,MAAM,GAAG,OAAO,QAAQ,KAAK,UAAU;YACzC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC;Y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C,QAAQ,CAAC,CAAC;IAC1C,CAAC;CACJ;AAnFD,gDAmFC;AAkBD;;;;;;GAMG;AACH,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC1B,mCAAa,CAAA;IACb,qCAAe,CAAA;AACnB,CAAC,EAHW,kBAAkB,kCAAlB,kBAAkB,QAG7B"}
|
|
@@ -46,8 +46,8 @@ class StartLocalServerOnRandomPort extends core_1.Interaction {
|
|
|
46
46
|
constructor() {
|
|
47
47
|
super(`#actor starts local server on a random port`);
|
|
48
48
|
}
|
|
49
|
-
performAs(actor) {
|
|
50
|
-
|
|
49
|
+
async performAs(actor) {
|
|
50
|
+
await abilities_1.ManageALocalServer.as(actor).listen();
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
@@ -59,9 +59,9 @@ class StartLocalServerOnPort extends core_1.Interaction {
|
|
|
59
59
|
super(`#actor starts local server on port ${preferredPort}`);
|
|
60
60
|
this.preferredPort = preferredPort;
|
|
61
61
|
}
|
|
62
|
-
performAs(actor) {
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
async performAs(actor) {
|
|
63
|
+
const preferredPort = await actor.answer(this.preferredPort);
|
|
64
|
+
await abilities_1.ManageALocalServer.as(actor).listen(preferredPort);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
@@ -75,12 +75,10 @@ class StartLocalServerOnRandomPortBetween extends core_1.Interaction {
|
|
|
75
75
|
this.lowestPort = lowestPort;
|
|
76
76
|
this.highestPort = highestPort;
|
|
77
77
|
}
|
|
78
|
-
performAs(actor) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
]).
|
|
83
|
-
then(([lowestPort, highestPort]) => abilities_1.ManageALocalServer.as(actor).listen(lowestPort, highestPort));
|
|
78
|
+
async performAs(actor) {
|
|
79
|
+
const lowestPort = await actor.answer(this.lowestPort);
|
|
80
|
+
const highestPort = await actor.answer(this.highestPort);
|
|
81
|
+
await abilities_1.ManageALocalServer.as(actor).listen(lowestPort, highestPort);
|
|
84
82
|
}
|
|
85
83
|
}
|
|
86
84
|
//# sourceMappingURL=StartLocalServer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StartLocalServer.js","sourceRoot":"","sources":["../../../src/screenplay/interactions/StartLocalServer.ts"],"names":[],"mappings":";;;AACA,4CAAgD;AAEhD,4CAAkD;AAElD;;;;GAIG;AACH,MAAa,gBAAgB;IAEzB;;OAEG;IACH,MAAM,CAAC,YAAY;QACf,OAAO,IAAI,4BAA4B,EAAE,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,aAAiC;QAC3C,OAAO,IAAI,sBAAsB,CAAC,aAAa,CAAC,CAAC;IACrD,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,mBAAmB,CAAC,UAA8B,EAAE,WAA+B;QACtF,OAAO,IAAI,mCAAmC,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IAC5E,CAAC;CACJ;AAhCD,4CAgCC;AAED;;GAEG;AACH,MAAM,4BAA6B,SAAQ,kBAAW;IAElD;QACI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACzD,CAAC;IAED,SAAS,CAAC,KAA2D;
|
|
1
|
+
{"version":3,"file":"StartLocalServer.js","sourceRoot":"","sources":["../../../src/screenplay/interactions/StartLocalServer.ts"],"names":[],"mappings":";;;AACA,4CAAgD;AAEhD,4CAAkD;AAElD;;;;GAIG;AACH,MAAa,gBAAgB;IAEzB;;OAEG;IACH,MAAM,CAAC,YAAY;QACf,OAAO,IAAI,4BAA4B,EAAE,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,aAAiC;QAC3C,OAAO,IAAI,sBAAsB,CAAC,aAAa,CAAC,CAAC;IACrD,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,mBAAmB,CAAC,UAA8B,EAAE,WAA+B;QACtF,OAAO,IAAI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AAW,CAAC,CAAC;IACvE,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenity-js/local-server",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.36.1",
|
|
4
4
|
"description": "Serenity/JS Screenplay Pattern library for managing local Node.js test servers, including Express, Koa, Hapi, and Restify, to support comprehensive integration testing",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jan Molak",
|
|
@@ -54,17 +54,17 @@
|
|
|
54
54
|
"url": "https://github.com/serenity-js/serenity-js/issues"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
|
-
"node": "^
|
|
57
|
+
"node": "^20 || ^22 || ^24"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@serenity-js/core": "3.
|
|
60
|
+
"@serenity-js/core": "3.36.1",
|
|
61
61
|
"http-shutdown": "1.2.2",
|
|
62
62
|
"portfinder": "1.0.38"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@hapi/hapi": "^21.4.
|
|
65
|
+
"@hapi/hapi": "^21.4.4",
|
|
66
66
|
"express": "^5.1.0",
|
|
67
|
-
"koa": "^3.
|
|
67
|
+
"koa": "^3.1.1",
|
|
68
68
|
"restify": "^11.1.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependenciesMeta": {
|
|
@@ -82,25 +82,25 @@
|
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@hapi/hapi": "21.4.
|
|
85
|
+
"@hapi/hapi": "21.4.4",
|
|
86
86
|
"@integration/testing-tools": "3.0.0",
|
|
87
|
-
"@serenity-js/assertions": "3.
|
|
88
|
-
"@serenity-js/rest": "3.
|
|
87
|
+
"@serenity-js/assertions": "3.36.1",
|
|
88
|
+
"@serenity-js/rest": "3.36.1",
|
|
89
89
|
"@types/chai": "4.3.20",
|
|
90
90
|
"@types/express": "5.0.5",
|
|
91
91
|
"@types/hapi": "18.0.15",
|
|
92
92
|
"@types/mocha": "10.0.10",
|
|
93
93
|
"@types/restify": "8.5.12",
|
|
94
|
-
"axios": "1.13.
|
|
94
|
+
"axios": "1.13.2",
|
|
95
95
|
"c8": "10.1.3",
|
|
96
96
|
"express": "5.1.0",
|
|
97
|
-
"koa": "3.
|
|
98
|
-
"mocha": "11.7.
|
|
97
|
+
"koa": "3.1.1",
|
|
98
|
+
"mocha": "11.7.5",
|
|
99
99
|
"mocha-multi": "1.1.7",
|
|
100
100
|
"restify": "11.1.0",
|
|
101
101
|
"semver": "7.7.3",
|
|
102
102
|
"ts-node": "10.9.2",
|
|
103
103
|
"typescript": "5.9.3"
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "d13abbfcd6255c6f9466394d4efa1e808907a71f"
|
|
106
106
|
}
|
|
@@ -14,7 +14,7 @@ import { getPortPromise } from 'portfinder';
|
|
|
14
14
|
* ```ts
|
|
15
15
|
* import { actorCalled } from '@serenity-js/core'
|
|
16
16
|
* import { CallAnApi, GetRequest, Send } from '@serenity-js/rest'
|
|
17
|
-
* import { ManageALocalServer, LocalTestServer,
|
|
17
|
+
* import { ManageALocalServer, LocalTestServer, StartLocalServer, StopLocalServer } from '@serenity-js/local-server'
|
|
18
18
|
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
19
19
|
*
|
|
20
20
|
* import * as axios from 'axios'
|
|
@@ -27,15 +27,15 @@ import { getPortPromise } from 'portfinder';
|
|
|
27
27
|
*
|
|
28
28
|
* await actorCalled('Apisit')
|
|
29
29
|
* .whoCan(
|
|
30
|
-
* ManageALocalServer.
|
|
30
|
+
* ManageALocalServer.runningAHttpListener(server),
|
|
31
31
|
* CallAnApi.using(axios.create()),
|
|
32
32
|
* )
|
|
33
33
|
* .attemptsTo(
|
|
34
|
-
*
|
|
34
|
+
* StartLocalServer.onRandomPort(),
|
|
35
35
|
* Send.a(GetRequest.to(LocalServer.url())),
|
|
36
36
|
* Ensure.that(LastResponse.status(), equals(200)),
|
|
37
37
|
* Ensure.that(LastResponse.body<string>(), equals('Hello!')),
|
|
38
|
-
*
|
|
38
|
+
* StopLocalServer.ifRunning(),
|
|
39
39
|
* )
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
@@ -63,13 +63,12 @@ export class ManageALocalServer extends Ability {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
* An [`Ability`](https://serenity-js.org/api/core/class/Ability/) to manage a Node.js HTTPS server
|
|
66
|
+
* An [`Ability`](https://serenity-js.org/api/core/class/Ability/) to manage a Node.js HTTPS server
|
|
67
|
+
* using the provided [`requestListener`](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener).
|
|
67
68
|
*
|
|
68
69
|
* @param listener
|
|
69
70
|
* @param options
|
|
70
71
|
* Accepts an options object from `tls.createServer()`, `tls.createSecureContext()` and `http.createServer()`.
|
|
71
|
-
*
|
|
72
|
-
* @see https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
|
|
73
72
|
*/
|
|
74
73
|
static runningAHttpsListener(listener: RequestListener | https.Server, options: https.ServerOptions = {}): ManageALocalServer {
|
|
75
74
|
const server = typeof listener === 'function'
|
|
@@ -85,8 +84,6 @@ export class ManageALocalServer extends Ability {
|
|
|
85
84
|
*
|
|
86
85
|
* @param server
|
|
87
86
|
* A Node.js server requestListener, with support for [server shutdown](https://www.npmjs.com/package/http-shutdown).
|
|
88
|
-
*
|
|
89
|
-
* @see https://www.npmjs.com/package/http-shutdown
|
|
90
87
|
*/
|
|
91
88
|
constructor(private readonly protocol: SupportedProtocols, server: net.Server) {
|
|
92
89
|
super();
|
|
@@ -141,9 +138,8 @@ export class ManageALocalServer extends Ability {
|
|
|
141
138
|
export type RequestListener = (request: http.IncomingMessage, response: http.ServerResponse) => void;
|
|
142
139
|
|
|
143
140
|
/**
|
|
144
|
-
* A [`net.Server`](https://nodejs.org/api/net.html#class-netserver) with
|
|
145
|
-
*
|
|
146
|
-
* @see https://www.npmjs.com/package/http-shutdown
|
|
141
|
+
* A [`net.Server`](https://nodejs.org/api/net.html#class-netserver) with
|
|
142
|
+
* an additional [`shutdown`](https://www.npmjs.com/package/http-shutdown) method.
|
|
147
143
|
*/
|
|
148
144
|
export type ServerWithShutdown = net.Server & {
|
|
149
145
|
shutdown: (callback: (error?: Error) => void) => void,
|
|
@@ -51,8 +51,8 @@ class StartLocalServerOnRandomPort extends Interaction {
|
|
|
51
51
|
super(`#actor starts local server on a random port`);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): Promise<void> {
|
|
55
|
-
|
|
54
|
+
async performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): Promise<void> {
|
|
55
|
+
await ManageALocalServer.as(actor).listen();
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -65,9 +65,10 @@ class StartLocalServerOnPort extends Interaction {
|
|
|
65
65
|
super(`#actor starts local server on port ${ preferredPort }`);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): Promise<void> {
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
async performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): Promise<void> {
|
|
69
|
+
const preferredPort = await actor.answer(this.preferredPort);
|
|
70
|
+
|
|
71
|
+
await ManageALocalServer.as(actor).listen(preferredPort);
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -83,11 +84,10 @@ class StartLocalServerOnRandomPortBetween extends Interaction {
|
|
|
83
84
|
super(`#actor starts local server on port between ${ lowestPort } and ${ highestPort }`);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): Promise<void> {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
then(([lowestPort, highestPort]) => ManageALocalServer.as(actor).listen(lowestPort, highestPort));
|
|
87
|
+
async performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): Promise<void> {
|
|
88
|
+
const lowestPort = await actor.answer(this.lowestPort);
|
|
89
|
+
const highestPort = await actor.answer(this.highestPort);
|
|
90
|
+
|
|
91
|
+
await ManageALocalServer.as(actor).listen(lowestPort, highestPort);
|
|
92
92
|
}
|
|
93
93
|
}
|