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.
npm i -D vitest-ansi-serializer
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);
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>
MIT