@aventara/testing

中文文档
1.0.0-rc.12发布于 2026/11/01SEE LICENSE IN LICENSETypeScriptES Module近 30 天下载 2408

Conformance and extension testing utilities for Aventara.

原始使用文档
文档目录5 节
  1. Install
  2. Serving the corpus through your own stack
  3. The corpus as JSON
  4. Documentation
  5. License

@aventara/testing

Conformance fixtures and testing utilities for Aventara extensions. They test an adapter or a transport host from outside.

  • createFakeAdapter: an in-memory adapter, with transaction tracing, for testing code that runs an AvFramework without a database.
  • runAvProtocolConformance(driver): drives the protocol corpus (AvProtocolFixtures) through one host and reports, per row, every mismatch with the expected status, code, cause, headers and body. A host supplies an AvProtocolDriver: given an AvFramework, a session that sends one protocol request and returns the answer, and closes.
  • AvProtocolCorpus: the corpus's server side, for serving it through your own client or host (below).
  • @aventara/testing/fixtures/protocol-v1.json: the same corpus as plain JSON, for a client or host written in any language (below).

It depends on @aventara/core only.

Install

npm install --save-dev @aventara/testing@rc

Node ^22.23.4 || >=24.22.1. ES modules.

Serving the corpus through your own stack

runAvProtocolConformance builds the corpus AvFramework itself. To serve it from a host or test bench of your own, for example to point a client you are writing at it, take it from AvProtocolCorpus:

import { AvProtocolCorpus, AvProtocolFixtures } from "@aventara/testing";

const framework = await AvProtocolCorpus.framework();
// Mount `framework` under AvProtocolCorpus.entrypoint ("/api") with your host,
// then send each row's `request` and compare the answer with the row's `server`.
  • framework(contractHash?): a fresh corpus AvFramework, backed by an in-memory adapter whose answers every row states. Pass a row's Aventara-Contract-Hash to get the contract that row targets (a cached read's GET sends no such header: pass its query's v). A few rows target a contract without transactions, the /_access/can rows one with access, and the cached-read rows one with cache stages; every other hash (a stale one included) gets the main contract.
  • entrypoint: where the corpus is mounted; every row's path is relative to it.
  • clientContractHash: the main ClientContract's hash. A client generated against it sends this hash, and GET /_contract names it.

A row whose client.outcome is "transport-error" describes an answer no host produces (a proxy's HTML page, a dropped connection); skip it when serving, as the conformance run does. A row's adapterCalls counts the operations the corpus adapter was handed, which only the conformance run can observe.

The corpus as JSON

@aventara/testing/fixtures/protocol-v1.json holds the whole corpus for protocol version 1. It is generated from AvProtocolFixtures when the package is built, with every row in the same order and with the same fields, so a client or host written in another language can be held to the same answers:

{
  "protocolVersion": 1,
  "entrypoint": "/api",
  "clientContractHash": "sha256:…",
  "contracts": [{ "hash": "sha256:…", "document": "{\"enums\":{},…}" }, …],
  "rows": [{ "label": "…", "request": { … }, "server": { … }, "client": { … } }, …]
}
  • contracts: each ClientContract a row targets: its hash and its exact GET /_contract bytes (document, a string). The first is the main contract, clientContractHash; a row targets another by sending its hash (a cached read's GET as its query's v).
  • rows: as AvProtocolFixture describes them. A cached read's request carries its query (without the ?). A streamed POST /_all answer (Accept: application/x-ndjson) is no envelope: its row's code is null and its bodyBytes are the lines in order. One body is too large to write out (one byte over the 1 MiB request limit): its request.body.content is a recipe, { "prefix": "…", "repeat": "x", "times": 1048567, "suffix": "…" }, standing for prefix + repeat repeated times times + suffix. Every other content is the body's text.

From JavaScript: require("@aventara/testing/fixtures/protocol-v1.json"), or import it with { type: "json" }.

Documentation

@aventara/core's README is where to start (the framework, its adapters and hosts). @aventara/nest is held to this corpus on Express and Fastify in its own tests. Each package's README ships in its tarball and shows on its npm page.

License

PolyForm Shield 1.0.0 with an additional permission. It is free to use, including in commercial applications, but you may not use it to build a product that competes with Aventara itself. See LICENSE and LICENSE-ADDITIONAL-PERMISSION.md.

版本与发布记录

@aventara/testing 共发布 16 个版本,首次发布于 2026/10/06;过去 12 个月发布了 16 个版本。

版本发布日期距今
1.0.0-rc.12latest2026/11/016 天前
1.0.0-rc.112026/10/317 天前
1.0.0-rc.102026/10/2711 天前
1.0.0-rc.92026/10/2315 天前
1.0.0-rc.82026/10/2216 天前
1.0.0-rc.42026/10/2117 天前

其他发布通道:pilot → 0.1.0-pilot.4。

关于 @aventara/testing 的常见问题

@aventara/testing 是什么?

Conformance and extension testing utilities for Aventara.

如何安装 @aventara/testing?

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

@aventara/testing 支持 TypeScript 吗?

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

@aventara/testing 支持 ESM 还是 CommonJS?

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

@aventara/testing 需要什么版本的 Node.js?

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

@aventara/testing 可以商用吗?

@aventara/testing 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@aventara/testing 的下载量有多少?

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

@aventara/testing 还在维护吗?

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