Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,55 @@
name: CI

on:
- push
pull_request:
types:
- opened
- reopened
- synchronize

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use node-16
uses: actions/setup-node@v3
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 16
node-version-file: ./.nvmrc
cache: npm

- run: npm ci
- run: npm run lint
- run: npm test

# - uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
- run: npm pack --dry-run
- run: npm run docs:build

versions:
name: node-${{ matrix.node }}
runs-on: ubuntu-latest
name: test node-${{ matrix.node }}
needs: test
runs-on: ubuntu-latest
strategy:
matrix:
node:
- 16
- 18
- 20
- 16.x
- 18.x
- 20.x
- 22.x
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- name: Use node-${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node }}
cache: npm

- run: npm ci
- run: npm test

ci-success:
needs: [test, versions]
runs-on: ubuntu-slim
if: always()
steps:
- name: Check all success or skipped
run: echo "$NEEDS_JSON" | jq -e 'map(select(.result != "success" and .result != "skipped")) | length == 0' || exit 1
env:
NEEDS_JSON: ${{ toJson(needs) }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.DS_Store
.vitepress/cache/
.nyc_output/
coverage/
node_modules/

*.DS_Store
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24.x
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"printWidth": 120,
"semi": true,
"proseWrap": "always",
"trailingComma": "all"
}
37 changes: 37 additions & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { defineConfig } from "vitepress";

const urls = {
github: "https://github.com/someimportantcompany/http-assert-plus",
npm: "https://npm.im/http-assert-plus",
};

// https://vitepress.dev/reference/site-config
export default defineConfig({
title: "http-assert-plus",
description: "More assertions with status codes",
lastUpdated: true,
srcExclude: ["./LICENSE"],
themeConfig: {
aside: false,
outline: false,
socialLinks: [
{ icon: "npm", link: urls.npm },
{ icon: "github", link: urls.github },
],
docFooter: {
prev: false,
next: false,
},
lastUpdated: {
formatOptions: {
dateStyle: "long",
timeStyle: "short",
timeZone: "UTC",
},
},
},
rewrites: {
"README.md": "index.md",
"(.*)/README.md": "(.*)/index.md",
},
});
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![NPM](https://badge.fury.io/js/http-assert-plus.svg)](https://npm.im/http-assert-plus)
[![CI](https://github.com/jdrydn/http-assert-plus/actions/workflows/ci.yml/badge.svg?branch=master&event=push)](https://github.com/jdrydn/http-assert-plus/actions/workflows/ci.yml)
[![Typescript](https://img.shields.io/badge/TS-TypeScript-%230074c1.svg)](https://www.typescriptlang.org)

<!-- [![Coverage](https://coveralls.io/repos/github/jdrydn/http-assert-plus/badge.svg)](https://coveralls.io/github/jdrydn/http-assert-plus) -->

More assertions with status codes.
Expand Down Expand Up @@ -36,36 +37,46 @@ $ npm install --save http-assert-plus

## API

This API matches the [built-in `assert` module](https://nodejs.org/dist/latest/docs/api/assert.html), and builds upon the success of [`http-assert`](https://github.com/jshttp/http-assert), with a few differences:
This API matches the [built-in `assert` module](https://nodejs.org/dist/latest/docs/api/assert.html), and builds upon
the success of [`http-assert`](https://github.com/jshttp/http-assert), with a few differences:

- Each function throws an instance of `Error` when the assertion fails.
- Zero dependencies.

#### `assert(value, [status], [message], [props])`

Tests if `value` is truthy, and throws an `Error` if falsey.

#### `assert.ok(value, [status], [message], [props])`

Alias for above, tests if `value` is truthy, and throws an `Error` if falsey.

#### `assert.fail([status], [message], [props])`

Always throws an `Error` with the provided status/message/props.

#### `assert.equal(a, b, [status], [message], [props])`

Tests shallow, coercive equality between `a` & `b` using `==`.

#### `assert.notEqual(a, b, [status], [message], [props])`

Tests shallow, coercive inequality between `a` & `b` using `!=`.

#### `assert.strictEqual(a, b, [status], [message], [props])`

Tests strict equality between `a` & `b` using `===`.

#### `assert.notStrictEqual(a, b, [status], [message], [props])`

Tests strict inequality between `a` & `b` using `!==`.

#### `assert.includes(a, b, [status], [message], [props])`

Tests whether `a` includes `b` - where `a` has a method call `includes`.

#### `assert.notIncludes(a, b, [status], [message], [props])`

Tests whether `a` does not include `b` - where `a` has a method `includes`.

### What about deep equality?
Expand All @@ -88,7 +99,10 @@ assert(deepEqual(a, b, { strict: true }), 400, 'These two are not entirely equal

## Browser supported?

Yes! Not all browsers support [`Error.captureStackTrace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#static_methods) so this library checks if it is present in the current environment - if it isn't available the only behaviour you'll likely want to change is to pre-construct `Error` arguments to preserve a proper stack trace, like so:
Yes! Not all browsers support
[`Error.captureStackTrace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#static_methods)
so this library checks if it is present in the current environment - if it isn't available the only behaviour you'll
likely want to change is to pre-construct `Error` arguments to preserve a proper stack trace, like so:

```js
const { origin } = window.location;
Expand All @@ -109,4 +123,5 @@ assert(origin.startsWith('https://'), 'Expected origin to start with https://');
// }
```

If you don't use a construct such as `new Error`, when reading stacktraces just ignore the first line as it'll always be the `assert` function :wink:
If you don't use a construct such as `new Error`, when reading stacktraces just ignore the first line as it'll always be
the `assert` function :wink:
Loading