Skip to content

Serializes ANSI codes as human-readable text for vitest snapshots

License

Notifications You must be signed in to change notification settings

43081j/vitest-ansi-serializer

Repository files navigation

vitest-ansi-serializer

This package provides a snapshot serializer to be used with vitest.

It will serialize ANSI escape sequences into human-readable code in strings, to allow for easier reading and diffing of snapshots.

Install

npm i -D vitest-ansi-serializer

Usage

As per the vitest docs, you can use the serializer like so:

import { expect } from 'vitest';
import ansiSerializer from 'vitest-ansi-serializer';

expect.addSnapshotSerializer(ansiSerializer);

Supported ANSI codes

The following ANSI codes are supported:

  • cursor.hide (?25l)
  • cursor.show (?25h)
  • cursor.save (7)
  • cursor.restore (8)
  • cursor.up (A)
  • cursor.down (B)
  • cursor.forward (C)
  • cursor.backward (D)
  • cursor.nextLine (E)
  • cursor.prevLine (F)
  • cursor.left (G)
  • cursor.scrollUp (S)
  • cursor.scrollDown (T)
  • erase.screen (2J)
  • erase.down (J, 0J)
  • erase.up (1J)
  • erase.lineEnd (K, 0K)
  • erase.lineStart (1K)
  • erase.line (2K)
  • erase.reset (c)

These will be made human readable in snapshots in the form of XML-like tags:

<cursor.down count=1>

License

MIT

About

Serializes ANSI codes as human-readable text for vitest snapshots

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •