API
createTestApp()
Boots an app and returns a TestApp. When boot fails, the TestingError names the phase (config, setup, plugins, overrides, initialize or ready) and the step, and keeps the original error as cause.
| Option | Default | Description |
|---|---|---|
controllers | [] | Controller classes to bind. |
providers | [] | Services to bind as singletons: a class, or [key, implementation]. |
overrides | [] | [key, replacement] pairs, applied after plugins. |
strictOverrides | false | Wrap object overrides with stub(). |
plugins | [] | Plugins to register: a class, or [class, options]. |
config | {} | Configuration over { requestLogging: false, logLevel: 'error' }. |
configFile | false | { cwd } loads vercube.config and .env from there. |
logger | true | Bind a TestLogger and expose it as app.logs. |
setup | none | (app) => void, run after the bindings above and before plugins are applied. |
baseUrl | 'http://localhost' | Base URL for relative paths. |
extensions | [] | See Extensions. |
TestApp
| Member | Description |
|---|---|
get(path), post(), put(), patch(), delete(), head(), options(), request(method, path) | Start a request. |
fetch(input, init?) | Send a Request or a path as is. |
client | A @vercube/client for the app, typed by createTestApp<Routes>(). |
agent() | A client with its own cookie jar. |
resolve(key), resolveOptional(key) | Get a service from the container. |
logs | The TestLogger. Throws with logger: false. |
app, container | The App and its container. |
close(), [Symbol.asyncDispose]() | Close the app, then tear the extensions down. Safe to call twice. |
useImpersonator(handler) | For extensions: support .as(user). |
override() | Always throws: declare overrides up front. |
TestRequest
Builder methods: header(), headers(), query(), cookie(), json(), text(), form(), urlencoded(), body(), bearer(), as(), signal(). Expectations: expect(status), expect(header, value), expect(check). It is sent when awaited or on send(), once however many times it is awaited.
TestResponse
status, headers, ok, raw, request, json(), text(), bytes(), cookies(), events().
createTestContainer()
Takes providers, overrides, strictOverrides and logger, and returns { container, logs }. logs is null with logger: false.
stub()
stub<T>(partial, name?) returns a T whose missing methods throw a TestingError naming name and the method.
TestLogger
records, find(level?, match?), filter(level?, match?), clear() and print, plus every Logger method. Drains, enrichers and evlog plugins are accepted and ignored.
TestingError
Thrown for failed expectations, unstubbed methods and failed boots. Carries request, response, phase and cause where they apply.
Core options used by the module
createTestApp() is built on two createApp() options that are available to any app: configFile (false, or { cwd }) and beforeInitialize(app), which runs after plugins have been applied and before the container is initialised.