npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

barrt

v1.7.0

Published

A Bash Rspec-like Regression Test Framework

Downloads

31

Readme

barrt - A Bash Rspec-like Regression Test Framework

Usage

barrt was written to allow easy testing of commandline programs. The initial use case was making it possible to choose "Copy as cURL" from a request in Google Chrome, drop the result into a test case, edit the URL slightly, and begin checking the headers and response body.

One of the design goals is to provide helpful error messages when tests fail. The framework may be extended with modules that create custom "expectations" (which are functions like expect that describe the left side of a comparison) that make sense when coupled with existing assertions like to_equal.

barrt and its plugins are available as NPM modules. They don't use any Javascript. But having support for versioning and ease of installing releases is helpful even so.

An effort has been made to provide compatible versions of grep and sed as functions that support extended (Perl or PCRE-like) regular expression syntax which work on both Linux and OS X.

Plugins

Examples

Simple test case

In a new file called test/number-five.sh (make sure to run chmod +x on it):

#!/bin/bash

. $(dirname $0)/../setup.sh

describe "The number 5"

num=5

it "is greater than 0"

expect $num; to_be_greater_than 0

Test case with chained assertions

it "is a number less than 7"

expect $num; to_be_numeric; to_be_less_than 7

Test case using the barrt-curl module

In a new file called test/example-request.sh (make sure to run chmod +x on it):

#!/bin/bash

. $(dirname $0)/../setup.sh

describe "Requests to example.com"

record_curl http://example.com

it "returns a 200 response with type text/html"

expect_response_code; to_equal 200
expect_header Content-Type; to_equal text/html

Output

$ ./runner.sh
* Requests to example.com
  - it returns a 200 response with type text/html
* The number 5
  - it is greater than 0
  - it is a number less than 7

Test Summary:
  - 2 scenario(s) passed
  - 0 scenario(s) skipped
  - 0 scenario(s) failed

Installation

Install the module from npm:

npm i --save barrt

Install any plugins you may want.

Edit the setup.sh file in your test suite to include the following:

#!/bin/bash

modules=$(dirname "$BASH_SOURCE")/node_modules

. "$modules"/barrt/setup.sh
. "$modules"/barrt-curl/setup.sh

# other plugins or setup tasks...

Create a runner.sh file in your test suite with these contents:

#!/bin/bash

modules=$(dirname "$BASH_SOURCE")/node_modules

exec "$modules"/barrt/runner.sh

Write some tests and place them in the test/ directory.

Run tests

Run all tests:

./runner.sh

Run a single test:

./test/different_origin.sh

Skipping a test:

chmod -x ./test/skip_this_one.sh

API

The following are provided as bash functions:

Core

describe $scenario_description

it $test_case_description

Expectations

expect $value_to_be_compared

Assertions

to_be_empty

to_not_be_empty

to_equal $another_value

to_be_numeric

to_be_greater_than $another_number

to_be_greater_than_or_equal_to $another_number

to_be_less_than $another_number

to_be_less_than_or_equal_to $another_number

to_be_between $range_1 $range_2

to_contain $substring

to_match $pattern

to_be_consistent

Compatibility

grep $grep_arguments

sed $sed_arguments

Utility

echo_quoted $arguments_to_quote...

in_n_seconds $seconds $commands_to_run...

print_json_array $arguments_of_array...

first_line

last_line

remove_last_line

count_lines

fail $failure_reason

soft_fail $failure_reason

is_between $num $start_range $end_range

is_numeric $possible_number

Defining new assertions

define_side_a $value_to_be_compared

define_side_a_text $description_of_value_to_be_compared

define_addl_text $additional_explanation_if_test_case_fails

get_side_a, get_side_a_text, get_addl_text

License

MIT