HTTP request recording and replay system for API testing
—
Replay provides flexible host routing capabilities to handle different network scenarios, including localhost redirection, pass-through hosts, and connection dropping.
Configure hosts to be treated as localhost, routing requests to 127.0.0.1 without recording or replay.
/**
* Configure hosts to be treated as localhost
* @param {...string} hosts - Hostnames or host patterns to treat as localhost
* @returns {Replay} The Replay instance for chaining
*/
Replay.localhost(...hosts: string[]): Replay;
/**
* Check if a host should be treated as localhost
* @param {string} host - Hostname to check
* @returns {boolean} True if host should be treated as localhost
*/
Replay.isLocalhost(host: string): boolean;Usage Examples:
const Replay = require('replay');
// Configure localhost hosts
Replay.localhost('api.myapp.local', 'test.example.com');
// Use wildcard patterns
Replay.localhost('*.dev.local', 'api.*');
// Check if host is configured as localhost
if (Replay.isLocalhost('api.myapp.local')) {
console.log('Host will be routed to 127.0.0.1');
}Configure hosts to bypass recording and replay, allowing direct network access.
/**
* Configure hosts to pass through directly (bypass recording/replay)
* @param {...string} hosts - Hostnames or host patterns to pass through
* @returns {Replay} The Replay instance for chaining
*/
Replay.passThrough(...hosts: string[]): Replay;
/**
* Check if a host is configured for pass-through
* @param {string} host - Hostname to check
* @returns {boolean} True if host should pass through
*/
Replay.isPassThrough(host: string): boolean;Usage Examples:
const Replay = require('replay');
// Configure pass-through hosts
Replay.passThrough('s3.amazonaws.com', 'cdn.example.com');
// Use wildcard patterns
Replay.passThrough('*.googleapis.com', 'api.github.*');
// Check if host is configured for pass-through
if (Replay.isPassThrough('s3.amazonaws.com')) {
console.log('Host will bypass replay system');
}Configure hosts to be dropped (simulate network unavailable), useful for blocking unwanted requests.
/**
* Configure hosts to drop connections (simulate network unavailable)
* @param {...string} hosts - Hostnames or host patterns to drop
* @returns {Replay} The Replay instance for chaining
*/
Replay.drop(...hosts: string[]): Replay;
/**
* Check if a host is configured to be dropped
* @param {string} host - Hostname to check
* @returns {boolean} True if host should be dropped
*/
Replay.isDropped(host: string): boolean;Usage Examples:
const Replay = require('replay');
// Drop analytics and tracking hosts
Replay.drop('www.google-analytics.com', 'rollbar.com');
// Use wildcard patterns
Replay.drop('*.doubleclick.net', 'tracking.*');
// Check if host is configured to be dropped
if (Replay.isDropped('www.google-analytics.com')) {
console.log('Host connections will be dropped');
}Remove hosts from all configuration lists (localhost, pass-through, and drop).
/**
* Remove hosts from all lists (passThrough, drop, localhost)
* @param {...string} hosts - Hostnames to reset
* @returns {Replay} The Replay instance for chaining
*/
Replay.reset(...hosts: string[]): Replay;Usage Examples:
const Replay = require('replay');
// Configure various hosts
Replay.localhost('api.local')
.passThrough('cdn.example.com')
.drop('tracker.example.com');
// Reset specific hosts
Replay.reset('api.local', 'cdn.example.com');
// Reset all configured hosts
Replay.reset('api.local', 'cdn.example.com', 'tracker.example.com');All host configuration methods support flexible pattern matching:
Replay.localhost('api.example.com');
// Matches exactly: api.example.comReplay.passThrough('*.example.com');
// Matches: api.example.com, cdn.example.com, www.example.com
// Does not match: example.com, test.api.example.comReplay.drop('api.*');
// Matches: api.example.com, api.test.com, api.local
// Does not match: test.api.example.com// Configure multiple patterns at once
Replay.localhost('localhost', '127.0.0.1', '::1', '*.local');When a host matches multiple configurations, the priority is:
Usage Examples:
const Replay = require('replay');
// This host will be treated as localhost (highest priority)
Replay.localhost('api.example.com')
.drop('api.example.com')
.passThrough('api.example.com');
// Check priorities
console.log(Replay.isLocalhost('api.example.com')); // true
console.log(Replay.isDropped('api.example.com')); // true
console.log(Replay.isPassThrough('api.example.com')); // true
// But actual behavior will be localhost routingAll configuration methods return the Replay instance for method chaining:
const Replay = require('replay');
// Chain multiple configuration calls
Replay
.localhost('*.local')
.passThrough('s3.amazonaws.com', '*.googleapis.com')
.drop('*.doubleclick.net', 'www.google-analytics.com')
.reset('old.example.com');Install with Tessl CLI
npx tessl i tessl/npm-replay