Let's say that I made 3 bundles of my library with my rollup config
esm
cjs
umd
I want to try each of the bundles in their respective environment.
Is it necessary? Usually I only do unit test of the source codes. Anyway, the only difference is to use babel or not.
install
npm i @babel/register mocha
.babelrc
{
"presets": ["@babel/preset-env"]
}
//package.json
{
//...
"scripts":
"test:es": "mocha test/index.esm.js --require @babel/register",
"test:cjs": "mocha test/index.cjs.js",
"test:umd": "mocha test/index.umd.js"
}
}
"import/require" part are different in test files:
//test/index.esm.js
import xx from '../dist/xx.esm.js'
//test/index.cjs.js
const xx = require('../dist/xx.cjs.js')
//test/index.umd.js
const xx = require('../dist/xx.umd.js')
For umd you may also test it in browser environment. Just build a html file, include mocha.js, umd.js with <script> tag and runs it.