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
Please note that babel-plugin-espower
is an alpha version product. Pull-requests, issue reports and patches are always welcomed. See power-assert project for more documentation.
$ npm install --save-dev babel-core babel-plugin-espower
$ npm dedupe
Because Babel plugin system requires babel-core at the top level. Sorry for the inconvenience.
$ ./node_modules/.bin/babel --plugins babel-plugin-espower /path/to/test/some_test.js > /path/to/build/some_test.js
or shortly,
$ ./node_modules/.bin/babel --plugins espower /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, {
plugins: ['babel-plugin-espower']
});
console.log(transformed.code);
require('babel-core/register')({
only: /test\/tobe_instrumented/,
plugins: ['babel-plugin-espower'],
extensions: ['.es6', '.js']
});
For example, with babel_hook.js
above, you can run mocha without code generation steps.
$ ./node_modules/.bin/mocha --require ./babel_hook /path/to/test/demo_test.js
For given test file 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);
});
});
Run babel
with --plugins espower
to transform tests.
$ ./node_modules/.bin/babel --plugins espower /path/to/test/demo_test.js > /path/to/build/demo_test.js
Then run. You will see the power-assert output appears.
$ ./node_modules/.bin/mocha /path/to/build/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> (build/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> (build/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> (build/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, {
plugins: [
createEspowerPlugin({
patterns: [
'assert.isNull(object, [message])',
'assert.same(actual, expected, [message])',
'assert.near(actual, expected, delta, [message])'
]
})
]
});
console.log(transformed.code);
Sometimes you'll see TypeError such as...
TypeError: Transformer babel-plugin-espower is resolving to a different Babel version to what is doing the actual transformation...
This error is caused by Babel plugin system that requires babel-core at the top level. To solve this problem, run npm dedupe
. If dedupe does not solve the problem, it's time to clean-install by rm -rf node_modules && npm install
. Sorry for the inconvenience.
See CHANGELOG
Licensed under the MIT license.
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.