Skip to content

Latest commit

 

History

History
92 lines (52 loc) · 2.48 KB

README.md

File metadata and controls

92 lines (52 loc) · 2.48 KB

xk6-mock

A k6 extension for mocking HTTP(s) servers during test development. The design of the library was inspired by Express. If you already know Express framework, using this library should be very simple.

Features

  • Start mock HTTP server inside of a k6 process
  • Familiar, Express like mock route definitions
  • Almost transparent for test scripts: change import from k6/http to k6/x/mock/http

http module

The k6/x/mock/http module is a drop-in replacement for k6/http module. During the k6 test development simply replace k6/http imports with k6/x/mock/http. Each URL's host and port part will be automatically replaced with the mock server's host and port value. Other parts of the request are remain untouched.

mock module

The k6/x/mock module's default export is an Express like default mock server with the usual HTTP method functions (get, post, ..) and use function for defining middlewares.

You can add route definitions both in Init and VU stages.

Table of contents

Classes

Interfaces

Type aliases

Variables

Type aliases

CallbackFunc

Ƭ CallbackFunc: (req: Request, res: Response, next: NextFunc) => void

CallbackFunc defines middleware and request handler callback function.

param the request object

param the response object

param indicating the next middleware function

Type declaration

▸ (req: Request, res: Response, next: NextFunc): void

Parameters

Name Type
req Request
res Response
next NextFunc

Returns: void


NextFunc

Ƭ NextFunc: () => void

NextFunc defines callback function's next parameter function. Calling from middleware enables processing next middleware.

Type declaration

▸ (): void

Returns: void

Variables

default

Const default: Module

default export