@anev/ts-mountebank

中文文档
1.8.0发布于 2023/10/06ISCTypeScriptCommonJS近 30 天下载 8505

Mountebank client for TS / node

原始使用文档
文档目录5 节
  1. Usage
  2. Pre-Requisite
  3. Create Imposter
  4. Check for QueryString
  5. Create Debug Proxy

ts-mountebank

A simple node package that lets you manage your Mountebank test server. Based on https://www.npmjs.com/package/@toincrease/node-mountebank, but

  • updated/removed vulnerable packages,
  • modernized the code and
  • added ability to create very simple proxies
  • improved predicates (not just equal)

Usage

Pre-Requisite

Install Mountebank:

npm install -g mountebank --production

Start Mountebank:

mb 

I recommend reading the Mountebank documentation for a deeper understanding of their API.

For more samples on how to use this package check this blog: https://angela-evans.com/easy-api-tests-with-mountebank/ or the integration tests.

Create Imposter

const mb = new Mountebank();
let imposter = new Imposter().withPort(port).withStub(
    new DefaultStub(testPath, HttpMethod.GET, 'testbody', 222));
await mb.createImposter(imposter);

Check for QueryString

Add a query to the stub. For usages check the tests in ./integration-tests/predicate.flexi-predicate.query.mb-tests.ts

new Stub()
    .withPredicate(
    new FlexiPredicate()
        .withOperator(Operator.equals)
        .withPath('/testpath')
        .withQuery({name: 'x', max: 5})
    )
    .withResponse(new DefaultResponse('found', 222))

Create Debug Proxy

A simple proxy which always proxies the request and records the responses. This is useful to

  • 'debug' traffic during tests or
  • record traffic between APIs to use as template for building imposters.
// forward all requestsfrom port 5000 => 5001 and generate response stubs
let proxyImposter = new Imposter()
    .withPort(5000)
    .withStub(new Stub()
        .withProxy(new DebugProxy(`http://localhost:5001}`))); 

await mb.createImposter(proxyImposter);

版本与发布记录

@anev/ts-mountebank 共发布 14 个版本,首次发布于 2021/05/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.8.0latest2023/10/063 年前
1.7.02023/07/213 年前
1.6.12022/11/163 年前
1.6.02022/08/064 年前
1.5.02022/04/074 年前
1.4.12022/01/164 年前

关于 @anev/ts-mountebank 的常见问题

@anev/ts-mountebank 是什么?

Mountebank client for TS / node

如何安装 @anev/ts-mountebank?

在项目目录运行 npm install @anev/ts-mountebank,或使用 pnpm add / yarn add / bun add。

@anev/ts-mountebank 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@anev/ts-mountebank 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@anev/ts-mountebank 可以商用吗?

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

@anev/ts-mountebank 的下载量有多少?

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

@anev/ts-mountebank 还在维护吗?

最新版本 1.8.0 发布于 2023/10/06(3 年前);至今共发布 14 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/05/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。