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

gt

v0.10.0

Published

JavaScript native QUnit runner with code coverage and multiple extensions

Downloads

598

Readme

gt

JavaScript native QUnit runner with code coverage and multiple extensions

NPM

Build status Coverage Status dependencies devdependencies

Install and run

gt requires nodejs and a few modules to run. Assuming you wrote a few qunit tests in tests.js:

sudo npm install -g gt
gt tests.js

some of the options (-h for all):
  -l <debug level> 0 = debug, 1 = default, 2 = warnings, 3 = errors
  -r <report level> 0 = all (default), 1 = failed tests only

Goals

  1. Make sure QUnit tests work with istanbul JS coverage tool
  2. Experiment with JS unit testing by writing a framework from scratch.

Example

A simple example is in examples subfolder

Unit tests follow QUnit approach:

gt.module("Basic tests");

gt.test("get N '='", function () {
	gt.ok(typeof getLines === "function", "getLines is a function");
	gt.equal(getLines(0), "", "0 character");
	gt.equal(getLines(1), "=", "1 character");
});

Creates unit test report (stdout only) and JS code coverage (stdout plus Lines of Code + HTML in folder cover)

gt ./examples/basic/tests ./examples/basic/exceptionTests

Sample unit test output image

Sample JS coverage output image

CoffeeScript support

You can write your unit tests using coffeescript, which allows very concise code. So far, the code coverage does not include the unit test files themselves, they will be omitted from the coverage report. See examples/coffee folder.

Running in browser

See example examples/browser

BDD support

gt provides minimal BDD support and can run Mocha/Jasmine specs that have describe and it calls. See spec example. You can run it using gt --bdd spec.js command.

API

module

Creates new suite of tests with given name

gt.module('math tests');

You can specify additional functions to run before / after each unit tests. You can also specify a function to run once before any tests, and after all tests.

gt.module('server tests', {
    setupOnce: function () {
        // setup server
    },
    setup: function () {
        // clear data before each unit test
    },
    teardown: function () {
        // clean up after each unit test
    },
    teardownOnce: function () {
        // stop server
    }
});

See module tests for more information and examples.

A very convenient feature: each method can return a promise object to tell the test engine when it is done. See example

exec

Spawns new proces, waits for it to finish, then checks the exit code. Automatically restarts the test queue

Checking just the exit code

gt.async('run Nodejs program', function () {
  gt.exec('node', ['index.js', 'arg1', 'arg2'], 0,
    'expect "node index.js arg1 arg2" to exit with code 0');
});

Checking the exit code and the output

gt.async('run a program', function () {
  gt.exec('node', ['index.js', 'arg1', 'arg2'], 0,
    function (stdout, stderr) {
      if (/error/.test(stdout)) {
        throw new Error('Errors in output ' + stdout);
      }
    });
});

Full exec unit test

shortcuts:

gt.exec(cmd, [...], 'msg');
// same as
gt.exec(cmd, [...], 0, 'msg');

gt.exec(cmd, 'msg');
// same as
gt.exec(cmd, [], 0, msg);

gt.exec(cmd);
// same as
gt.exec(cmd, [], 0);

gt.equiv

Performs deep equality comparison between two objects.

command line options

--no-cover part-of-path

gt excludes certain common paths from coverage, speeding up the test runs: node_modules, bower_components, etc. You can add paths to this list, for example to exclude all files loaded from vendor folders:

gt --no-cover vendor src/*.js tests/*.js

The option is used as case insensitive regular expression.

Small print

Author: Gleb Bahmutov © 2014

License: MIT - do anything with the code, but don't blame me if it does not work.

Spread the word: tweet, star on github, etc.

Support: if you find any problems with this module, email / tweet / open issue on Github.

Bitdeli Badge