espower-babel v4.0.3
espower-babel 
power-assert instrumentor for Babel.
This module is wrapper of babel-plugin-espower.
Purpose
- Writing ES6 tests with Babel
- Running tests with power-assert on the fly!
- No configuration
DESCRIPTION
espower-babel is a Node.js module loader that instruments power-assert feature into target ECMAScript6 sources on the fly.
Please note that espower-babel is a beta version product. Pull-requests, issue reports and patches are always welcomed. See power-assert project for more documentation.
If you want to use with Traceur, please see yosuke-furukawa/espower-traceur.
EXAMPLE
Given test/demo_test.js
let assert = require('power-assert')
class Person {
constructor(name, age) {
this.name = name
this.age = age
}
getAge() {
return this.age
}
}
describe("Person", ()=>{
let alice = new Person("alice", 3)
let bob = new Person("bob", 5)
it("#getAge", ()=>{
assert(alice.getAge() === 3)
})
it("#name", ()=>{
assert(alice.name === "alice")
})
// failed
it("#mistake", ()=>{
assert(alice.name === bob.name)
})
})Run mocha with --compilers js:espower-babel/guess
$ mocha --compilers js:espower-babel/guess test/demo_test.js
․․․
2 passing (17ms)
1 failing
1) Person #mistake:
AssertionError: # test/demo_test.js:24
assert(alice.name === bob.name)
| | | | |
| | | | "bob"
| | | Person{name:"bob",age:5}
| | false
| "alice"
Person{name:"alice",age:3}
--- [string] bob.name
+++ [string] alice.name
@@ -1,3 +1,5 @@
-bob
+aliceSee the power-assert output appears!
INSTALL
$ npm install espower-babel -DHOW TO USE
Zero-config mode(for testing)
If your tests are located on 'test/**/*.js', just run mocha with --compilers js:espower-babel/guess
$ mocha --compilers js:espower-babel/guess test/**/*.jsIf your tests are not in test dir
You can set test directory in your package.json
{
"name": "your-module",
"description": "Your module",
"version": "0.0.1",
"directories": {
"test": "spec/"
},
...
}Then, run mocha with --compilers js:espower-babel/guess
$ mocha --compilers js:espower-babel/guess spec/**/*.jsNote: 'espower-babel/guess' is inspired by intelli-espower-loader
More customization
If you want to configure more explicitly, put espower-babel-loader.js somewhere in your project.
require('espower-babel')({
// directory where match starts with
cwd: process.cwd(),
// glob pattern using minimatch module
pattern: 'spec/unit/**/*.js',
// options for espower module
espowerOptions: {
patterns: [
'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])'
]
}
});Then, run mocha with --require option
$ mocha --require ./path/to/espower-babel-loader spec/unit/some_test_using_powerassert.jsBabel transform options
Babel has many transform options.
espower-babel support babel transform options with .babelrc.
espower-babel read ${cwd}/.babelrc if exists.
Also, you can manually configure babel transform options.
e.g.)
require('espower-babel')({
babelrc: {
"presets": ["es2015"],
"plugins": ["transform-es2015-modules-commonjs"]
}
})Caution:
Babel 6 does not transform your code by default.
It means that you must set babel config by .babelrc file or babelrc option.
Transform all files with Babel by default
Do limit transform files by setting babelrc
e.g.)
require('espower-babel')({
babelrc: {
only: [
"src/**/*.js"
]
}
})Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request :D
License
MIT
Includes yosuke-furukawa/espower-traceur
Acknowledgements
Thanks to yosuke-furukawa/espower-traceur.