Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pluginTester
✓ import { pluginTester } from 'babel-plugin-tester'
✗ import pluginTester from 'babel-plugin-tester'
Default export was removed in v12. Use named import only.
prettierFormatter
✓ import { prettierFormatter } from 'babel-plugin-tester'
Available as a named export; commonly used to format output with Prettier.
pluginTester (CJS)
✓ const { pluginTester } = require('babel-plugin-tester')
✗ const pluginTester = require('babel-plugin-tester')
CJS require must destructure the named export. Default require returns an object with named exports.
Basic test suite for a Babel plugin with inline code tests and a snapshot test.
import { pluginTester } from 'babel-plugin-tester';
import myPlugin from './my-plugin';
pluginTester({
plugin: myPlugin,
tests: {
'transforms correctly': {
code: 'const x = 1;',
output: 'const x = 1;',
},
'snapshot test': {
code: 'const y = 2;',
snapshot: true,
},
},
});
Debug
Known issues
breakingDefault export removed in v12. Import { pluginTester } instead of default import.fixChange `import pluginTester from 'babel-plugin-tester'` to `import { pluginTester } from 'babel-plugin-tester'`. affects: >=12.0.0
breakingMinimum Node.js version is now 20.18.0 (v12).fixUpgrade Node.js to >=20.18.0.
affects: >=12.0.0
breakingResultFormatter is now async (returns Promise) due to prettier@3.fixIf using custom formatter, ensure it returns a Promise or use async/await.
affects: >=12.0.0
gotchaWith prettier@3, some Node versions require --experimental-vm-modules flag.fixRun tests with `NODE_OPTIONS='--no-warnings --experimental-vm-modules' npx jest`.
affects: >=12.0.0
breakingImplicit global option merging removed in v11. All options must be explicitly set per test or via global config.fixMove shared options to the top-level pluginTester configuration.
affects: >=11.0.0 <12.0.0
Errors
Common errors & fixes
TypeError: pluginTester is not a function
Using default import with v12+ which removed default export.
fixChange to named import: `import { pluginTester } from 'babel-plugin-tester'` Error: Cannot find module 'babel-plugin-tester'
Missing install or wrong import path.
fixRun `npm install --save-dev babel-plugin-tester` and ensure import path is correct.
AssertionError: expected 'const x = 1;' to equal 'const x = 2;'
Test output mismatch; plugin may not be transforming as expected.
fixCheck plugin logic and verify test input/output.
Audit
Dependencies
@babel/corerequiredRequired peer dependency for transforming code with Babel plugins/presets.