https://github.com/harrysolovay/babel-microtest
🔬Framework-agnostic, minimal testing for Babel 7 plugins
https://github.com/harrysolovay/babel-microtest
babel compiler plugin testing transform
Last synced: about 2 months ago
JSON representation
🔬Framework-agnostic, minimal testing for Babel 7 plugins
- Host: GitHub
- URL: https://github.com/harrysolovay/babel-microtest
- Owner: harrysolovay
- Created: 2019-02-04T20:46:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-05T03:07:53.000Z (over 7 years ago)
- Last Synced: 2025-02-16T10:33:52.318Z (over 1 year ago)
- Topics: babel, compiler, plugin, testing, transform
- Language: JavaScript
- Homepage:
- Size: 183 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# babel-microtest
[](https://travis-ci.org/harrysolovay/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:
1. interoperability with any testing framework
2. code comparison (avoiding test failure over negligible differences such as semicolons and line breaks)
## Installation
```shell
$ npm i -D babel-microtest
```
## Usage
`my-test.js`
```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
```