@contract-case/contract-case-jest

中文文档
0.31.4发布于 2026/10/08BSD-3-ClauseTypeScriptCommonJS近 30 天下载 123.5万

ContractCase contract testing suite for Jest

原始使用文档
文档目录5 节
  1. Caveats and limitations
  2. I'm fine with all the caveats, how do I get started?
  3. For Pact users
  4. Roadmap
  5. Releases

ContractCase Contract Testing Framework

Build and test Coverage Status Known Vulnerabilities

npm

Case

Briefcase sticker created by Gohsantosadrive on Flaticon

Read the documentation here.

ContractCase is a next-generation consumer-driven contract testing framework, building on many of the lessons from maintaining the excellent Pact contract testing framework. It is our belief that contract testing is the best way to get deployment confidence for your applications and services.

Feedback welcome on github!

Caveats and limitations

ContractCase is now available and should work for both client and server driven http/https contracts. Feedback on the ContractCase API / DSL and (especially) naming conventions very welcome. However, the following caveats should be kept in mind:

  1. ContractCase is currently only available in Javascript / Typescript and Java. At a later date, support for Python, C# and Go will be added. There are no plans to add other languages at this time.
  2. ContractCase doesn't currently support merging of contracts. This means that each contract must be defined in one test file (per contract).
  3. ContractCase currently is only compatible with Jest (js/ts) and JUnit (java).
  4. ContractCase currently only has minimal broker support. It supports the Pact broker, although the Pact broker isn't able to render ContractCase contracts in the UI.

Although the test coverage is high, and great care has been taken to ensure that the results are correct, there may still be bugs. Please open an issue if you experience any problems.

You can follow the detailed progress by reading the maintainer todo list. These caveats will be updated as progress is made.

I'm fine with all the caveats, how do I get started?

If you want to get started immediately, we recommend starting with the defining contracts documentation.

npm install --save-dev @contract-case/contract-case-jest

You may also need jest:

npm install --save-dev jest

For Pact users

ContractCase has a very similar philosophy to Pact, and to maximise Pact compatibility, ContractCase works with the Pact broker. We recommend either:

  • The Pact Broker for users wanting to host their own broke
  • The excellent Pactflow Broker for those needing SaaS and enterprise features

There are a few key differences - ContractCase is easier to extend, can express more complex contracts, and can define contracts at either the server side or the client side (although it is always consumer driven - your consumer just might be consuming requests). See for Pact users for more discussion.

Roadmap

  1. Pact Parity (complete)
  2. Server driven contracts (complete)
  3. Plugins and arbitrary extensions (complete)
  4. Support java (complete)
  5. Support function-based contracts (complete)
  6. Documentation (in progress)
  7. gRPC matchers
  8. Support Python, C# and Go
  9. Arbitrary combinations of request/response pairs, incidentally including native SQS support
  10. Pass-through APIs

For the gory details of the roadmap, you can see the implementation notebook / todo list here

Releases

ContractCase releases follow semantic versioning, with two additional restrictions:

  1. Before 1.0.0, ContractContractCase is in Beta, and the API is considered unstable. Breaking changes will be indicated in minor version bumps- that is, 0.2.0 and 0.3.0 are not entirely compatible.
  2. Before 1.0.0, patch versions will always be backwards compatible.

Breaking changes will always be detailed in the changelog.

版本与发布记录

@contract-case/contract-case-jest 共发布 56 个版本,首次发布于 2023/05/03;过去 12 个月发布了 13 个版本。

版本发布日期距今
0.31.4latest2026/10/081 个月前
0.31.32026/10/021 个月前
0.31.22026/08/312 个月前
0.31.12026/08/312 个月前
0.31.02026/08/282 个月前
0.30.22026/08/282 个月前

关于 @contract-case/contract-case-jest 的常见问题

@contract-case/contract-case-jest 是什么?

ContractCase contract testing suite for Jest

如何安装 @contract-case/contract-case-jest?

在项目目录运行 npm install @contract-case/contract-case-jest,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:jest(^29.4.3 || ^30.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 ContractCase,可以用 npx ContractCase 直接运行。

@contract-case/contract-case-jest 支持 TypeScript 吗?

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

@contract-case/contract-case-jest 支持 ESM 还是 CommonJS?

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

@contract-case/contract-case-jest 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@contract-case/contract-case-jest 可以商用吗?

@contract-case/contract-case-jest 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@contract-case/contract-case-jest 的下载量有多少?

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

@contract-case/contract-case-jest 还在维护吗?

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