包详细信息

gulp-espower

power-assert-js2.4kMIT1.1.0

A gulp plugin for power-assert

assert, assertion, gulpplugin, power-assert

自述文件

gulp-espower

Build Status NPM version Dependency Status License

A gulp plugin for power-assert.

Description

gulp-espower is a gulp plugin to instrument "Power Assert" feature into your code.

Internally, gulp-espower task uses espower module that manipulates assertion expression (JavaScript Code) defined in The ESTree Spec (formerly known as Mozilla SpiderMonkey Parser API), to instrument power-assert feature into the code. The magic is done by using Esprima and Escodegen.

Pull-requests, issue reports and patches are always welcomed. See power-assert project for more documentation.

Usage

First, install gulp-espower as a development dependency:

npm install --save-dev gulp-espower

Then, add it to your gulpfile.js:

var espower = require('gulp-espower');

gulp.src('./test/*.js')
    .pipe(espower())
    .pipe(gulp.dest('./dist'));

Source maps

gulp-espower works with gulp-sourcemaps to generate source maps for the instrumented javascript code. Note that you should init gulp-sourcemaps prior to running the gulp-espower and write the source maps after. gulp-espower works well with some gulp plugins that supports gulp-sourcemaps.

var espower = require('gulp-espower');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');

// compile, instrument then concatinate
gulp.src('./test/*test.coffee')
    .pipe(sourcemaps.init())
    .pipe(coffee())
    .pipe(espower())
    .pipe(concat('all_test.js'))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('./build'));
// will write the source maps inline in the code

For more information, see gulp-sourcemaps.

API

espower(options)

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.

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.

CHANGELOG

See CHANGELOG

OUR SUPPORT POLICY

We support Node under maintenance. In other words, we stop supporting old Node version when their maintenance ends.

This means that any other environment is not supported.

NOTE: If espower-cli works in any of the unsupported environments, it is purely coincidental and has no bearing on future compatibility. Use at your own risk.

AUTHOR

CONTRIBUTORS

License

Licensed under the MIT license.

更新日志

1.1.0 (2016-11-22)

Features

1.0.2 (2015-12-10)

Bug Fixes

  • fix typo in PluginError call (070431fe)

1.0.1 (2015-10-08)

  • update espower to 1.0.7 (5173f4b)
  • update vinyl-sourcemaps-apply to 0.2.0 (7ae9fcb)
  • update bufferstreams to 1.1.0 (1c19377)

1.0.0 (2015-08-22)

Bug Fixes

  • should emit error when the file has a syntax error, even if using Streams (a786374d)

Features

0.10.1 (2015-03-04)

Bug Fixes

  • fix a bug that throw an error when the file has a syntax error (603a681b) (by @bouzuya)

0.10.0 (2014-11-11)

  • update espower and espower-source to 0.10.0 (724aead0)
  • update vinyl-sourcemaps-apply (c19ca9ab)

0.9.1 (2014-09-17)

Features

  • update espower and espower-source to 0.9.1 (681f1ab9)

0.9.0 (2014-09-02)

Features

  • gulp-sourcemaps support (caf2a275)
  • keep paths relative until the end of chain (9dc8f50b)

0.8.0 (2014-08-12)

Features

  • update espower-source to 0.8.0 (a9ab1f7d)
  • now supports streams as well (ada19f90)

Breaking Changes

  • update espower-source to 0.8.0 (a9ab1f7d)

If you already customize instrumentation pattern using powerAssertVariableName and targetMethods, you need to migarte. To migrate, change your code from the following:

var espower = require("gulp-espower");

gulp.src("./test/*.js")
    .pipe(espower({
        powerAssertVariableName: 'yourAssert',
        targetMethods: {
            oneArg: [
                'okay'
            ],
            twoArgs: [
                'equal',
                'customEqual'
            ]
        }
    }))
    .pipe(gulp.dest("./dist"));

To:

var espower = require("gulp-espower");

gulp.src("./test/*.js")
    .pipe(espower({
        patterns: [
            'yourAssert(value, [message])',
            'yourAssert.okay(value, [message])',
            'yourAssert.equal(actual, expected, [message])',
            'yourAssert.customEqual(actual, expected, [message])'
        ]
    }))
    .pipe(gulp.dest("./dist"));