Scripts & tests
Turn every request
into a test.
Prepare data before a request goes out, then assert on what comes back. Plain JavaScript, a sandboxed runtime, and results right beside the response.
- JavaScript
- QuickJS sandbox
- Pass/fail + console
Two scripts, one request
1// Pre-request · runs before the request is sent2const requestId = "req-" + Math.random().toString(36).slice(2, 10);3variables.set("requestId", requestId);4console.log("Sending", request.name, "as", requestId); 1// Tests · run after the response arrives2test("status is 201", () => response.status === 201);3 4test("responds with JSON", () =>5 response.headers["content-type"].includes("application/json"));6 7const order = JSON.parse(response.bodyPreview);8test("order has an id", () => typeof order.id === "string");9test("quantity matches", () => order.quantity === 2); Script reference
The complete set of globals available to scripts. Standard JavaScript built-ins like JSON, Math and Date are available too.
| Global | Type | Description |
|---|---|---|
| request.name | string | The request’s name. |
| request.protocol | string | Protocol id, e.g. "rest" or "graphql". |
| request.config | object | The request’s configuration (URL, method, headers, body …). |
| response.status | number | Status code. Tests only — absent in pre-request scripts. |
| response.statusText | string | Status text, e.g. "Created". |
| response.headers | object | Response headers as name → value. |
| response.bodyPreview | string | The response body as text (very large bodies are truncated). |
| response.sizeBytes | number | Response size in bytes. |
| response.timing | object | startedAt / endedAt timestamps in ms. |
| variables.get(key) | string | undefined | Read a variable from the current run. |
| variables.set(key, value) | void | Set a variable for the current run — e.g. a value the request uses. |
| console.log(...args) | void | Captured and shown with the test results. |
| test(name, fn) | void | Passes when fn returns a truthy value; fails when it returns falsy or throws. |
Scripting questions
What language are Voyager scripts written in?
JavaScript. Scripts run in QuickJS, a small, standards-compliant JavaScript engine, inside an isolated sandbox.
Is it the same as Postman’s pm API?
No. Voyager’s script API is intentionally small: request, response, variables, console and test. Postman scripts that use pm.* need to be adapted when you move them over.
Can a script access my file system or the network?
No. The sandbox only exposes the globals listed on this page, and scripts are stopped if they run past their time limit.
Can I run a whole collection of tests at once?
Not yet. Tests run when you send each request today. A CLI runner and GitHub Actions support for CI are on the roadmap.