Registry / testing / babel-test

babel-test

JSON →
library0.2.4jsnpmunverified

An opinionated library for testing Babel plugins with Jest or Mocha, using fixture files instead of snapshots. Current stable version is 0.2.4 (last released October 2020, low release cadence). Integrates with Jest's snapshot feature to auto-update fixture outputs on keypress, avoiding manual copy-paste. Simpler API than alternatives like @babel/helper-plugin-test-runner or babel-plugin-tester; focuses on directory-based fixtures with code.js/output.js/error.js pattern. Ships TypeScript types.

npm install babel-test
INSTALL
IMPORT
SIG · BABEL-TEST
B
babel-test
testingjavascriptv0.2.4
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.

create
import { create } from 'babel-test'
const create = require('babel-test')
Package ships TypeScript types and supports both ESM and CJS. Named import required.
default import
import { create } from 'babel-test'
import create from 'babel-test'
This package does not have a default export; only named export 'create'.
test
const { test } = create({ plugins: [...] })
const { test } = require('babel-test')
The 'test' function is returned from the create() call, not exported directly.

Demonstrates creating a test helper with babel-test using a fixture directory and lifecycle hooks.

import path from 'path'; import { create } from 'babel-test'; const { fixtures } = create({ plugins: [['path/to/plugin', { option1: true }]], }); fixtures('my plugin tests', path.join(__dirname, '__fixtures__'), { beforeEach() { console.log('Running setup...'); }, }); // Directory structure: // __fixtures__/ // simple-transform/ // code.js // output.js // error-case/ // code.js // error.js
Debug
Known issues
gotchaThe 'create' function sets babelrc and configFile to false by default to avoid external config interference.
fix
If you need external config, pass babelrc: true or configFile: true explicitly in the config object.
affects: >=0.1.0
deprecatedThe 'test' function returned from create() is undocumented and may be removed in future versions.
fix
Use 'fixtures' instead for directory-based tests. For single-file tests, consider using 'babel-plugin-tester'.
affects: >=0.2.0
gotchaFixture directories prefixed with 'skip.' or 'only.' are case-sensitive and must be lowercase.
fix
Name directories exactly as 'skip.my-test' or 'only.my-test' (all lowercase before dot).
affects: >=0.2.0
gotchaIf using Jest's --updateSnapshot flag, fixture output files are overwritten automatically; this may cause data loss if output.js is hand-edited.
fix
Version control fixture files. Use --ci mode to prevent accidental updates.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'babel-core'
babel-core is a peer dependency and not installed automatically.
fix
Run npm install --save-dev @babel/core (or babel-core for v6).
ENOENT: no such file or directory, open '.../__fixtures__/test/code.js'
Fixture directory structure is incorrect; missing code.js file.
fix
Ensure each fixture subdirectory contains a code.js file. See documentation for required structure.
TypeError: (0 , _babelTest.create) is not a function
Default import used instead of named import.
fix
Change import create from 'babel-test' to import { create } from 'babel-test'.
Upgrade
Version history
0.2.4latest on npm
Audit
Dependencies
babel-corerequiredRequired to transform code during tests
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
2
Resources
babel-test — npm install babel-test · libregistry