import {ManageALocalServer} from '@serenity-js/local-server/lib/screenplay/abilities'
ManageALocalServer
Implements:
Examples:
import { Actor } from '@serenity-js/core';
import { CallAnApi, GetRequest, Send } from '@serenity-js/rest';
import { ManageALocalServer, LocalTestServer, StartLocalTestServer, StopLocalTestServer } from '@serenity-js/local-server'
import { Ensure, equals } from '@serenity-js/assertions';
import axios from 'axios';
import * as http from 'http';
const server = http.createServer(function (request, response) {
response.setHeader('Connection', 'close');
response.end('Hello!');
})
const actor = Actor.named('Apisit').whoCan(
ManageALocalServer.using(server),
CallAnApi.using(axios.create()),
);
actor.attemptsTo(
StartLocalTestServer.onRandomPort(),
Send.a(GetRequest.to(LocalServer.url())),
Ensure.that(LastResponse.status(), equals(200)),
Ensure.that(LastResponse.body<string>(), equals('Hello!')),
StopLocalTestServer.ifRunning(),
);
Tests:
Static Method Summary
Static Public Methods | ||
public static |
as(actor: UsesAbilities): ManageALocalServer Used to access the Actor's Ability to ManageALocalServer from within the Interaction classes, such as StartLocalServer. |
|
public static |
runningAHttpListener(listener: Server): ManageALocalServer Ability to manage a Node.js HTTP server using the provided |
|
public static |
runningAHttpsListener(listener: Server, options: ServerOptions): ManageALocalServer Ability to manage a Node.js HTTPS server using the provided server |
Constructor Summary
Public Constructor | ||
public |
constructor(protocol: string, server: Server) |
Method Summary
Public Methods | ||
public |
listen(preferredPort: number, highestPort: number): Promise<void> Starts the server on the first free port between |
|
public |
mapInstance(fn: function(server: ServerWithShutdown, protocol?: SupportedProtocols): T): T Provides access to the server requestListener |
Static Public Methods
public static as(actor: UsesAbilities): ManageALocalServer source
Used to access the Actor's Ability to ManageALocalServer from within the Interaction classes, such as StartLocalServer.
Params:
Name | Type | Attribute | Description |
actor | UsesAbilities |
public static runningAHttpListener(listener: Server): ManageALocalServer source
Ability to manage a Node.js HTTP server using the provided requestListener
.
Params:
Name | Type | Attribute | Description |
listener | Server |
public static runningAHttpsListener(listener: Server, options: ServerOptions): ManageALocalServer source
Ability to manage a Node.js HTTPS server using the provided server requestListener
.
Params:
Name | Type | Attribute | Description |
listener | Server | ||
options | ServerOptions | Accepts options from |
Public Constructors
public constructor(protocol: string, server: Server) source
Params:
Name | Type | Attribute | Description |
protocol | string | Protocol to be used when communicating with the running server; |
|
server | Server | A Node.js server requestListener, with support for server shutdown. |
Public Methods
public listen(preferredPort: number, highestPort: number): Promise<void> source
Starts the server on the first free port between preferredPort
and highestPort
, inclusive.
Params:
Name | Type | Attribute | Description |
preferredPort | number |
|
Lower bound of the preferred port range |
highestPort | number |
|
highestPort Upper bound of the preferred port range |
Returns:
Promise<void> |
public mapInstance(fn: function(server: ServerWithShutdown, protocol?: SupportedProtocols): T): T source
Provides access to the server requestListener
Params:
Name | Type | Attribute | Description |
fn | function(server: ServerWithShutdown, protocol?: SupportedProtocols): T |
Returns:
T |