tests: co-locate every Vitest suite next to its subject under src/

Eliminate the parallel `tests/` tree. Each `*.test.ts` / `*.test.tsx`
now sits in the same directory as the module it covers, mirroring its
filename (`Foo.ts` ↔ `Foo.test.ts`). The renderer-SDK mock used by
component / hook tests moves to `src/__mocks__/nitro-renderer.ts` and
the Vitest setup file becomes `src/test-setup.ts` — both still wired
through `vitest.config.mts` exactly as before, only the paths changed.

All 13 suites + 178/178 cases still pass. The production build is
unaffected: rollup only follows imports from `src/index.tsx` and never
crosses into `.test.ts` files, so test code is naturally tree-shaken
out of the bundle. `yarn build` output is byte-for-byte the same on
the user-facing chunks.

tsconfig drops the now-redundant `tests` include entry. CLAUDE.md
'Layout convention' replaces the old `tests/` row with three rows
documenting the new co-located convention, the `__mocks__/` directory
and the `test-setup.ts` entry; ARCHITECTURE.md picks up the same
update. The 'DO NOT CHANGE' qualifier on the layout is preserved —
this rewrite IS the change, decided deliberately to make tests a
first-class part of the source tree rather than a sibling project.
This commit is contained in:
simoleo89
2026-05-16 11:35:03 +02:00
parent eb8d87969d
commit 8b4308af16
19 changed files with 47 additions and 46 deletions
+39
View File
@@ -0,0 +1,39 @@
import { describe, expect, it } from 'vitest';
import { dedupeBadges } from './dedupeBadges';
describe('dedupeBadges', () =>
{
it('returns an empty array for an empty input', () =>
{
expect(dedupeBadges([])).toEqual([]);
});
it('preserves unique badges in slot order', () =>
{
expect(dedupeBadges([ 'a', 'b', 'c' ])).toEqual([ 'a', 'b', 'c' ]);
});
it('replaces duplicate slots with empty strings to preserve slot indices', () =>
{
expect(dedupeBadges([ 'a', 'b', 'a', 'c' ])).toEqual([ 'a', 'b', '', 'c' ]);
});
it('normalizes falsy entries (null, undefined, "") to empty string', () =>
{
// server sometimes returns null/undefined for unused slots
const input = [ 'a', null as unknown as string, '', undefined as unknown as string, 'b' ];
expect(dedupeBadges(input)).toEqual([ 'a', '', '', '', 'b' ]);
});
it('only keeps the FIRST occurrence of each unique code', () =>
{
expect(dedupeBadges([ 'a', 'a', 'a' ])).toEqual([ 'a', '', '' ]);
});
it('is order-sensitive: identical multisets but different orderings yield different outputs', () =>
{
expect(dedupeBadges([ 'a', 'b', 'a' ])).toEqual([ 'a', 'b', '' ]);
expect(dedupeBadges([ 'b', 'a', 'a' ])).toEqual([ 'b', 'a', '' ]);
});
});