For the complete documentation index, see llms.txt. This page is also available as Markdown.

Configuration

Configuring URL Patterns

Q: How do I specify which URLs to intercept?

A: Use the urls array with strings or regular expressions to filter which requests Stoobly intercepts.

Example:

const stoobly = new Stoobly();

// Exact URL match
const interceptor1 = stoobly.playwrightInterceptor({
  urls: ['https://api.example.com/users'],
});

// Regex pattern (match all API endpoints)
const interceptor2 = stoobly.playwrightInterceptor({
  urls: [new RegExp('https://api.example.com/.*')],
});

// Multiple URLs
const interceptor3 = stoobly.playwrightInterceptor({
  urls: [
    'https://api.example.com/users',
    'https://api.example.com/products',
    new RegExp('https://cdn.example.com/.*'),
  ],
});

Q: How do I configure per-URL options like match rules or fixture paths?

A: Pass InterceptorUrl objects in the urls array to attach per-URL configuration such as match rules, rewrite rules, a public directory path, or a response fixtures path.

InterceptorUrl shape:

Example:

Use InterceptorUrl when:

  1. You need different match rules for specific endpoints

  2. You want to serve static fixture files for certain URLs

  3. You need rewrite rules applied to a subset of intercepted URLs


Q: How do I change the intercepted URLs dynamically?

A: Pass a new urls array to enable() to update which URLs are intercepted.

Example:


Request Matching

Q: What determines whether a request matches a recording during mocking?

A: Stoobly matches requests against recordings using these components, in order (case-sensitive):

  1. HTTP Method (required) — GET, POST, PUT, DELETE, etc.

  2. Path (required) — e.g., /users

  3. Query Parameters — Sorted alphabetically before comparison

  4. Headers — Sorted alphabetically before comparison

  5. Body — Strict matching if provided

  6. Body Parameters — Parsed from JSON or form-urlencoded, sorted alphabetically

If a scenarioKey or scenarioName is set, only requests within that scenario are considered; otherwise any matching recorded request is used. Multiple matches within a scenario return responses in recording order. Use per-URL matchRules (see above) to relax which components are compared.


Scenarios and Sessions

Q: How do I specify a scenario for my tests?

A: Prefer scenarioName in the interceptor options to associate requests with a scenario. This is more intuitive and avoids managing keys. You can also derive it from your test framework (e.g., Playwright testInfo.titlePath.join(' > ')).

Example:

Q: How do I change the scenario dynamically?

A: Use withScenarioName() to update the scenario.

Example:

Q: What is a session ID and how do I use it?

A: A session ID groups requests together within a scenario. It defaults to the current timestamp but can be customized for test reproducibility.

Example:


Recording Configuration

Q: What record policies are available?

A: Stoobly supports three record policies: All (record everything), Found (record only if request exists), and NotFound (record only new requests).

Example:

Q: What's the difference between record orders?

A: Overwrite replaces existing requests with the same signature, while Append always creates new request records.

Example:

Note: Overwrite is sent only once per URL pattern per session. Subsequent requests to the same URL pattern use Append behavior. Each URL pattern is tracked independently, so multiple patterns can each receive one overwrite.

Q: What record strategies are available?

A: Stoobly supports Full (record complete request/response) and Minimal (record only essential data).

Example:

Q: How do I change record settings dynamically?

A: Use withRecordPolicy(), withRecordOrder(), and withRecordStrategy() methods.

Example:


Controlling Interception

Q: How do I manage the intercept mode (mock, record, replay) for tests?

A: The simplest, CI-friendly way is to set the STOOBLY_INTERCEPT_MODE environment variable before running your tests. This avoids hardcoding modes in code and keeps behavior consistent across local and CI.

Try:

  1. Set an environment variable for the whole test run:

    • macOS/Linux:

    • One-off run:

  2. Set per-interceptor in code if needed for a specific suite (derive from the environment variable):

More details: Intercept FAQ (https://docs.stoobly.com/faq/intercept)

Q: How do I stop recording requests?

A: Call enable({ mode: InterceptMode.mock }) (or another non-record mode) to stop recording while keeping interception active. apply/clear remain as deprecated aliases for enable/disable.

Example:

Q: How do I completely remove the interceptor?

A: Use disable() to remove all interception and reset session state for the next enable().

Example:

Q: What's the difference between disable() and switching modes with enable()?

A: disable() tears down interception (routes / patches) and resets the session id that enable() will assign next. To keep intercepting but stop recording, call enable({ mode: InterceptMode.mock }) instead of disable().

Example:


Advanced Configuration

Q: How do I set a custom Stoobly UI URL?

A: Pass the UI URL to the Stoobly constructor if your agent is running on a different port or host.

Example:

Q: How do I use test titles for request grouping?

A: Set test titles using withTestTitle() to group requests by test name in the Stoobly UI.

Example:

Q: Can I use the interceptor without a test framework?

A: Yes, use the generic interceptor() method for vanilla JavaScript applications.

Example:

Q: How do I read or update the Stoobly agent's configuration from my tests?

A: Use the config property on the Stoobly instance to dump the agent's full configuration, get a summary, or set the active scenario.

Example:


Constants Reference

Q: What other constants does stoobly/constants export besides RecordPolicy, RecordOrder, RecordStrategy, and InterceptMode?

A: stoobly/constants also exports enums for mocking, replaying, testing, and request filtering/matching:

MockPolicy is set via mock: { policy } in InterceptorSettings (or withMockPolicy()). RequestParameter is used in per-URL matchRules/rewriteRules (see Configuring URL Patterns above) to specify which request components to match on or rewrite.

Last updated