Skip to content

Commit 7a94fc7

Browse files
authored
Updated tests to follow TypeScript test skill (#611)
Noticed my own tests were not following the TypeScript test & format skill so updated my tests.
1 parent bf56c5a commit 7a94fc7

69 files changed

Lines changed: 1390 additions & 860 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.claude/rules/code-style.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Export style follows the kind of module. Components, layouts, App Router route f
3535

3636
The counts, thresholds, and carve-outs behind these live in the skill. What follows is how they land here.
3737

38-
- **A component gets a directory, not a loose file.** Every one lives in its own kebab-case directory under `src/components/` with a PascalCase file and a colocated test, as [`navbar/Navbar.tsx`](../../src/components/navbar/Navbar.tsx) does. Eight of the nine directories spell the name that way, and [`Stars/`](../../src/components/Stars/StarsBackground.tsx) is the single PascalCase exception rather than a second convention: match the eight. Related files are grouped into a subdirectory rather than left flat beside unrelated ones, and entries sharing a name prefix are the group to propose.
39-
- **Count the files sitting directly in a directory**, whatever subdirectories sit beside them: one subdirectory does not make the loose files next to it grouped. [`src/components/ServiceWorkerRegister.tsx`](../../src/components/ServiceWorkerRegister.tsx) and the two `ThemeRegistry` files sit directly in `src/components/` beside nine component directories, so the count there is three rather than twelve.
38+
- **A component gets a directory, not a loose file.** Every one lives in its own kebab-case directory under `src/components/` with a PascalCase file and a colocated test, as [`navbar/Navbar.tsx`](../../src/components/navbar/Navbar.tsx) does. Eleven of the twelve directories spell the name that way, and [`Stars/`](../../src/components/Stars/StarsBackground.tsx) is the single PascalCase exception rather than a second convention: match the eleven. Related files are grouped into a subdirectory rather than left flat beside unrelated ones, and entries sharing a name prefix are the group to propose.
39+
- **Count the files sitting directly in a directory**, whatever subdirectories sit beside them: one subdirectory does not make the loose files next to it grouped. [`ServiceWorkerRegister.tsx`](../../src/components/ServiceWorkerRegister.tsx), [`ServiceWorkerRegister.test.tsx`](../../src/components/ServiceWorkerRegister.test.tsx), [`ThemeRegistry.tsx`](../../src/components/ThemeRegistry.tsx), and [`ThemeRegistry.test.tsx`](../../src/components/ThemeRegistry.test.tsx) sit directly in `src/components/` beside twelve component directories, so the count there is four rather than sixteen.
4040
- **A setting the tooling reads from configuration is set once, never per file.** [`jest.config.js`](../../jest.config.js) already sets `testEnvironment: 'jsdom'` for every test, so only the minority that needs another environment carries a `@jest-environment` docblock: tests that build a fetch `Request` or `Response` run in `node`, because jsdom has neither. Path aliases are declared in [`tsconfig.json`](../../tsconfig.json) and mirrored in [`jest.config.js`](../../jest.config.js) rather than re-declared per import. Where the same directive would go into three or more files, **search for the key rather than for the directive's own spelling**, since the two are rarely the same word, and hoist the majority while leaving the minority declared. Moving a directive into the key the tool reads is not deleting it.
4141
- **A utility does one thing, and a parameter it branches on is a second thing.** Count the parameters of every function you write or review, splitting those supplying data from those the body branches on rather than operates on. Every exported helper here already matches that shape: [`convertAAAAHH(aaaaahhhh: string)`](../../src/helpers/aaaahhhh.ts) takes one value and no switch, and [`readConsent()`](../../src/util/consent/consentStore.ts) takes none, so a new helper carrying two booleans is the outlier rather than the norm. More than one switch on a utility is the trigger to split it into one function per behaviour; a function coordinating a sequence takes its modes legitimately. Each function a split produces has one caller the day it lands, and that is what a split looks like rather than a reason to keep the flag.
4242
- **Reuse before writing.** Check this repository's own [`helpers`](../../src/helpers/ascii.ts) and [`util`](../../src/util/absoluteUrl.ts) modules, then [`package.json`](../../package.json) with the lockfile beside it, then the platform, before hand-writing behaviour that has a name outside this repository. Read what the modules a file already imports export before accepting a hand-written block beneath them. Where nothing present provides it, say so rather than adding a dependency. Never hand-roll anything that signs, verifies, hashes a credential, or settles an authorization outcome.

‎.claude/rules/testing.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ Retrieve mock state with `jest.requireMock('@configs/firebase').logAnalyticsEven
3434

3535
`next/image` is left unmocked, and is the pattern to follow. It rewrites `src` through its loader, so the test asserts with `expect.stringContaining('profile_pic_drawn.webp')` rather than mocking the component to get an exact path.
3636

37-
## Test file exemptions
37+
## Modules that get no test file
3838

39-
Exempt from needing a colocated test: static data modules such as [`projects.ts`](../../src/data/projects.ts), type-only modules, metadata route exports ([`manifest.ts`](../../src/app/manifest.ts), [`robots.ts`](../../src/app/robots.ts)), and instrumentation entry points. Components are **not** exempt.
39+
Static data modules (everything under [`src/data/`](../../src/data/projects.ts), such as `projects.ts` and `structuredData.ts`), type-only modules, metadata route exports ([`manifest.ts`](../../src/app/manifest.ts), [`robots.ts`](../../src/app/robots.ts)), and instrumentation entry points get **no** colocated test file. A test that only asserts a static data literal against itself adds no behaviour coverage; a test of a component or function that consumes a module may import its exported value as an expected value. Components are **not** in this list.
4040

4141
## House patterns
4242

‎.claude/scripts/check-skill-publishability.test.mjs‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,6 @@ describe('skill checks', () => {
311311
});
312312
}
313313

314-
it('accepts a file nested in a bundle directory', () => {
315-
fixture.write('.claude/skills/alpha/references/nested/deep.md', '# Deep\n');
316-
317-
const { status, output } = fixture.check();
318-
319-
assert.equal(status, 0, output);
320-
});
321-
322314
it('walks a directory linked back up the tree once', () => {
323315
fixture.write('.claude/skills/alpha/references/nested/deep.md', '# Deep\n');
324316
symlinkSync('..', join(fixture.root, '.claude/skills/alpha/references/nested/loop'));

‎.claude/scripts/plugin-manifests.test.mjs‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,11 @@ describe('plugin marketplace checks', () => {
155155

156156
for (const { label, replace } of [
157157
{ label: 'a directory', replace: (readme) => mkdirSync(readme) },
158+
// The check reads only the entry's own type, never a link's target, so one link stands for every target.
158159
{
159160
label: 'a symbolic link to a file inside the skill',
160161
replace: (readme) => symlinkSync(join(fixture.root, '.claude/skills/alpha/SKILL.md'), readme),
161162
},
162-
{
163-
label: 'a symbolic link to a file outside the skill',
164-
replace: (readme) => symlinkSync(join(fixture.root, '.claude/skills/beta/SKILL.md'), readme),
165-
},
166-
{
167-
label: 'a symbolic link to nothing',
168-
replace: (readme) => symlinkSync(join(fixture.root, 'gone.md'), readme),
169-
},
170163
]) {
171164
it(`reports a README.md that is ${label}`, () => {
172165
const readme = join(fixture.root, ALPHA_README);

‎.claude/skills/typescript-code-and-test-standards/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Prefer the readable form wherever it costs nothing at runtime, and wherever the
191191

192192
**One test file per source file**, colocated and same-named, following whatever suffix the project already uses. No orphan test file without a same-named source beside it, no test file named after a function that lives in another file, and no second test file for one source.
193193

194-
Files typically exempt: static data modules, type-only modules, generated files, framework metadata or route manifest exports, and instrumentation entry points. Components are **not** exempt. Confirm the project's own exemption list rather than assuming this one.
194+
These typically get no test file: static data modules, type-only modules, generated files, framework metadata or route manifest exports, and instrumentation entry points. A test that only asserts a static data literal against itself adds no behaviour coverage; a test of code that consumes a module may still import its exported value as an expected value. Components are **not** in this list. Confirm the project's own list rather than assuming this one.
195195

196196
**Never:**
197197

‎.claude/skills/typescript-code-and-test-standards/agents/test-quality-reviewer.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ These do **not** qualify: a module that is merely slow, a module that is awkward
6565
- A test deleted or an assertion weakened in the diff, where the change is not a deliberate behaviour replacement stated as such.
6666
- A fallback added in production code that exists only to make a test pass.
6767
- An orphan test file with no same-named source beside it, or a second test file for one source.
68+
- A test file whose subject is a module the host project's rules exempt, such as static data, type-only, generated, framework metadata, or an instrumentation entry point.
6869
- A test that would still pass if the behaviour it names were broken. Break the behaviour in your head and ask which assertion fails; if none does, this is the finding.
6970
- Cases that cannot fail independently of one another, which lock in one behaviour under several names.
7071
- Setup or a fixture disproportionate to what the assertion reads, where most of the value built is never checked.

‎.claude/skills/typescript-code-and-test-standards/assets/project-rules.template.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Record the exact modules your tests are allowed to mock and what boundary each o
4040

4141
## Test file exemptions
4242

43-
Record which files in your project do not need a colocated test, and state explicitly which categories are **not** exempt.
43+
Record which files in your project get no colocated test, and state explicitly which categories are **not** exempt.
4444

4545
## Test patterns
4646

‎.claude/skills/typescript-code-and-test-standards/references/test-standards.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Where a source file has grown enough to want two test files, the signal is about
3434

3535
## Exemptions and why each one is exempt
3636

37-
Each of these is exempt because there is no behaviour to lock in, not because testing them is inconvenient:
37+
Each category gets no test file for the reason listed below. A test of code that consumes a module may still import its exported value as an expected value:
3838

3939
- **Static data modules.** A module that exports a literal has no code path. A test asserting the literal equals itself fails only when someone edits the data deliberately.
4040
- **Type-only modules.** They emit nothing. The compiler already checks them.
@@ -44,7 +44,7 @@ Each of these is exempt because there is no behaviour to lock in, not because te
4444

4545
**Components are not exempt.** They hold conditional rendering, event wiring, and prop handling, all of which are behaviour.
4646

47-
Confirm the host project's own exemption list before applying this one. A project that tests its data modules has a reason.
47+
Confirm the host project's own list before applying this one.
4848

4949
## The prohibitions
5050

@@ -54,6 +54,7 @@ Confirm the host project's own exemption list before applying this one. A projec
5454
- **Never assert the implementation back at itself.** A test that mirrors the code line for line fails only when the code changes shape, not when it breaks.
5555
- **Never type-assert an already-typed value.** Checking that a `string` is a string tests the compiler, and the compiler already ran.
5656
- **Never build a one-row table.** A table with one row is a loop that runs once, which is a plain test case written indirectly.
57+
- **Never write a test file for a module with no code path.** A test of static data asserts the literal equals itself and fails only when someone edits the data deliberately.
5758
- **Never add a fallback in production code to make a test pass.** A `?? defaultValue` inserted to satisfy an assertion moves a defect from the test into production.
5859
- **Never leave a test that would still pass if the behaviour it names were broken.** Break the behaviour in your head and ask which assertion fails. If none does, the test names something it does not check, and it will keep passing through the regression it was written to catch.
5960
- **Never write cases that cannot fail independently of one another.** Several cases breaking together lock in one behaviour, not several. The extra names cost a reader time and buy no coverage, and they make a single regression look like a suite-wide collapse.

‎.github/copilot-instructions.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ npm run build # Production build
3434

3535
- **One test file per source file**, colocated and same-named: `Banner.tsx` gives `Banner.test.tsx` (see `src/components/banner/Banner.test.tsx`). No orphan tests, no test file named after a function, no second test file for one source.
3636
- **Logic changes, bug fixes, and new features land with their tests in the same change.** Pure refactors need no new tests, but every existing test must still pass. A diff that skips or weakens a test is a behaviour change, not a refactor.
37-
- **Exempt** from needing a test: static data (`src/data/*`), type-only modules, metadata routes (`manifest.ts`, `robots.ts`), instrumentation entry points. Components are not exempt.
37+
- **No test file** for static data (`src/data/*`), type-only modules, metadata routes (`manifest.ts`, `robots.ts`), or instrumentation entry points. A test that only asserts a static data literal against itself adds no behaviour coverage. A consumer's test may import an exported value as its expected value. Components always get one.
3838
- **Never** skip, gut, or delete a failing test: read the test, read the source, fix the cause. No `it.skip`/`describe.skip`, no `expect(true).toBe(true)`, no assertions that restate the implementation, no `expect(typeof x).toBe('string')` on an already-typed value, no one-row `it.each` table, and never add a `?? fallback` in production code to make a test pass. Also never leave a test that would still pass if the behaviour it names were broken, write cases that cannot fail independently of one another, or build setup disproportionate to what the assertion reads.
3939
- **Do not mock.** Start from zero and add one only when the real dependency cannot run in the test. This covers every substitution technique: mocks, stubs, fakes, behaviour-replacing spies, hand-written doubles. A test whose collaborators are all mocked asserts only that mocks were called. Try first, in order: the real implementation with real inputs; passing the dependency in as an argument instead of replacing a module; a real fixture asserted on its real output; moving the assertion to where the seam is real, or into Cypress
4040
- **Never mock code that holds logic**, whoever wrote it: helpers, utilities, domain logic, components, hooks, constants, `src/data/*`. Never mock the subject under test, even partially
@@ -176,7 +176,7 @@ Not adopted: the ban on default exports (this repository uses them for the modul
176176
### Structure & Reuse
177177

178178
- **Count seven things on any file you write or review**, since no tool checks them, each with the threshold that backstops it: lines in the file (600), members of each exported type against how many a caller uses (15), files sitting **directly** in the directory (20, counted whatever subdirectories sit beside them, so one subdirectory does not make the loose files next to it grouped), occurrences of a repeated block (3, counting test cases too, where three differing only in a value are one table-driven case), files repeating one declaration (3), parameters a function branches on rather than operates on (more than one, and only on a utility, meaning one named for a single operation or exported for general use rather than one coordinating a sequence, which takes its modes legitimately), and the shape of each function body as three numbers together (lines, nesting depth, widest expression), which is the one unit the other six never reach inside. Name the principle a structural finding violates rather than describing it: single responsibility, control coupling for a branched-on parameter, common coupling for shared mutable module state, content coupling for reaching past an interface, stamp coupling for a whole record where a field would do, dependency inversion, interface segregation, or DRY. Those numbers apply where every sibling is equally large; the sharper test is being an outlier in this tree, stated against what it is measured on. A count triggers a look and is never a finding alone; what makes it one is the concrete split
179-
- **A component gets a directory, not a loose file**: kebab-case directory under `src/components/`, PascalCase file, colocated test, as `navbar/Navbar.tsx` does. Eight of the nine spell it that way, and `Stars/` is the single PascalCase exception rather than a second convention: match the eight. Related files are grouped into a subdirectory rather than left flat, and entries sharing a name prefix are the group to propose. Detect the scheme the tree uses; never impose a methodology
179+
- **A component gets a directory, not a loose file**: kebab-case directory under `src/components/`, PascalCase file, colocated test, as `navbar/Navbar.tsx` does. Eleven of the twelve spell it that way, and `Stars/` is the single PascalCase exception rather than a second convention: match the eleven. Related files are grouped into a subdirectory rather than left flat, and entries sharing a name prefix are the group to propose. Detect the scheme the tree uses; never impose a methodology
180180
- **A setting the tooling reads from configuration is set once, never per file.** `jest.config.js` already sets `testEnvironment: 'jsdom'` for every test, so only the minority that needs another environment carries a `@jest-environment` docblock (tests that build a fetch `Request` or `Response` run in `node`, because jsdom has neither), and path aliases live in `tsconfig.json` mirrored into `jest.config.js` rather than re-declared per import. Where the same directive would go into three or more files, **search for the key, not for the directive's own spelling**, since the two are rarely the same word, then hoist the majority and leave the minority declared, counting the majority over every file the setting governs rather than over the files in front of you
181181
- **Reuse before writing.** Before hand-writing behaviour that has a name outside this repository (a wire format, a version-ordering rule, a retry schedule, a cryptographic construction), check three sources in order and say which you read: this repository's own `helpers` and `util` modules, then `package.json` and the lockfile, which lists what is resolved where the manifest lists only what was asked for, then the standard library and the platform. Read what the modules a file already imports export before accepting a hand-written block beneath them, since hand-rolling half of what the file imports is the shape this misses most often. The tell is vocabulary: code spelling a specification's own field names is implementing that specification whatever the function is called. Where nothing present provides it, say so and stop rather than adding a dependency. **Never hand-roll anything that signs, verifies, encrypts, hashes a credential, or settles an authorization outcome.** A test building a value by hand to exercise a rejection path is not this finding
182182

0 commit comments

Comments
 (0)