Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browserify transform for power-assert
JavaScript

1.0.0

latest commit b6865de57c
@twada twada authored

README.md

espowerify

Build Status NPM package Dependency Status License

Browserify transform for power-assert.

DESCRIPTION

espowerify is a browserify transform for power-assert.

espowerify applies espower to target sources through browserify transform chain. espower manipulates assertion expression (JavaScript Code) represented as AST defined in The ESTree Spec (formerly known as Mozilla SpiderMonkey Parser API), to instrument power-assert feature into the code.

Pull-requests, issue reports and patches are always welcomed.

See power-assert project for more documentation.

FAQ

espowerify does not work with babelify!!

espowerify does not work with babelify due to the change of transpiled code since babel 5.0. Please use babel-plugin-espower with babelify.

CHANGELOG

See CHANGELOG

HOW TO USE

First, install power-assert and espowerify via npm.

$ npm install --save-dev power-assert espowerify

Second, require power-assert in your test.

--- a/test/your_test.js
+++ b/test/your_test.js
@@ -1,4 +1,4 @@
-var assert = require('assert');
+var assert = require('power-assert');

Third, apply espowerify through browserify transform.

by command-line,

$ browserify -t espowerify test/your_test.js > dist/your_test.js

or programmatically,

var source = require('vinyl-source-stream');
var browserify = require('browserify');
var glob = require('glob');

gulp.task('build_test', function() {
    var files = glob.sync('./test/*_test.js');
    var b = browserify({entries: files, debug: true});
    b.transform('espowerify');
    return b.bundle()
        .pipe(source('all_test.js'))
        .pipe(gulp.dest('./build'));
});

(Note that files are transformed if matches to entries)

Lastly, run your test in your way. For example,

$ mocha-phantomjs path/to/test.html

SOURCE MAPS

espowerify supports source maps. espowerify generates source maps with all original sources inlined then adds the resulting source map base64 encoded to the bottom of the transformed code.

This allows debugging the original code when using the debug flag -d with browserify.

$ browserify -d -t espowerify test/your_test.js > dist/your_test_with_sourcemaps.js

or programmatically (see debug: true option),

var source = require('vinyl-source-stream');
var browserify = require('browserify');
var glob = require('glob');
var mold = require('mold-source-map');

gulp.task('build_test', function() {
    var files = glob.sync('./test/*_test.js');
    var b = browserify({entries: files, debug: true});
    b.transform('espowerify');
    return b.bundle()
        .pipe(mold.transformSourcesRelativeTo(__dirname))
        .pipe(source('all_test.js'))
        .pipe(gulp.dest('./build'));
});

(note: mold-source-map module adjusts absolute paths in resulting sourcemaps to relative path. This is required if you are debugging with Firefox)

If the debug flag is not set, these source maps will be removed by browserify and thus will not be contained inside your bundle.

API

espowerify(filepath, options)

Apply espower through the browserify transform chain.

options.patterns

type default value
Array of string objects shown below
[
    'assert(value, [message])',
    'assert.ok(value, [message])',
    'assert.equal(actual, expected, [message])',
    'assert.notEqual(actual, expected, [message])',
    'assert.strictEqual(actual, expected, [message])',
    'assert.notStrictEqual(actual, expected, [message])',
    'assert.deepEqual(actual, expected, [message])',
    'assert.notDeepEqual(actual, expected, [message])',
    'assert.deepStrictEqual(actual, expected, [message])',
    'assert.notDeepStrictEqual(actual, expected, [message])'
]

Target patterns for power assert feature instrumentation. (This option could be passed by programmatical way only)

If callee name (for example, assert.equal) matches exactly and number of arguments is satisfied, then the assertion will be modified. Detection is done by escallmatch. Any arguments enclosed in bracket (for example, [message]) means optional parameters. Without bracket means mandatory parameters.

AUTHOR

CONTRIBUTORS

LICENSE

Licensed under the MIT license.

Something went wrong with that request. Please try again.