From 82b23a9c844e308153e6a75adc515eb3d9d827c8 Mon Sep 17 00:00:00 2001 From: Scrum4Me Agent <30029041+madhura68@users.noreply.github.com> Date: Sat, 9 May 2026 20:40:09 +0200 Subject: [PATCH] feat(PBI-49): add debugProps helper + Vitest test Adds lib/debug.ts with debugProps(id, component, file) that returns data-debug-id and data-debug-label attrs in dev mode, empty object in production. Adds __tests__/lib/debug.test.ts covering both modes. Co-Authored-By: Claude Sonnet 4.6 --- __tests__/lib/debug.test.ts | 24 ++++++++++++++++++++++++ lib/debug.ts | 16 ++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 __tests__/lib/debug.test.ts create mode 100644 lib/debug.ts diff --git a/__tests__/lib/debug.test.ts b/__tests__/lib/debug.test.ts new file mode 100644 index 0000000..96d6487 --- /dev/null +++ b/__tests__/lib/debug.test.ts @@ -0,0 +1,24 @@ +import { describe, it, expect, vi } from 'vitest' + +import { debugProps } from '@/lib/debug' + +describe('debugProps', () => { + it('returns both attrs with correct label in dev mode', () => { + const result = debugProps('sprint-board', 'SprintBoard', 'components/sprint/sprint-board.tsx') + expect(result).toEqual({ + 'data-debug-id': 'sprint-board', + 'data-debug-label': 'SprintBoard — components/sprint/sprint-board.tsx', + }) + }) + + it('returns empty object in production mode', () => { + const original = process.env.NODE_ENV + try { + vi.stubEnv('NODE_ENV', 'production') + const result = debugProps('sprint-board', 'SprintBoard', 'components/sprint/sprint-board.tsx') + expect(result).toEqual({}) + } finally { + vi.stubEnv('NODE_ENV', original ?? 'test') + } + }) +}) diff --git a/lib/debug.ts b/lib/debug.ts new file mode 100644 index 0000000..6339f64 --- /dev/null +++ b/lib/debug.ts @@ -0,0 +1,16 @@ +export type DebugProps = { + 'data-debug-id': string + 'data-debug-label': string +} + +export function debugProps( + id: string, + component: string, + file: string +): DebugProps | Record { + if (process.env.NODE_ENV === 'production') return {} + return { + 'data-debug-id': id, + 'data-debug-label': `${component} — ${file}`, + } +}