Namespace: serverless

Interfaces

Type Aliases

Headers

Ƭ Headers: Object

Additional headers for postJson and postBinary requests.

Index signature

▪ [key: string]: string


Test

Ƭ Test: Context & { connect?: () => Promise<WebSocket> ; invoke?: (functionName: string, data?: any) => Promise<string[]> ; postBinary?: (path: string, body: Buffer, headers?: Headers) => Promise<Response> ; postJson?: (path: string, body: any, headers?: Headers) => Promise<Response> ; receive?: (socket: WebSocket) => Promise<string> ; serverless?: SpawnInfo }

Serverless intersection Test type: Mocha context with helpers for invoking lambdas and posting JSON requests.

Functions

connect

connect(address): Promise<WebSocket>

Connect to a websocket server.

Parameters

Name Type Description
address string Address of the server

Returns

Promise<WebSocket>


invoke

invoke(serverlessDir, functionName, data?): Promise<string[]>

Invoke a local lambda from a serverless-offline app.

Parameters

Name Type Description
serverlessDir string Build directory for the serverless-offline app
functionName string Lambda name
data? string Data to pass to the Lambda

Returns

Promise<string[]>


postBinary

postBinary(url, body, headers?, agent?): ReturnType<typeof fetch>

Post a base64 encoded octet-stream to the serverless instance.

Parameters

Name Type Description
url string Url to post to
body Buffer Buffer to post as an octet-stream
headers? Headers -
agent? Agent Optional override for the https.Agent

Returns

ReturnType<typeof fetch>


postJson

postJson(url, body, headers?, agent?): ReturnType<typeof fetch>

Post a JSON request to the serverless instance.

Parameters

Name Type Description
url string Url to post to
body any Body to post via JSON.stringify
headers? Headers -
agent? Agent Optional override for the https.Agent

Returns

ReturnType<typeof fetch>


receive

receive(socket): Promise<string>

Receive a message from a previously opened websocket.

Parameters

Name Type Description
socket WebSocket Socket to receive from

Returns

Promise<string>


spawn

spawn(serverlessDir): SpawnInfo

Spawn a serverless-offline app.

Parameters

Name Type Description
serverlessDir string Build directory for the serverless-offline app

Returns

SpawnInfo


suite

suite(title, serverlessDir, testTimeout, fn): Suite

Create a Serverless test suite that automatically spawns a serverless offline instance for each test. Every test in the suite will have this set to serverless.Test type with helpers for invoking lambdas and posting JSON requests.

Set environment variable SLS_TEST_LOG=1 to enable stdout logging.

Parameters

Name Type Description
title string Passed to Mocha describe
serverlessDir string Build directory for the serverless-offline app
testTimeout number Timeout in milliseconds for each test
fn (this: Suite) => void Callback passed to Mocha describe

Returns

Suite