All Projects → johnnynotsolucky → upssert

johnnynotsolucky / upssert

Licence: Apache-2.0 license
Simple REST API assertion framework

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to upssert

assert.sh
❗ Assertion lib for shell script users
Stars: ✭ 105 (+707.69%)
Mutual labels:  assertions
fluentcheck
Fluent assertions for Python
Stars: ✭ 79 (+507.69%)
Mutual labels:  assertions
codeceptjs-bdd
Javascript BDD UI Automation Framework. Exclusive LWC Shadow DOM Support. Playwright, Webdriver.io, Appium, Saucelabs.
Stars: ✭ 35 (+169.23%)
Mutual labels:  assertions
picolisp-unit
Unit Testing framework for PicoLisp
Stars: ✭ 22 (+69.23%)
Mutual labels:  assertions
karate
Test Automation Made Simple
Stars: ✭ 6,384 (+49007.69%)
Mutual labels:  assertions
crystal-clear
Design by Contract for Crystal
Stars: ✭ 45 (+246.15%)
Mutual labels:  assertions
jsonassert
A Go test assertion library for verifying that two representations of JSON are semantically equal
Stars: ✭ 102 (+684.62%)
Mutual labels:  assertions
tester
Lightweight test utilities to use with Go's testing package
Stars: ✭ 43 (+230.77%)
Mutual labels:  assertions
Assertion
The power of Respect\Validation into an assertion library.
Stars: ✭ 23 (+76.92%)
Mutual labels:  assertions
phpsemver
Check if your changes are a major change, minor change or just a patch.
Stars: ✭ 28 (+115.38%)
Mutual labels:  assertions
apid
User focused API testing
Stars: ✭ 90 (+592.31%)
Mutual labels:  assertions
vim-UT
Unit Testing plugin for Vim
Stars: ✭ 18 (+38.46%)
Mutual labels:  assertions
asserts
The most over-engineered and overpowered C++ assertion library.
Stars: ✭ 217 (+1569.23%)
Mutual labels:  assertions
jasmine2-custom-message
custom failure message on any jasmine v2 assertion
Stars: ✭ 27 (+107.69%)
Mutual labels:  assertions
cxx-tap
Test Anything Protocol (TAP) Producer for C++
Stars: ✭ 22 (+69.23%)
Mutual labels:  assertions
kiwi
Fluent assertions for Kotlin
Stars: ✭ 17 (+30.77%)
Mutual labels:  assertions
concise
✅ Concise is test framework for using plain English and minimal code, built on PHPUnit.
Stars: ✭ 47 (+261.54%)
Mutual labels:  assertions
beJS
Simple, light-weight assertions framework for javascript
Stars: ✭ 12 (-7.69%)
Mutual labels:  assertions
karma-expect
Expect.js adapter for Karma test runner
Stars: ✭ 12 (-7.69%)
Mutual labels:  assertions
rust-claim
Assertion macros toolkit for Rust
Stars: ✭ 53 (+307.69%)
Mutual labels:  assertions



Upssert REST API assertion framework



Upssert

Build Status Coverage Status Dependencies

Upssert is an extremely simple REST API assertion framework which makes it easier to monitor and test your API. Without writing any code, test your API against its responsiveness and any combination of parameters.

Principles

  • Zero configuration setup
  • Human-readable test suite definitions
  • Repeatable across environments
  • Assert anything
  • Stay easy

Installation

npm install upssert

Usage

$ upssert --url http://httpbin.org/get

Executing 1 test suites (2 assertions)…

Ping
  ✓ http://httpbin.org/get

1 passing (204.000ms)

By default Upssert will assert that a URL's response code is within the 200 or 300 range, i.e.

$ node ./dist/bin/index.js --url https://httpbin.org/status/404

Executing 1 test suites (2 assertions)…

Ping
  ✖ https://httpbin.org/status/404

1) https://httpbin.org/status/404
Error: expected 404 to be below 400 (statusCode)

0 passing (418.000ms)
1 failing

Assertions

Under the hood, Upssert uses Chai Assertion Library's assert API for its assertions. All the assertions exposed by Chai are available in Upssert with the exception of:

  • assert(expression, message)
  • throws
  • doesNotThrow
  • changes
  • doesNotChange
  • increases
  • doesNotIncrease
  • decreases
  • doesNotDecrease

The following will be supported in the future

  • operater
  • closeTo
  • approximately

CLI

Options

  • url Supply Upssert with a URL to run a ping assertion against
  • reporter Tell Upssert which reporter to use. Options are tap and console. Defaults to console

If neither a glob pattern or --url flag is supplied, Upssert will look in test/api/**/*.json for test suites. Alternatively, Upssert can be configured within package.json with the following options:

{
  ...
  "upssert": {
    "globOpts": {},
    "testDir": "path/to/your/tests/**/*.json"
  }
}

globOpts can be configured as defined in https://github.com/isaacs/node-glob

Running Test Suites

Test suites are defined as JSON files

$ cat << EOF > ping.json
{
  "name": "Ping httpbin.org",
  "tests": [
    {
      "name": "Successfully pings httpbin.org",
      "request": {
        "url": "https://httpbin.org",
        "method": "GET"
      }
    }
  ]
}
EOF

$ upssert ping.json

A more complex example

$ cat << EOF > workflow.json
{
  "name": "Test against httpbin",
  "tests": [
    {
      "name": "/get",
      "request": {
        "url": "https://httpbin.org/get?foo=bar",
        "method": "GET"
      },
      "response": {
        "content-type": "application/json",
        "status-code": {
          "equal": 200
        },
        "timing.dns-resolution": {
          "is-below": 100
        },
        "timing.total": {
          "is-below": 500
        },
        "body.args.foo": "bar"
      }
    }, {
      "name": "/post formdata",
      "requires": ["test1"],
      "request": {
        "url": "https://httpbin.org/post",
        "method": "POST",
        "form": [
          {
            "key": "out",
            "value": "{{test1.body.args.foo}}"
          }
        ]
      },
      "response": {
        "content-type": "application/json",
        "status-code": {
          "equal": 200
        },
        "timing.dns-resolution": {
          "is-below": 100
        },
        "timing.total": {
          "is-below": 500
        },
        "body.form.out": "bar"
      }
    }, {
      "name": "/post raw data",
      "requires": ["test1", "test2"],
      "request": {
        "url": "https://httpbin.org/post",
        "method": "POST",
        "headers": {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        "data": "test1-data={{test1.body.args.foo}}&test2-data={{test2.body.form.out}}"
      },
      "response": {
        "content-type": "application/json",
        "status-code": {
          "equal": 200
        },
        "timing.dns-resolution": {
          "is-below": 100
        },
        "timing.total": {
          "is-below": 500
        },
        "body.form[test1-data]": "bar",
        "body.form[test2-data]": "bar"
      }
    }
  ]
}
EOF

$ upssert workflow.json

Programmatically

import Upssert from 'upssert';
const ping = {
  name: 'Ping httpbin.org',
  tests: [
    {
      name: 'Successfully pings httpbin.org',
      request: {
        url: 'https://httpbin.org',
        method: 'GET',
      },
    },
  ],
}

const upssert = new Upssert(ping);
upssert.execute();

Reporters

Currently, there are only two reporters available

ConsoleReporter (default)

Similar to Mocha Spec reporter.

TapReporter

Outputs test reports with the TAP specification

import Upssert, { TapReporter } from 'upssert';
const reporter = new TapReporter();
const upssert = new Upssert('https://httpbin.org/get', reporter);
upssert.execute();

1..1
ok 1 https://httpbin.org/get
# tests 1
# pass 1
# fail 0
# assertions 2

Lifecycle

Upssert uses the EventEmitter to emit events at runtime. The bundled reporters report on events as they occur instead of collecting all output first and then writing out the formatted report.

The following is an exhaustive list of events which are emitted

  • suite.assertion.count (count) emits count assertions for each test
  • suite.test.count (count) emits count tests for each suite
  • suite.count (count) emits count for each suite, which is usually 1
  • start emitted when the test runner starts
  • suite.start emitted when a suite starts
  • suite.fail emitted if a suite fails and cannot continue. Generally for invalid test suite configuration.
  • suite.test.start emitted when a test starts
  • suite.test.pass emitted if none of the tests assertions fail
  • suite.test.fail emitted if any of the tests assertions fail
  • suite.test.end emitted when a test ends
  • fail emitted for every failure (suite.test.fail, suite.fail). Useful for marking a test run as failed.
  • suite.end emitted when a suite ends
  • end emitted when the test runner stops

Custom Reporters

User-defined reporters can be passed to Upssert through the constructor.

A custom implementation only requires that it expose a setEventEmitter(emitter) method which Upssert can pass an event emitter into.

class CustomReporter {
  setEventEmitter(emitter){
    emitter.on('start', () => console.log('Started'));
    emitter.on('end', () => console.log('Ended'));
  }
}

const upssert = new Upssert('https://httpbin.org/get', new CustomReporter());
upssert.execute();

Inspired by the simplicity of Ansible

License

Apache 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].