@t-req/plugin-assert
v0.1.0
Published
Inline assertion plugin for t-req (@assert directives in .http files)
Maintainers
Readme
@t-req/plugin-assert
Inline assertions for t-req using # @assert ... directives in .http files.
Installation
npm install @t-req/plugin-assert
# or
bun add @t-req/plugin-assert
yarn add @t-req/plugin-assert
pnpm add @t-req/plugin-assertSetup
Add to treq.jsonc:
{
"plugins": ["@t-req/plugin-assert"]
}Or load ad-hoc:
treq run ./requests/user.http --plugin @t-req/plugin-assertAssertion Syntax
# @assert status == 200
# @assert header Content-Type contains application/json
# @assert body contains "ok"
# @assert jsonpath $.token exists
GET https://api.example.com/healthSupported targets:
| Target | Operators | Example |
|---|---|---|
| status | == != > >= < <= | # @assert status == 200 |
| header <name> | exists == != contains | # @assert header X-Trace-Id exists |
| body | contains not-contains | # @assert body not-contains "error" |
| jsonpath <expr> | exists == != | # @assert jsonpath $.count == 2 |
Behavior
- Assertions run in
response.after. - One summary report is emitted per request with:
kind: "assert"passed: booleantotal,failedchecks[]details
- Any failed assertion sets
passed: false, andtreq runexits with code1. - Malformed assertions also fail the run (fail-fast behavior).
Validate Integration
treq validate uses this plugin's validate hook to surface assertion issues early:
assert.syntaxassert.operatorassert.targetassert.missing-valueassert.invalid-jsonpathassert.position
Example:
treq validate ./requestsLicense
MIT
