Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
babel-plugin-espower
Advanced tools
Babel plugin for power-assert.
babel-plugin-espower
is a Babel plugin for power-assert.
power-assert
provides descriptive assertion messages for your tests, like this.
1) ES6 demo Destructuring and TemplateLiteral:
AssertionError: # test/demo_test.js:7
assert(`${ alice.name } and ${ bob.name }` === `bob and alice`)
| | | | | | |
| | | | | | "bob and alice"
| | | | "bob" false
| | "alice" Object{name:"bob"}
| Object{name:"alice"}
"alice and bob"
--- [string] `bob and alice`
+++ [string] `${ alice.name } and ${ bob.name }`
@@ -1,13 +1,13 @@
-bob and alice
+alice and bob
Pull-requests, issue reports and patches are always welcomed. See power-assert project for more documentation.
$ npm install --save-dev babel-plugin-espower
Babel6 is incompatible with Babel5. For Babel 5 or lower, you need to use the 1.x release of babel-plugin-espower.
$ npm install --save-dev babel-plugin-espower@1.1.0
{
"presets": [
...
],
"plugins": [
"babel-plugin-espower"
]
}
$ babel /path/to/test/some_test.js > /path/to/build/some_test.js
var babel = require('babel-core');
var jsCode = fs.readFileSync('/path/to/test/some_test.js');
var transformed = babel.transform(jsCode, {
presets: [...],
plugins: ['babel-plugin-espower']
});
console.log(transformed.code);
require('babel-register')({
presets: [...],
plugins: ['babel-plugin-espower']
});
For example, with babel_hook.js
above, you can run mocha without code generation steps.
$ $(npm bin)/mocha --require ./babel_hook /path/to/test/demo_test.js
var fs = require('fs');
var browserify = require('browserify');
var babelify = require('babelify');
var glob = require('glob'),
browserify({ entries: glob.sync('./test/*_test.js'), debug: true })
.transform(babelify.configure({
presets: [...],
plugins: ['babel-plugin-espower']
}))
.bundle()
.on('error', function (err) { console.log('Error : ' + err.message); })
.pipe(fs.createWriteStream('all_test.js'));
$ $(npm bin)/browserify -d -e ./test/*_test.js -t [ babelify --presets ... --plugins babel-plugin-espower ]
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(babelify.configure({
presets: [...],
plugins: ['babel-plugin-espower']
}));
return b.bundle()
.pipe(source('all_test.js'))
.pipe(gulp.dest('./build'));
});
module.exports = function(config) {
config.set({
frameworks: ['mocha', 'browserify'],
files: [
"test/**/*.js"
],
preprocessors: {
"test/**/*.js": "browserify"
},
browserify: {
debug: true,
transform: [
[
'babelify', {
presets: [...],
plugins: ['babel-plugin-espower']
}
]
]
},
// ...
For given test file test/demo_test.js
below,
import assert from 'power-assert';
describe('ES6 demo', () => {
it('Destructuring and TemplateLiteral', () => {
let [alice, bob] = [ { name: 'alice' }, { name: 'bob' } ];
assert(`${alice.name} and ${bob.name}` === `bob and alice`);
});
it('ArrowFunctionExpression and SpreadElement', () => {
let seven = 7, ary = [4, 5];
assert(seven === ((v, i) => v + i)(...[...ary]));
});
it('Enhanced Object Literals', () => {
let name = 'bobby';
assert.deepEqual({
name,
[ `${name}'s greet` ]: `Hello, I'm ${name}`
}, null);
});
});
prepare babel_hook.js
to transform tests.
require('babel-register')({
presets: [...], // presets of your choice
plugins: ['babel-plugin-espower']
});
Run mocha
with --require
option. You will see the power-assert output appears.
$ $(npm bin)/mocha --require ./babel_hook test/demo_test.js
ES6 demo
1) Destructuring and TemplateLiteral
2) ArrowFunctionExpression and SpreadElement
3) Enhanced Object Literals
0 passing
3 failing
1) ES6 demo Destructuring and TemplateLiteral:
AssertionError: # test/demo_test.js:7
assert(`${ alice.name } and ${ bob.name }` === `bob and alice`)
| | | | | | |
| | | | | | "bob and alice"
| | | | "bob" false
| | "alice" Object{name:"bob"}
| Object{name:"alice"}
"alice and bob"
--- [string] `bob and alice`
+++ [string] `${ alice.name } and ${ bob.name }`
@@ -1,13 +1,13 @@
-bob and alice
+alice and bob
at Context.<anonymous> (test/demo_test.js:19:28)
2) ES6 demo ArrowFunctionExpression and SpreadElement:
AssertionError: # test/demo_test.js:12
assert(seven === ((v, i) => v + i)(...[...ary]))
| | | | |
| | | | [4,5]
| | 9 [4,5]
7 false
[number] ((v, i) => v + i)(...[...ary])
=> 9
[number] seven
=> 7
at Context.<anonymous> (test/demo_test.js:29:28)
3) ES6 demo Enhanced Object Literals:
AssertionError: # test/demo_test.js:17
assert.deepEqual({name,[`${ name }'s greet`]: `Hello, I'm ${ name }`}, null)
| | | | |
| | | | "bobby"
| | "bobby" "Hello, I'm bobby"
| "bobby's greet"
Object{name:"bobby","bobby's greet":"Hello, I'm bobby"}
at Context.<anonymous> (test/demo_test.js:40:29)
You can customize assertion patterns via Babel API,
var babel = require('babel-core');
var createEspowerPlugin = require('babel-plugin-espower/create');
var jsCode = fs.readFileSync('/path/to/test/some_test.js');
var transformed = babel.transform(jsCode, {
presets: [...],
plugins: [
createEspowerPlugin(babel, {
patterns: [
'assert.isNull(object, [message])',
'assert.same(actual, expected, [message])',
'assert.near(actual, expected, delta, [message])'
]
})
]
});
console.log(transformed.code);
or via Require Hook.
var createEspowerPlugin = require('babel-plugin-espower/create');
require('babel-register')({
presets: [...],
plugins: [
createEspowerPlugin(babel, {
patterns: [
'assert.isNull(object, [message])',
'assert.same(actual, expected, [message])',
'assert.near(actual, expected, delta, [message])'
]
})
]
});
type | default value |
---|---|
object | (return value of espower.defaultOptions() with default visitorKeys , path , sourceRoot and sourceMap ) |
Configuration options for internal espower
module. If not passed, default options will be used (return value of espower.defaultOptions()
with default visitorKeys
, path
, sourceRoot
and sourceMap
. visitorKeys
is value of babel.types.VISITOR_KEYS
. path
is filename passed to babel. sourceRoot
is be return value of process.cwd()
, sourceMap
is babel's internal SourceMap object).
See CHANGELOG
Licensed under the MIT license.
2.0.0 (2015-11-13)
Babel6 is incompatible with Babel5. For Babel 5 or lower, you need to use the 1.x release of babel-plugin-espower.
$ npm install --save-dev babel-plugin-espower@1.1.0
FAQs
Babel plugin for power-assert
The npm package babel-plugin-espower receives a total of 59,641 weekly downloads. As such, babel-plugin-espower popularity was classified as popular.
We found that babel-plugin-espower demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.