Registry / testing / babel-plugin-tester

babel-plugin-tester

JSON →
library12.0.0jsnpmunverified

Utilities for writing tests for Babel plugins and presets. Version 12.0.0 is current. The library supports Jest, Mocha, Jasmine, node:test, and Vitest. Key differentiators: automatic fixture file loading, built-in prettier formatting, snapshot-based testing, environment variable filtering (TEST_ONLY, TEST_SKIP), and async ResultFormatter. Breaking changes in v12 include dropping default exports, requiring Node.js >=20.18.0, and adopting prettier@3's async interface. Peer dependency on @babel/core >=7.22.0.

npm install babel-plugin-tester
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TESTE
B
babel-plugin-tester
testingjavascriptv12.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 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.
fix
Change `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).
fix
Upgrade Node.js to >=20.18.0.
affects: >=12.0.0
breakingResultFormatter is now async (returns Promise) due to prettier@3.
fix
If 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.
fix
Run 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.
fix
Move 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.
fix
Change to named import: `import { pluginTester } from 'babel-plugin-tester'`
Error: Cannot find module 'babel-plugin-tester'
Missing install or wrong import path.
fix
Run `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.
fix
Check plugin logic and verify test input/output.
Upgrade
Version history
12.0.0latest on npm
Audit
Dependencies
@babel/corerequiredRequired peer dependency for transforming code with Babel plugins/presets.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
babel-plugin-tester — npm install babel-plugin-tester · libregistry