@exodus/replay

中文文档
1.0.0-rc.11发布于 2026/02/08MITES Module零依赖近 30 天下载 1.9万

Record/inspect/replay fetch and WebSocket sessions

原始使用文档
文档目录8 节
  1. fetchRecorder(log[, { fetch }])
  2. fetchReplayer(log)
  3. WebSocketRecorder(log[, { WebSocket }])
  4. WebSocketReplayer(log[, { interval = 0 }])
  5. prettyJSON(data, { width = 120 })
  6. Samples
  7. fetch recording
  8. WebSocket recording

Record/inspect/replay fetch and WebSocket sessions

For offline testing

These implementations are not specific to @exodus/test and can be used separately

Zero-dependencies, bundleable

Replayers can run in V8 / JavaScriptCore / Hermes even with no network API implemented at all

import { fetchRecorder, fetchReplayer, WebSocketRecorder, WebSocketReplayer, prettyJSON } from '@exodus/replay'

Generated logs are human-readable

fetchRecorder(log[, { fetch }])

Returns a fetch implementation that appends all requests to the provided log array

log is expected to be an array and is mutated by appending new requests

If a base fetch implementation is not passed, global fetch is used as the base

That can be overriden, e.g. fetchRecorder(log, { fetch: require('node-fetch') })

fetchReplayer(log)

Returns a fetch implementation that replies with requests from the provided log array

Requests are served by "first matching" order and are discarded from an internal log clone

log is expected to be an array and is not mutated

WebSocketRecorder(log[, { WebSocket }])

Returns a WebSocket implementation that appends all sessions to the provided log array

log is expected to be an array and is mutated by appending new sessions

If a base WebSocket implementation is not passed, global WebSocket is used as the base

That can be overriden, e.g. WebSocketRecorder(log, { WebSocket: require('ws') })

WebSocketReplayer(log[, { interval = 0 }])

Returns a WebSocket implementation that replies with sessions from the provided log array

Sessions are served by "first matching" order and are discarded from an internal log clone

log is expected to be an array and is not mutated

Optionally, interval can be used to control replay speed:

  • interval = 0 for immediate event firing without delays (default)

  • interval = Infinity for event timing matching the original recording

  • interval = number for delay between events of Math.min(number, recorededDelay)

prettyJSON(data, { width = 120 })

Use it to pretty-print logs: prettyJSON(log)

Like JSON.stringify(), but with pretty-printing for readability and ease if inspection

The output is parse-able with JSON.parse()

For simplicity, fitting into width is not guaranteed, but the output is stable between runs

Samples

fetch recording

{
  "request": {
    "resource": "https://jsonplaceholder.typicode.com/users/2",
    "options": { "headers": [["accept", "application/json"]] }
  },
  "status": 200,
  "statusText": "OK",
  "ok": true,
  "headers": [
    ...
    ["connection", "keep-alive"],
    ["content-encoding", "br"],
    ["content-type", "application/json; charset=utf-8"],
    ["date", "Sat, 03 Aug 2024 16:57:51 GMT"],
    ...
  ],
  "url": "https://jsonplaceholder.typicode.com/users/2",
  "redirected": false,
  "type": "basic",
  "bodyType": "json",
  "body": {
    "id": 2,
    "name": "Ervin Howell",
    "username": "Antonette",
    "email": "[email protected]",
    "address": {
      "street": "Victor Plains",
      "suite": "Suite 879",
      "city": "Wisokyburgh",
      "zipcode": "90566-7771",
      "geo": { "lat": "-43.9509", "lng": "-34.4618" }
    },
    "phone": "010-692-6593 x09125",
    "website": "anastasia.net",
    "company": {
      "name": "Deckow-Crist",
      "catchPhrase": "Proactive didactic contingency",
      "bs": "synergize scalable supply-chains"
    }
  }
}

WebSocket recording

{
  "url": "wss://javascript.info/article/websocket/demo/hello",
  "log": [
    { "type": "get readyState", "at": 24, "value": 0 },
    { "type": "open", "at": 426 },
    { "type": "get readyState", "at": 426, "value": 1 },
    { "type": "get bufferedAmount", "at": 427, "value": 0 },
    { "type": "send()", "at": 427, "data": "Hi there" },
    { "type": "get bufferedAmount", "at": 427, "value": 8 },
    { "type": "message", "at": 543, "data": "Hello from server, there!" },
    { "type": "close()", "at": 543 },
    { "type": "get readyState", "at": 543, "value": 2 },
    { "type": "close", "at": 661, "code": 1005, "reason": "", "wasClean": true },
    { "type": "get readyState", "at": 661, "value": 3 }
  ]
}

版本与发布记录

@exodus/replay 共发布 12 个版本,首次发布于 2024/08/07;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.0.0-rc.11latest2026/02/089 个月前
1.0.0-rc.102026/02/069 个月前
1.0.0-rc.92025/05/241.5 年前
1.0.0-rc.82025/04/251.6 年前
1.0.0-rc.72025/04/251.6 年前
1.0.0-rc.62025/04/201.6 年前

关于 @exodus/replay 的常见问题

@exodus/replay 是什么?

Record/inspect/replay fetch and WebSocket sessions

如何安装 @exodus/replay?

在项目目录运行 npm install @exodus/replay,或使用 pnpm add / yarn add / bun add。

@exodus/replay 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/exodus__replay 是否存在。

@exodus/replay 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@exodus/replay 可以商用吗?

@exodus/replay 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@exodus/replay 的下载量有多少?

根据 npm 官方下载统计,@exodus/replay 在 2026/10/14 – 2026/11/12 这 30 天内被下载 19,154 次,日均约 638 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@exodus/replay 还在维护吗?

最新版本 1.0.0-rc.11 发布于 2026/02/08(9 个月前);至今共发布 12 个版本,其中过去 12 个月发布了 2 个;首次发布于 2024/08/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。