Test runner based on Tape and Browserify

Related tags

Testing prova
Overview

prova

Node & Browser Test runner based on Tape and Browserify.

Screencasts: node.gif, browser.gif, both.gif, headless browser

Slides: slides.com/azer/prova

Features and screenshots:

Install

$ npm install -g azer/prova

Usage

Example test:

var test = require('prova')

test('timing test', function (t) {
  t.plan(2)

  t.equal(typeof Date.now, 'function')
  var start = Date.now()

  setTimeout(function () {
    t.equal(Date.now() - start, 100)
  }, 100)
})

In Node, it will output:

$ node test.js
Passed 1 test.

Or, in case it fails:

In Browser

To run the tests in a web browser, just pass -b parameter:

$ node test.js -b
Visit localhost:7559 with a browser to start running the tests.

Then visit localhost:7559 in your web browser:

In case it fails, it'll show:

The web app uses watchify to monitor file changes. So, you won't have to reload the page when you modify a source code.

Prova runs the tests inside of an iframe. In case you test some UI stuff, you can open the iframe by clicking the < button on the right:

Multiple Tests

Prova comes with a command-line script when you install it globally;

$ npm install -g prova

And it allows you running multiple tests on both Node and browser;

$ prova test/foo.js test/bar.js
$ prova test/**/*.js -b

Launching Browsers and Headless Testing

List the detected browsers;

$ prova -l
Available Browsers: safari v7.0.2, chrome v34.0.1847.116, phantom v1.9.7

And launch after publishing the tests:

$ prova -b -l safari

If your system has Xvfb, you can pass -e parameter to open the browser headlessly:

$ prova -b -l chrome -e

Or you can just run the tests on PhantomJS:

$ prova -b -l phantom

If you get no matches for errors and you think that your system has that browser, try removing browser-launcher's config:

$ rm /Users/azer/.config/browser-launcher/config.json

Browserify Transforms

Prova automatically applies bunch of transforms by looking at the file extension. If you'd like to use a transform that doesn't exist in Prova by default, you can choose it with a parameter;

$ node test -b -t coffeeify

Multiple transforms can be specified using comma;

$ node test -b -t coffeeify,brfs,foo,bar

Browserify Plugins

Pass Browserify plugins passing -u or --plugin parameter;

$ node test -b --plugin foo

Use comma to separate multiple plugins;

$ node test -b --plugin foo,bar

Custom Frame Documents

When you're running the tests on the browser, Prova has an empty HTML template that loads and runs the JavaScript tests. You can customize this HTML file with -f or --frame parameter:

$ node test -b -f test.html

Click the arrow button on right middle to keep the frame open. You'll be seeing the HTML document and test results in the same screen.

Manually Restarting Browser Tests

Prova watches for changes and automatically restarts the browser tests (inside in an iframe) but in case you need, there is an endpoint for restarting all the tests by hitting an endpoint;

$ curl localhost:7559/restart

Loading Assets

You may need to load your images, web workers etc. for testing. Prova allows you to load assets from your current directory via the /assets/in endpoint. Let's say you'd like to load a file called "foobar.png":

$ curl http://localhost:7559/assets/in/foobar.png

Should work for you.

HTTP Proxy

HTTP proxying is pretty useful to by-pass cross-domain issues (CORS) on the browser. You can easily point a URL to another host using -y / --http-proxy parameters:

$ node test -b -y "/my-api=http://localhost:8080"

Assuming that you'll be running your tests on :7559, any requests to /my-api will be streamed through localhost:8080 in the above example.

Command-line

      USAGE

          prova [filenames] [options]

      OPTIONS

          -g     --grep         Run tests matching with given pattern

          -b     --browser       Publishes the tests on 0.0.0.0:7559
          -o     --port          Publish the tests on given port number.
          -d     --hostname      Publish the tests on given hostname.
          -l     --launch        List available browsers to launch or launch specified browser.
          -e     --headless      Launch the browser headlessly. (Requires xvfb)
          -r     --proxy         Launch the browser with specified proxy configuration.
          -q     --quit          Shut down the browser server once all the tests are done.
          -f     --frame         Specify a custom document to run tests on browser. e.g node test -b -f custom.html
          -x     --exec          Execute given commmand before running the tests.
          -y     --http-proxy    Proxy requests matching with given pattern to a target. e.g -y "/images=localhost:8080"

          -t     --transform     Use given Browserify transforms. e.g node test -b -t coffeeify,brfs
          -u     --plugin        Use given Browserify plugins. e.g node test -b -u foo,bar

          -s     --progress      Show a progress bar. Useful when tests are running slow.

          -p     --tap           Output original Tap output without modifying anything.

          -C     --no-console    Disable showing browser console messages on command-line.

          -v     --version       Show version and exit
          -h     --help          Show help and exit
                 --examples      Show example commands

Example Commands

    EXAMPLES

        1. Run the tests on NodeJS.

           $ node test.js
           $ node test
           $ prova test/index.js
           $ prova

           All the above example commands will work same way. Prova assumes the filename of your test is either `test.js` or `test/index.js`

       2. Publish the tests on localhost:7559, so you can run the tests on a web browser.

          $ node test.js -b
          $ prova test -b
          $ prova -b

       3. Publish the tests on given host and port.

          $ node test.js -o 8080 -d foobar.net
          $ prova test.js -o 8080 -d foobar.net

       4. Publish the tests and launch a browser to automatically run the tests.

          $ node test.js -b -l chrome
          $ prova test.js -b -l chrome

       5. List the browsers that can be launched automatically.

          $ prova -l
          $ node test.js -l

       6. Run the tests with PhantomJS.

          $ node test.js -b -l phantom
          $ prova test.js -b -l phantom

       7. Run only specified tests with PhantomJS.

          $ node test.js -b -l phantom -g pattern
          $ prova test.js -b -l phantom -g pattern

       8. Launch Chrome headlessly using xvfb:

          $ node test -b -l chrome -e
          $ prova test -b -l chrome -e
Comments
  • When an error happens in a test, it's hard to track down

    When an error happens in a test, it's hard to track down

    Right now I'm seeing this error when running my test suite. I suspect one of my test files is throwing an error, but Prova doesn't show me any useful information. What can we do about this?

    https://cloudup.com/cjJhMEU817G

    opened by techwraith 38
  • 0.16.0 fails to browserify

    0.16.0 fails to browserify

    Looks like there's a missing dep?

    prova:browser Failed to browserify the source code. We're probably missing a module required. The error was: +15s
    
        Cannot find module 'sha.js' from '/…/node_modules/prova/node_modules/browserify/node_modules/crypto-browserify' /…/node_modules/prova/node_modules/browserify/node_modules/resolve/lib/async.js
                            v
        49.         else if (core[x]) return cb(null, x);
        50.         else cb(new Error("Cannot find module '" + x + "' from '" + y + "'"))
        51.     });
                            ^
        Error: Cannot find module 'sha.js' from '/…/node_modules/prova/node_modules/browserify/node_modules/crypto-browserify'
    
    opened by joeybaker 19
  • Uncaught DataCloneError: Failed to execute 'postMessage' on 'Window': An object could not be cloned.

    Uncaught DataCloneError: Failed to execute 'postMessage' on 'Window': An object could not be cloned.

    I've not been able to isolate this to a reproducible scenario, but it seems to happen when async tests fail to end(). I also seem to encounter some false plan != count errors, not sure if that is related.

    I will continue trying to isolate, but I figured I would report in case you have ideas on what could be the issue. Screen grab of console: http://cl.ly/image/2a392W0I3c3M

    opened by bclinkinbeard 17
  • Browser is hanging when live reload runs

    Browser is hanging when live reload runs

    run.js is never returning. The read.bundle({ debug: true }).pipe(write); call in lib/browser.js appears to be failing, but I haven't figured out why. Any ideas?

    I am running into this on a fresh install of prova.

    opened by bclinkinbeard 13
  • Add provify transform

    Add provify transform

    This transform will replace all instances of "tap" or "tape" require statements in a script with require('prova'). This closes #2.

    opened by MylesBorins 9
  • Update Dependencies

    Update Dependencies

    The first commit updates all out of date dependencies except for Browserify and Watchify which both require a rewrite in order to support the latest versions.

    The second commit updates both browserify and watchify.

    Both have changed quite a bit since the versions tracked in the current iteration of Prova. This required a bit of an overhaul to the current way that prova interfaces with the two. Specifically it was neccessary to modify lib/browser.js and lib/browserify-transform.js to support the latest api.

    opened by MylesBorins 4
  • http server does not serve test-level asset files

    http server does not serve test-level asset files

    This would be nice to have in order to

    • test stuff like ajax calls, image loading etc.
    • misuse prova as a rapid prototyping server (like beefy). I have been doing that :)

    (pull request is coming up)

    opened by regular 4
  • it should output in tap format when run via node

    it should output in tap format when run via node

    One of the advantages of TAP is that it produces output in a simple, standard format that can be piped into other tools, e.g. faucet. It would be nice if prova-the-library preserved this property, and produced TAP-compliant output when run via node test.js. It's fine if prova-the-command, e.g. prova test.js produces a custom output format.

    opened by jfirebaugh 4
  • "undefined" error displayed in console when browserify bundle emits an error

    When browserify.bundle() emits an error, the error object seems to be improperly transformed for display in console output. It looks like prova is expecting error to be a string when it's actually an Error object. I am using prova with browserify 4.1.11.

    The console output reads like the following:

    prova:browser Failed to browserify the source code. We're probably missing a module required. The error was: +261ms
    
        undefined
    

    In my tests, the error itself is an Error object, and looks like this:

    {
       "message": "reserved word \"var\"",
       "line": 1,
       "column": 1,
       "annotated": "/Users/ahutchings/Projects/myproject/test/test-file.coffee:1\nvar TestClass, test;\n^\nParseError: reserved word \"var\""
    }
    
    opened by ahutchings 4
  • how to run the prova test suite?

    how to run the prova test suite?

    When I run:

    git clone https://github.com/azer/prova.git
    cd prova
    npm install
    npm test
    

    I get this output:

    > [email protected] test /Users/jchris/code/js/prova
    > node test.js
    
    
    module.js:340
        throw err;
              ^
    Error: Cannot find module '/Users/jchris/code/js/prova/test.js'
        at Function.Module._resolveFilename (module.js:338:15)
        at Function.Module._load (module.js:280:25)
        at Function.Module.runMain (module.js:497:10)
        at startup (node.js:119:16)
        at node.js:906:3
    npm ERR! Test failed.  See above for more details.
    npm ERR! not ok code 0
    

    When I run prova from inside my working directory, I get:

    
        assert object
        should be equal /Users/jchris/code/js/prova/test/index.js
                        v
            4.   assert.plan(4);
            5.   assert.equal(3.15, 3.14);
            6.   assert.ok(true);
                        ^
            Error: should be equal
                at Test.assert (/Users/jchris/code/js/prova/node_modules/tape/lib/test.js:188:54)
                at Test.bound [as _assert] (/Users/jchris/code/js/prova/node_modules/tape/lib/test.js:59:32)
                at Test.equal.Test.equals.Test.isEqual.Test.is.Test.strictEqual.Test.strictEquals (/Users/jchris/code/js/prova/node_modules/tape/lib/test.js:311:10)
                at Test.bound (/Users/jchris/code/js/prova/node_modules/tape/lib/test.js:59:32)
                at Test.<anonymous> (/Users/jchris/code/js/prova/test/index.js:5:10)
                at Test.bound [as _cb] (/Users/jchris/code/js/prova/node_modules/tape/lib/test.js:59:32)
                at Test.run (/Users/jchris/code/js/prova/node_modules/tape/lib/test.js:72:10)
                at Test.bound [as run] (/Users/jchris/code/js/prova/node_modules/tape/lib/test.js:59:32)
                at Object.next [as _onImmediate] (/Users/jchris/code/js/prova/node_modules/tape/lib/results.js:66:15)
                at processImmediate [as _immediateCallback] (timers.js:336:15)
    
    
            Expected: 3.14
            Actual:   3.15
    
    
    
    
        1 failed, 3 passed assertions.
    

    Which doesn't seem like it's running all the tests in test/

    And when I run prova -b I get a browser window with that same output (only the one failing test).

    Is this the expected behavior? I'd like to be using prova heavily on a project but without a test suite, I don't know where to start on fixing little bugs I find with it.

    Thanks for any pointers!

    opened by jchris 3
  • node/browser test runner

    node/browser test runner

    Hello, I have been happily using prova and loving it.

    How do you run multiple test files with prova ?

    It seems tape *.js will do it but I think prova would benefit in having a prova bin.

    What do you think?

    opened by vvo 3
  • upgrade package dependencies

    upgrade package dependencies

    I update package dependencies to latest and all 7 test passed.

    Is a warnnig on the command line:

    npm WARN [email protected] license should be a valid SPDX license expression
    

    that can be solved is you choose another, more specific, BSD license

    opened by bySabi 4
  • Report about throw exception in browser

    Report about throw exception in browser

    If we run test in browser and throw exception:

    var test = require('prova');
    
    test('smth', function(t) {
        throw new Error();
        t.end();
    });
    

    Test case does not end and error appears only in browser console, but not in command line.

    opened by Trufi 2
  • Add --browserify arg to proxy Browserify instantiation

    Add --browserify arg to proxy Browserify instantiation

    Enable instantiating Browserify from args.

    If --browserify command is passed, it will proxy instantiation of Browserify and ignore automatic prova extensions, transforms and plugins.

    This request constitutes a 'feature' version bump in package.json.

    README.md has also been updated to document the change.

    opened by JeremyJonas 0
  • Fix broken browser testing/launching

    Fix broken browser testing/launching

    Browserify currently breaks because files contains the cli ('/bin/prova') and then the files it should be browserify*ing. This fixes that

    Currently browserify will error immediately!

    See https://github.com/azer/prova/pull/62 first /cc @azer

    opened by megawac 0
  • grep doesn't work with nested tests

    grep doesn't work with nested tests

    test.js:

    var test = require('prova');
    
    test('a', function(t) {
        t.test('b', function(t) {
            t.equal(2 + 2, 4);
            t.end();
        });
    });
    

    I expect -g b to run this test, but:

    $ prova test.js 
    
        1 passed assertions.
    
    $ prova test.js -g b
    
        0 passed assertions.
    
    
    opened by jfirebaugh 3
Owner
Azer Koçulu
Chief Technology Officer at @hipeople (we're hiring!)
Azer Koçulu
Node.js test runner that lets you develop with confidence 🚀

AVA is a test runner for Node.js with a concise API, detailed error output, embrace of new language features and process isolation that lets you devel

AVA 20.2k Jan 1, 2023
tap-producing test harness for node and browsers

tape tap-producing test harness for node and browsers example var test = require('tape'); test('timing test', function (t) { t.plan(2); t.eq

James Halliday 5.7k Dec 18, 2022
Cypress Playback is a plugin and a set of commands that allows Cypress to automatically record responses to network requests made during a test run.

Cypress Playback ?? Automatically record and playback HTTP requests made in Cypress tests. Cypress Playback is a plugin and a set of commands that all

O’Reilly Media, Inc. 5 Dec 16, 2022
☕️ simple, flexible, fun javascript test framework for node.js & the browser

☕️ Simple, flexible, fun JavaScript test framework for Node.js & The Browser ☕️ Links Documentation Release Notes / History / Changes Code of Conduct

Mocha 21.8k Dec 30, 2022
E2E test framework for Angular apps

Protractor Protractor is an end-to-end test framework for Angular and AngularJS applications. Protractor is a Node.js program built on top of WebDrive

Angular 8.8k Jan 2, 2023
Politik Test

Politik Test Netlify Live Installation and Setup Instructions Clone down this repository. You will need node and npm installed globally on your machin

Yavuz Selim Şerifoğlu 6 Jun 13, 2021
blanket.js is a simple code coverage library for javascript. Designed to be easy to install and use, for both browser and nodejs.

Blanket.js A seamless JavaScript code coverage library. FYI: Please note that this repo is not actively maintained If you're looking for a more active

Alex Seville 1.4k Dec 16, 2022
Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

?? Playwright Documentation | API reference Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit w

Microsoft 46.3k Jan 9, 2023
JSCover is a JavaScript Code Coverage Tool that measures line, branch and function coverage

JSCover - A JavaScript code coverage measurement tool. JSCover is an easy-to-use JavaScript code coverage measuring tool. It is an enhanced version of

null 392 Nov 20, 2022
Simple JavaScript testing framework for browsers and node.js

A JavaScript Testing Framework Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any Ja

Jasmine 15.5k Jan 2, 2023
Adds promise support (rejects(), doesNotReject()) to tape by decorating it using tape-promise.

Tape With Promises Adds promise support (rejects(), doesNotReject()) to tape by decorating it using tape-promise. Install npm install --save-dev @smal

Small Technology Foundation 3 Mar 21, 2022
A low-feature, dependency-free and performant test runner inspired by Rust and Deno

minitest A low-feature, dependency-free and performant test runner inspired by Rust and Deno Simplicity: Use the mt test runner with the test function

Sondre Aasemoen 4 Nov 12, 2022
Tape Planner Promise

washi-tape Washi Tape makes a test planner from a Tape instance that makes it easy to plan and await parts of your tests. npm install washi-tape Usag

Mathias Buus 17 Sep 7, 2021
Spectacular Test Runner for JavaScript

Karma A simple tool that allows you to execute JavaScript code in multiple real browsers. The main purpose of Karma is to make your test-driven develo

Karma 11.8k Dec 27, 2022
Node.js test runner that lets you develop with confidence 🚀

AVA is a test runner for Node.js with a concise API, detailed error output, embrace of new language features and process isolation that lets you devel

AVA 20.2k Jan 1, 2023
A new zero-config test runner for the true minimalists

Why User-friendly - zero-config, no API to learn, simple conventions Extremely lighweight - only 40 lines of code and no dependencies Super fast - wit

null 680 Dec 20, 2022
A leetcode workspace template with test case runner for JavaScript/TypeScript programmers.

leetcode-typescript-workspace English | 简体中文 A vscode workspace template with test case runner script for JavaScript/TypeScript programmers using exte

null 10 Dec 13, 2022
A simple tap test runner that can be used by any javascript interpreter.

just-tap A simple tap test runner that can be used in any client/server javascript app. Installation npm install --save-dev just-tap Usage import cre

Mark Wylde 58 Nov 7, 2022
Isomorphic WHATWG Fetch API, for Node & Browserify

isomorphic-fetch Fetch for node and Browserify. Built on top of GitHub's WHATWG Fetch polyfill. Warnings This adds fetch as a global so that its API i

Matt Andrews 6.9k Jan 2, 2023