Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJul 25, 2026·2 min de lecture

Polly.js — Record, Replay, and Stub HTTP Interactions by Netflix

An HTTP interaction recording and playback library by Netflix for deterministic testing of API-dependent code in Node.js and browsers.

Prêt pour agents

Installation avec revue préalable

Cet actif nécessite une revue. Le prompt copié demande un dry-run, affiche les écritures, puis continue seulement après confirmation.

Needs Confirmation · 64/100Policy : confirmer
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Polly.js Overview
Commande avec revue préalable
npx -y tokrepo@latest install 2ef78570-8869-11f1-9bc6-00163e2b0d79 --target codex

Dry-run d'abord, confirmez les écritures, puis lancez cette commande.

Introduction

Polly.js by Netflix records HTTP interactions during test runs and replays them on subsequent executions. This eliminates flaky tests caused by network variability while keeping tests realistic by using actual API responses as fixtures.

What Polly.js Does

  • Records HTTP requests and responses to persistent storage (filesystem, REST API, or localStorage)
  • Replays recorded interactions on subsequent test runs for deterministic results
  • Intercepts and stubs requests that match configurable rules
  • Supports request matching by URL, method, headers, and body
  • Provides timing simulation to mirror real-world latency

Architecture Overview

Polly.js uses an adapter layer to intercept HTTP calls (fetch, XHR, or Node.js http) and a persister layer to store recordings as HAR-like JSON files. On replay, incoming requests are matched against recordings using a configurable matching strategy. Unmatched requests can passthrough, record, or throw depending on the mode.

Self-Hosting & Configuration

  • Install the core package plus your chosen adapter and persister
  • Register adapters and persisters before creating a Polly instance
  • Set recordIfMissing to control behavior for unrecorded requests
  • Configure request matching strictness via matchRequestsBy options
  • Use expiresIn to auto-expire recordings and force re-recording

Key Features

  • Three modes: record, replay, and passthrough for flexible test workflows
  • HAR-compatible recording format for interoperability
  • Request interception with custom response handlers
  • Timing simulation preserving original response latency
  • Built-in adapters for fetch, XHR, and Node.js http

Comparison with Similar Tools

  • MSW (Mock Service Worker) — Mocks at the service worker level; Polly.js records real interactions
  • Nock — Node.js-only HTTP mocking; Polly.js works in both Node.js and browsers
  • VCR (Ruby) — Ruby HTTP recording; Polly.js brings the same pattern to JavaScript
  • WireMock — Java-based mock server; Polly.js runs in-process without a separate server
  • Mirage.js — Client-side mock server; Polly.js focuses on recording real responses

FAQ

Q: Can I use Polly.js with Jest? A: Yes. Use the @pollyjs/core setup/teardown in beforeEach/afterEach hooks.

Q: How do I handle sensitive data in recordings? A: Use the recordFailedRequests option and custom serializers to redact headers or body fields.

Q: Does it support GraphQL? A: Yes. Configure matchRequestsBy to include the request body so different queries are recorded separately.

Q: Can recordings be shared across CI environments? A: Yes. Commit recordings to your repository or use the REST persister to store them centrally.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires