Registry / testing / jest-serializer-babel-ast

jest-serializer-babel-ast

JSON →
library0.0.5jsnpmunverified

A Jest snapshot serializer that pretty-prints Babel AST nodes (e.g., from @babel/parser) in a human-readable, indented format. Current stable version is 0.0.5 (unreleased beyond). No active release cadence; maintained sporadically. Differentiators: provides a clean, nested view of AST node properties, ideal for snapshot testing Babel plugins or AST transformations. Compared to alternatives like jest-serialize, it is purpose-built for Babel AST and outputs structured property lists. Works with Jest snapshotSerializers configuration.

npm install jest-serializer-babel-ast
INSTALL
IMPORT
SIG · JEST-SERIALIZER-BA
J
jest-serializer-babel-ast
testingjavascriptv0.0.5
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.

jest-serializer-babel-ast
Add to jest.snapshotSerializers in package.json or jest.config.js: 'jest-serializer-babel-ast'
import serializer from 'jest-serializer-babel-ast'
This is a Jest serializer, not a module you import directly. It is loaded automatically via Jest configuration.
expect.addSnapshotSerializer
expect.addSnapshotSerializer(require('jest-serializer-babel-ast'))
const serializer = require('jest-serializer-babel-ast').default
If using programmatic registration with expect.addSnapshotSerializer, use require() directly; the package does not export a default.
default (CommonJS)
const serializer = require('jest-serializer-babel-ast')
const { serialize } = require('jest-serializer-babel-ast')
The package exports the serializer object directly (with serialize and test methods), not named exports.

Configures Jest to use the serializer, then generates a human-readable AST snapshot from parsed code.

// jest.config.js or package.json module.exports = { snapshotSerializers: ['jest-serializer-babel-ast'] } // test file const { parse } = require('@babel/parser'); test('AST snapshot', () => { const ast = parse('const x = 1;', { sourceType: 'module' }); expect(ast).toMatchSnapshot(); }); // Snapshot output will show structured AST instead of JSON.
Debug
Known issues
gotchaWorks only with Babel AST nodes from @babel/parser (babylon). May not handle other parsers or custom AST types.
fix
Ensure you are using @babel/parser (or babylon) to generate AST nodes.
affects: >=0.0.0
gotchaThe serializer expects nodes with a 'type' property; non-AST objects will not be serialized by this serializer.
fix
Make sure the snapshot content contains Babel AST nodes. For other objects, Jest's default serializer will be used.
affects: >=0.0.0
deprecatedThe package is no longer actively maintained. There are no security issues reported, but bugs may remain unaddressed.
fix
Consider alternatives like jest-serializer-ast or writing your own serializer with a library like pretty-format.
affects: >=0.0.0
gotchaSerializer may not show private properties (prefixed with underscore) or Babel node internal metadata (e.g., start/end locations) unless they are enumerable.
fix
If you need location data, configure Babel parser to include 'ranges' or check the node's 'loc' property.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'jest-serializer-babel-ast'
Package not installed or not present in node_modules.
fix
Run: npm install jest-serializer-babel-ast --save-dev
TypeError: serializer.serialize is not a function
Importing the package incorrectly, e.g., using import default or expecting named exports.
fix
Use: const serializer = require('jest-serializer-babel-ast');
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
jest-serializer-babel-ast — npm install jest-serializer-babel-ast · libregistry