peter

    2.2.0 • Public • Published

    Peter Test Framework

    Peter is designed to be an extremely lightweight and extensible test framework, with a few test drivers included to accomodate most modes of JavaScript testing.

    At it's core, Peter was designed with the following intention in mind:

    Testing should be as simple as running the file by itself.

    Installation

    npm i peter

    Usage

    # Look in the tests/ directory for test files
    npx peter tests/

    Updates

    Version Date Description
    2.2.0 June 2021 Add JUnit XML output

    Drivers

    A peter driver is a module which is responsible for handling files with a specific file extension. The following drivers are included with Peter by default:

    Driver Name File Extension Description
    TAP .tap This driver will run JavaScript files with the .tap extension, and expect the standard output of the file to be in TAP format. We recommend using zora as a testing library that outputs TAP.
    Simple .simple This driver will execute JavaScript files with the .simple extension, and simply assert that no errors were thrown during execution. Top-level await is supported.
    Bash .bash This driver will execute Bash scripts as tests, and assert that the exit code of the script is 0.

    Note that files with the .js extension are ignored by Peter so that utility scripts can be written alongside the test scripts.

    Testing Peter

    To run the example tests (Peter's self tests), run:

    ./peter tests
    

    Debugging Simple Tests

    If a .simple test fails, you can debug it using

    ./simple <filename>
    

    This file will use niim by default, but --debugger=<debugger> can be used to specify a debugger. A debugger; call is also automatically added to the start of the .simple file being debugged.

    About Peter

    Peter is a Pragmatic, Extensible Test Environment / Runner. It was built based on the observation that developers tend to write a lot of little tests during the course of development, but these little tests tend not to get captured into unit tests. The idea with Peter, in particular the simple tests, is to make it possible for developers to simply take these tests -- often one or two lines of code -- and move them into their peter directory, where they become simple pass/fail unit tests.

    Architecture

    ./peter is a test runner, which executes tests in random order and in parallel by traversing directories. The test runner discovers the type of test based on the test's file extension. This file extension is then used to select the appropriate test driver, and the test is run. Certain extensions, such as .js, are reserved for library code which could be used by multiple tests. If the test filename begins with the mathematical not symbol, ¬, the sense of the test is inverted (i.e. a pass becomes a fail and vice-versa).

    Simple

    Simple tests run in NodeJS. If the file throws an uncaught exception or exits with a non-zero exit code, it fails; otherwise it passes. The Simple test driver plumbs in top-level await on Node to make async/await tests easy to run. Individual tests which run directly in NodeJS will run as .simple tests with no changes. Tests written specifically for this test driver can be run individually via /path/to/simple /path/to/test.

    Peter

    A special shout-out to Peter DeMartini, who let us have the Peter npm name. Peter is awesome - the end!

    Team

    Peter was written and is maintained by the team at Kings Distributed Systems. We use it internally to test the Distributed Computer.

    • Wes Garland
    • Ryan Rossitter
    • Ryan Saweczko
    • Andrew Fryer
    • James McDonald
    • Parker Rowe

    Install

    npm i peter

    DownloadsWeekly Downloads

    222

    Version

    2.2.0

    License

    MIT

    Unpacked Size

    39.9 kB

    Total Files

    20

    Last publish

    Collaborators

    • wesgarland