Giter Club home page Giter Club logo

alola's Introduction

pipe alola pipe pipe alola pipe

alola

npm version: alola zero dependencies code style: prettier

curl -i <url> | alola | fx .
  • glue beetween curl -i and cli JSON parser tool of your choice like jq or fx
  • it was built with unix-philosophy in the mind
  • runs assertions on JSON
  • no bail-out: it runs every assertions
  • CI-friendly: process exit code is always the number of failed testcases

usage

# npm install -g alola
# or
# npx alola (recommended)

curl -i <url> | npx alola [assertions]

examples

curl -i https://ewqfsixnkkhp3syjy65heuhkou0dogwr.lambda-url.eu-central-1.on.aws/ \
  | npx alola

# output

{
  "redirects": [],
  "protocol": "HTTP/1.1",
  "status": 200,
  "statusText": "OK",
  "headers": {
    "date": "Sun, 10 Jul 2022 08:30:19 GMT",
    "content-type": "application/json",
    "content-length": "68",
    "connection": "keep-alive",
    "x-amzn-requestid": "6f38be71-8c2a-4106-8bd5-6a2a0726d831",
    "x-amzn-trace-id": "root=1-62ca8e1b-3fa47e01777132441c03e3de;sampled=0"
  },
  "body": {
    "date": 1657441819664,
    "foobar": 42,
    "author": "balazs4",
    "name": "alola"
  }
}
# follows redirections
curl -i https://ewqfsixnkkhp3syjy65heuhkou0dogwr.lambda-url.eu-central-1.on.aws/ --follow \
  | npx alola

# assertion
curl -i https://ewqfsixnkkhp3syjy65heuhkou0dogwr.lambda-url.eu-central-1.on.aws/ \
  | npx alola \
   'status should be 200' \
   'headers.content-type should match json'\
   'body.author should be balazs4'

# silent assertion
curl -i https://ewqfsixnkkhp3syjy65heuhkou0dogwr.lambda-url.eu-central-1.on.aws/ \
  | npx alola 'status should be 200' 2>/dev/null

# assertion only
curl -i https://ewqfsixnkkhp3syjy65heuhkou0dogwr.lambda-url.eu-central-1.on.aws/ \
  | npx alola 'status should be 200' 1>/dev/null

# json assertion output
curl -i https://ewqfsixnkkhp3syjy65heuhkou0dogwr.lambda-url.eu-central-1.on.aws/ \
  | ALOLA_REPORT=json npx alola 'status should be 200' 1>/dev/null

# middleware
curl -i https://ewqfsixnkkhp3syjy65heuhkou0dogwr.lambda-url.eu-central-1.on.aws/ \
  | npx alola 'status should be 200' 'headers.content-type should match json' \
  | fx 'res => res.body.name + " by " + res.body.author'

assertions

<key> should be <expected-value>
<key> should not be <expected-value>
<key> should match <expected-regex>
<key> should not match <expected-regex>

more details

configuration

You can configure alola with the following environment variables:

Environment variable Description Default value Possible values
ALOLA_REPORT result reporter text text,json
ALOLA_CUSTOM any resolvable path to the custom assertions ./.alola.js

author

balazs4 - https://twitter.com/balazs4

alola's People

Contributors

balazs4 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

alola's Issues

setup CD with github actions

  • pull_request to master (workflow: pull-request.yml)

    • npm ci
    • npm run test
    • release-it --dry-run
  • on master release-publish.yml

    • npm ci
    • npm run test
    • release-it

open points

  • custom assertion doc
  • logo
  • screenshot
  • license

property-based-testing

alola curl -H 'auth: xxxx' http://fake.api/create/<name> -XPOST -- \
  'name should get string' \
  'status should be 201'

/cc @chubin

baretest pr

const rgb = require('barecolor')

module.exports = function(headline) {
  const suite = [],
    before = [],
    after = [],
    only = []

  function self(name, fn) {
    suite.push({ name: name, fn: fn })
  }

  self.only = function(name, fn) {
    only.push({ name: name, fn: fn })
  }

  self.before = function(fn) { before.push(fn) }
  self.after = function(fn) { after.push(fn)  }
  self.skip = function(fn) {}

  // for testing Baretest
  self.run = async function() {
    const tests = only[0] ? only : suite

    rgb.cyan(headline + ' ')
    const failed = [];

    for (const test of tests) {
      try {
        for (const fn of before) await fn()
        await test.fn()
        rgb.gray('• ')

      } catch(e) {
        for (const fn of after) await fn()
        rgb.red('• ')
        failed.push(()=>{
           rgb.red(`\n\n! ${test.name} \n\n`)
           prettyError(e)
         });
        continue
      }
    }

    for (const fn of after) await fn()

    if (failed.length === 0){
      rgb.greenln(`✓ ${ tests.length }`)
      console.info('\n')
      return true
    }

    failed.forEach(fn => fn());
    rgb.redln(`x ${ failed.length } of ${tests.length}`)
    return false;
  }

  return self

}


function prettyError(e) {
  const msg = e.stack
  if (!msg) return rgb.yellow(e)

  const i = msg.indexOf('\n')
  rgb.yellowln(msg.slice(0, i))
  rgb.gray(msg.slice(i))
  console.info('\n')
}

broken assertions

image

Steps to reproduce:

docker run -it node:alpine sh

# inside docker container
apk add --update git curl

curl -Lis http://krautipsum.com/api/noun | npx -q https://github.com/balazs4/alola#master 'status should be 200'

[backlog]

  • NO_COLOR vs tty
  • Docu rewrite
  • Logo (re)design

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.