Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@t-req/plugin-assert

Inline assertions for t-req using # @assert ... directives in .http files.

npm version License: MIT

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-assert

Setup

Add to treq.jsonc:

{
  "plugins": ["@t-req/plugin-assert"]
}

Or load ad-hoc:

treq run ./requests/user.http --plugin @t-req/plugin-assert

Assertion Syntax

# @assert status == 200
# @assert header Content-Type contains application/json
# @assert body contains "ok"
# @assert jsonpath $.token exists
GET https://api.example.com/health

Supported 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: boolean
    • total, failed
    • checks[] details
  • Any failed assertion sets passed: false, and treq run exits with code 1.
  • 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.syntax
  • assert.operator
  • assert.target
  • assert.missing-value
  • assert.invalid-jsonpath
  • assert.position

Example:

treq validate ./requests

License

MIT