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.
- 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
tok6/x/mock/http
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.
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.
Ƭ 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
▸ (req
: Request, res
: Response, next
: NextFunc): void
Name | Type |
---|---|
req |
Request |
res |
Response |
next |
NextFunc |
Returns: void
Ƭ NextFunc: () => void
NextFunc defines callback function's next
parameter function.
Calling from middleware enables processing next middleware.
▸ (): void
Returns: void
• Const
default: Module
default export