From 3279422933bd6c9f186c1463152a04b88b80ad25 Mon Sep 17 00:00:00 2001 From: Arnab Nandy Date: Mon, 8 Jun 2026 22:29:28 +0530 Subject: [PATCH] Fixes for null comparison --- src/lib/compare.ts | 4 ++++ test/lib/compare.test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/lib/compare.ts b/src/lib/compare.ts index 04d3b74..92895a3 100644 --- a/src/lib/compare.ts +++ b/src/lib/compare.ts @@ -107,6 +107,10 @@ function getDiffType( return undefined; } + if (baseline.value === null || target.value === null) { + return 'CHANGED'; + } + return getJsonType(baseline.value) === getJsonType(target.value) ? 'CHANGED' : 'TYPE_CHANGE'; diff --git a/test/lib/compare.test.ts b/test/lib/compare.test.ts index 6b061e9..4fabf10 100644 --- a/test/lib/compare.test.ts +++ b/test/lib/compare.test.ts @@ -135,6 +135,30 @@ describe('compareJson', () => { ]); }); + it('reports null comparisons as value changes instead of type changes', () => { + expect( + compareJson( + { text: null, count: 1 }, + { text: 'ready', count: null }, + { text: null, count: 2 }, + ), + ).toEqual([ + { + path: 'count', + type: 'CHANGED', + devValue: 1, + qaValue: null, + prodValue: 2, + }, + { + path: 'text', + type: 'CHANGED', + devValue: null, + qaValue: 'ready', + }, + ]); + }); + it('returns separate rows when one environment changes type and another changes value', () => { expect( compareJson(