Skip to content

A local-first personal finance app

[AI] DX: strip color codes in expectSnapshotWithDiffer (#8310)

Matiss Janis Aboltinsf1ea275d8b0d
diff --git a/packages/loot-core/src/mocks/util.ts b/packages/loot-core/src/mocks/util.ts
index eef6066a15..22c0c09683 100644
--- a/packages/loot-core/src/mocks/util.ts
+++ b/packages/loot-core/src/mocks/util.ts
@@ -1,5 +1,6 @@
// @ts-strict-ignore
import fs from 'fs/promises';
+import { stripVTControlCharacters } from 'node:util';
import { basename, dirname, join } from 'path';
import { diff } from 'jest-diff';
@@ -15,12 +16,14 @@ export function expectSnapshotWithDiffer(
return {
expectToMatchDiff: value => {
expect(
- diff(currentValue, value, {
- aAnnotation: 'First value',
- bAnnotation: 'Second value',
- contextLines: 5,
- expand: false,
- }),
+ stripVTControlCharacters(
+ diff(currentValue, value, {
+ aAnnotation: 'First value',
+ bAnnotation: 'Second value',
+ contextLines: 5,
+ expand: false,
+ }),
+ ),
).toMatchSnapshot();
currentValue = value;
},
diff --git a/upcoming-release-notes/strip-ansi-snapshot-differ.md b/upcoming-release-notes/strip-ansi-snapshot-differ.md
new file mode 100644
index 0000000000..4880a36a28
--- /dev/null
+++ b/upcoming-release-notes/strip-ansi-snapshot-differ.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+Strip ANSI color codes in the `expectSnapshotWithDiffer` test helper so diff snapshots are deterministic regardless of terminal color detection.