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

gulp-test-tools

v0.6.2

Published

Test tools for gulp

Downloads

62

Readme

gulp-test-tools Build Status Build Status

Testing tools for gulp

NPM

Usage

gulpRunner

(example.js)
var runner = require('gulp-test-tools').gulpRunner;

runner({ verbose: true })
  .basedir(__dirname)
  .chdir('test')
  .gulp('build', '--gulpfile fixtures/gulpfile.js')
  .run(cb);
  
function cb(err, stdout, stderr) {
  ...
}
$ node example.js
---- command
cd /home/sttk/project;
cd test; 
node /usr/local/lib/node_modules/gulp-cli/bin/gulp.js build --gulpfile fixtures/gulpfile.js
---- error
null
---- stdout
[20:11:53] Working directory changed to ~/project/test/fixtures
[22:11:53] Using gulpfile ~/project/test/fixtures/gulpfile.js
[20:11:53] Starting 'build'...
[20:11:53] Finished 'build' after 5.11 ms

---- stderr

----.

eraseTime

(example.js)
var eraseTime = require('gulp-test-tools').eraseTime;

var gulpOutput = 
  "[20:11:53] Starting 'default'...\n" +
  "[20:11:53] Finished 'default' after 5.11 ms\n";

console.log(eraseTime(gulpOutput));
$ node example.js
Starting 'default'...
Finished 'default' after 5.11 ms

eraseLapse

(example.js)
var eraseLapse = require('gulp-test-tools').eraseLapse;

var gulpOutput = 
  "[20:11:53] Starting 'default'...\n" +
  "[20:11:53] Finished 'default' after 5.11 ms\n";

console.log(eraseLapse(gulpOutput));
$ node example.js
[20:11:53] Starting 'default'...
[20:11:53] Finished 'default' after ?

skipLines

(example.js)
var skipLines = require('gulp-test-tools').skipLines;

var gulpOutput = 
  "[20:11:53] Using gulpfile ~/project/gulpfile-2.js\n" +
  "[20:11:53] Starting 'default'...\n" +
  "[20:11:53] Finished 'default' after 5.11 ms\n";

console.log(skipLines(gulpOutput, 1));
$ node example.js
[20:11:53] Starting 'default'...
[20:11:53] Finished 'default' after 5.11 ms

headLines

(example.js)
var headLines = require('gulp-test-tools').headLines;

var gulpOutput = 
  "[20:11:53] Using gulpfile ~/project/gulpfile-2.js\n" +
  "[20:11:53] Starting 'default'...\n" +
  "Hello, world!\n" +
  "[20:11:53] Finished 'default' after 5.11 ms\n";

console.log(headLines(gulpOutput, 1, 2));
$ node example.js
Hello, world!

How to use gulpRunner with istanbul

Though gulpRunner executes a command on a child process, it can get coverage about the command with istanbul. The way to get coverage is as follows:

$ istanbul cover example.js

If there are multiple test scripts, you can get their total coverage by following way:

$ istanbul cover example.js example2.js --print none && istanbul report lcov text-summary

If you run test scripts in the directory ./test with istanbul + mocha, you should execute the following command:

$ istanbul cover _mocha --print none && istanbul report lcov text-summary

API

gulpRunner([opts])

Creates a gulp runner which generates a command string and runs it.

Arguments:
  • opts [object] : options for a runner. This object has following properties:

    • verbose [boolean] : if true, prints command, err, stdout, stderr
Methods:
  • basedir(path)

    Sets base directory path. This base directory is remained after running gulp.

    Arguments:

    • path [string] : a base directory path.
  • chdir(path [, path ...])

    Sets directory paths to be changed.

    Arguments:

    • path [string] : a sequence of directory paths.
  • gulp(arg [, arg ...])

    Sets gulp command with its arguments.

    Arguments:

    • arg [string] : a sequence of command line arguments.
  • run(cb)

    Runs gulp command.

    Arguments:

    • cb [function] : a call back function which is passed result of execution.

eraseTime(text)

Returns a text which is erased timestamp of each line.

Arguments:
  • text [string] : stdout text of gulp.

eraseLapse(text)

Returns a text which is erased lapse time of ease line.

Arguments:
  • text [string] : stdout text of gulp.

skipLines(text, nSkip)

Returns a text which is skipped the specified number of lines.

Arguments:
  • text [string] : stdout text of gulp.
  • nSkip [number] : line number to be skipped.

headLines(text, nLine, nSkip)

Returns a first nLine lines of a text. If second argument nSkip is specified, first nSkip lines are skipped.

Arguments:
  • text [string] : stdout text of gulp.
  • nLine [number] : line number to be output.
  • nSkip [number] : line number to be skipped. (optional)

License

MIT