babel-microtest
v1.1.1
Published
Framework-agnostic, minimal testing for Babel 7 plugins
Downloads
11
Readme
babel-microtest
babel-microtest
is a way of checking that your Babel 7 presets/plugins transform code as expected. It was created to solve 2 key problems relating to plugin development:
- interoperability with any testing framework
- code comparison (avoiding test failure over negligible differences such as semicolons and line breaks)
Installation
$ npm i -D babel-microtest
Usage
my-test.js
// use whatever your favorite testing framework (this demo uses Ava)
import test from 'ava'
// import the lib
import createTest from 'babel-microtest'
// test options (in this case, we're gonna test 'babel-plugin-implicit-return'):
const options = {
plugins: ['implicit-return'], // or import and pass the plugin directly
}
// create the test instance
const implicitReturnTest = createTest(options)
// using Ava
test('implicit return test title', t => {
implicitReturnTest(
{
source: `
function add(a, b) {
a + b
}
`,
expected: `
function add(a, b) {
return a + b
}
`,
},
t,
)
})
// ^ we pass `t` as the 2nd argument, but could substitute it with any
// object containing the testing framework's pass and fail fns