agentleFS
naomiaronaomiaro/waveform-playlist/.claude/skills/unit-testing/SKILL.md

unit-testing

Skill1.7k starsChanged yesterdayMITView on GitHub

Use when writing, changing or debugging a vitest unit test in packages/ - mocks, fake timers, jsdom or happy-dom, mounting providers or dnd-kit components, StrictMode, counting renders, a test that passes for the wrong reason, a throwaway probe test - and when a downstream package's tests seem to run old behaviour.

22 other projects use a version of this.

Trending

Quiet this year.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the naomiaro/waveform-playlist repository that our weekly crawl found: only 11 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Most recently taken up by

Who's talking about naomiaro/waveform-playlist

The biggest 5 of 11 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 11

Talked about on GitHub, Stack Overflow and Hacker News (11 times).

On GitHub · 8

3 more on GitHub

On Stack Overflow · 2

On Hacker News · 1

Used with

Projects with it also use database-testing, contract-testing and 4 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • petrkindlmannSkill

    database-testing

    Validate database integrity, test migrations forward and backward, verify schema constraints, manage seed data, detect migration drift, and identify query performance issues. Covers PostgreSQL, MySQL, MongoDB with Prisma, TypeORM, Drizzle, and SQLAlchemy, plus Testcontainers test databases. Use when: "database test," "migration test," "migration rollback," "rollback test," "data integrity," "SQL test," "schema validation," "seed data," "query performance," "Testcontainers." Not for: synthetic data generation/masking at scale — use test-data-management; Docker/IaC test-environment provisioning — use test-environments; SQL injection — use security-testing. Related: test-data-management, test-environments, security-testing, ci-cd-integration.

    Also in 3 projects that use this

  • petrkindlmannSkill

    contract-testing

    Implement consumer-driven contract testing with Pact-JS (v16). Covers consumer test writing, broker-driven provider verification, Pact Broker setup, can-i-deploy as a deployment gate, webhook-triggered verification, pending pacts, and schema-first vs consumer-first approaches (OpenAPI/Ajv, Schemathesis). Use when: "contract test," "Pact," "consumer-driven," "API contract," "provider verification," "can-i-deploy." Not for: stubbing or mocking a dependency to isolate a test — use service-virtualization; general REST/GraphQL endpoint assertions against your own API — use api-testing. Related: api-testing, service-virtualization, ci-cd-integration, test-environments.

    Also in 3 projects that use this

  • jarosser06Skill

    test-strategy

    Plans pytest test strategies for Drift's 90%+ coverage requirement using coverage analysis, edge case identification, and test suite design. Use when determining what tests to write, analyzing coverage gaps, or planning test strategies.

    Also in 4 projects that use this

  • etewiahSkill

    e2e-testing

    Playwright E2E testing and Lighthouse performance auditing. Use when setting up E2E tests, running Playwright tests, performing Lighthouse audits, or debugging E2E test failures.

    Also in 4 projects that use this

  • Microsoft AzureSkill

    release-readiness

    Complete ODIN release documentation and validation checks before declaring user-visible work complete, preparing a release, or opening the Release-to-main pull request.

    Also in 3 projects that use this

  • Microsoft AzureSkill

    git-workflow

    Squad branching model: dev-first workflow with insiders preview channel

    Also in 4 projects that use this

The file

Files
SKILL.md

Unit tests (vitest)

Run from the package directory, in a subshell: (cd packages/<pkg> && npx vitest run). A test run is its own command, read before any commit (root CLAUDE.md). To check that a new test can fail, see the skill mutation-testing. Package-specific test notes: packages/browser/notes/testing.md (templates for mounting the providers and the view under jsdom), packages/dawcore/notes/testing.md (happy-dom and Lit), and the "Testing" paragraphs of the other packages' CLAUDE.md.

vitest

  • vitest does NOT typecheck — it transpiles TS without type errors, so a test with a wrong/missing prop passes RED→GREEN and only fails pnpm typecheck (which covers src/__tests__). Run typecheck after adding tests, not just vitest.
  • Packages do not share a compile target. A regular expression with the s flag (/a.*b/s) type-checks in core and engine tests and fails in browser with TS1501 (flag needs ES2018). In a test that may be copied between packages write [\s\S]*.
  • vitest 4+: a mock called with new must be implemented with function/class, never an arrow — vi.fn(() => x) / .mockImplementation(() => x) / .mockImplementationOnce(() => { throw … }) throw … is not a constructor when production code does new Mocked(). A loose .toThrow() then passes on that TypeError instead of the intended error — grep test output for did not use 'function' or 'class'. Type mocks as Mock<Sig> / MockInstance<typeof fn> (bare ReturnType<typeof vi.fn> is Mock<Procedure | Constructable>, not assignable to a callback type), and use mock.lastCall, not mock.calls.at(-1) (repo lib is ES2020; .at only type-checked via an @types/node 20 shim that v24 dropped).
  • vitest -t is a REGEX, not a substring — -t 'play() after' matches nothing (the () is an empty group). Filter on a paren-free fragment of the test name.
  • Fake timers + a promise that rejects: attach expect(p).rejects… BEFORE vi.advanceTimersByTimeAsync, or vitest reports an unhandled rejection for the gap.
  • vi.stubGlobal('process', undefined) tests code that must survive a page with no process (engine's isDevelopmentBuild).
  • it.each([...] as const) whose rows hold a function can fail typecheck with TS7024. Type the table as an explicit array.
  • Vitest cleanup: npx vitest run in pnpm monorepos can leave orphaned Node processes at ~100% CPU. After running tests across multiple packages, verify with pgrep -f vitest and kill strays with pkill -f vitest if needed.
  • Downstream tests resolve engine via dist/, not source (likewise dawcore-wam's transport integration test → pnpm --filter @dawcore/transport build first): after changing engine behavior (not just types), run pnpm --filter @waveform-playlist/engine build before running browser/dawcore vitest, or they exercise the OLD behavior (a RED-check against unbuilt source gives a false pass). The dawcore/browser packages' own source is transformed from TS on the fly by vitest, so changes within those packages need no rebuild.

jsdom and React

  • Mounting dnd-kit-backed components under jsdom needs a ResizeObserver stub imported FIRST — @dnd-kit/dom references it at module-load time. Each package has src/__tests__/jsdom-polyfills.ts (browser, ui-components, annotations); import it before anything else. annotations has no vitest config (node env default) — add // @vitest-environment jsdom per file.
  • Do not press a dnd-kit draggable element in a jsdom test. dnd-kit puts role="button" and aria-roledescription="draggable" on it at an unpredictable moment after mount, and ClipView's mouse-down handler ignores presses on a draggable. A test that pressed [data-clip-container] (the draggable itself when clip dragging is off) passed 5 runs in 6. Run a new jsdom interaction test several times before trusting it, alone with -t as well as in its file: this one failed every time alone.
  • Counting React renders in a unit test: vi.mock('@waveform-playlist/ui-components', async (importOriginal) => …) returning { ...actual, Clip: (props) => { count++; return createElement(actual.Clip, props); } }, with the counters in vi.hoisted. A wrapper counts its parent's renders, not renders its inner component gets from a context, so count a child the component renders unconditionally (SmartChannel for ChannelWithProgress). Template: browser's visualizationMemoBoundaries.test.tsx.
  • StrictMode in a hook test: renderHook(fn, { wrapper: StrictMode }), never a function that returns <StrictMode>. With the function form the hook's effects are NOT double-invoked (measured: 1 setup against 2), so the test passes without the fix it is meant to guard. Two effects-hook tests had been vacuous this way; useDynamicTracks dropped every decode under StrictMode (a cancelled flag set in the cleanup and never cleared on setup) with no test noticing.
  • A warning that is written once per page needs a reset between tests. warnMisplacedPart remembers its messages in module state, so the second test in a file that expects the same message sees none; resetPartWarnings() in afterEach.
  • jsdom: fireEvent.click on a disabled input still toggles it. Use the element's own click(), which honours disabled as a real click does.
  • A test in annotations can mount the real providers from browser's dist: createAdapter / createPlayout fakes, and waveformData: { sample_rate, duration } is enough for MediaElementPlaylistProvider when nothing draws.
  • React's <Profiler onRender> did not fire in jsdom for a context-triggered re-render that changed no DOM. To count such renders, put a component that reads the same hook in the tree and count its calls.
  • jsdom has no canvas.transferControlToOffscreen. Stub it on HTMLCanvasElement.prototype to test SpectrogramChannel's registration (SpectrogramChannelHeight.test.tsx).
  • jsdom has no layout: a click test passes on an area of zero height. Assert the inline height that gives the area its size, and call the click test a control.
  • An early return that removes a component a test counts makes "it did not render" vacuous. WaveformAnnotationBoxes returns null without the annotation integration; waveformPartsQuietShell.test.tsx mounted without it and asserted counts.boxes === 0. After adding an early return, grep the tests that count that component and give them what it needs to render.
  • dnd-kit's aria-roledescription="draggable" is not there in a jsdom render, so "it is absent" proves nothing. On #853 a placeholder test asserted the attribute was missing on the header; a reviewer's probe found 0 matches in 48 renders, loaded and draggable clips included. Assert what the component itself draws: the [data-clip-id] handle and the [data-boundary-edge] handles, with a loaded clip in the same test that HAS them.
  • styled-components rules are injected under jsdom: getComputedStyle(el).opacity reads a value that comes from a themed template ('0.5'), and '' when no rule sets it (clipPlaceholderOpacity.test.tsx in ui-components). A positive value can only pass when the rule was injected, so such an assertion is not vacuous.
  • jsdom's Blob has no arrayBuffer(). A test of code that reads a File or Blob adds the method on the instance (loadMidiTracks.test.ts); the test then proves the code calls it, nothing about a browser's Blob.

What a test proves

  • Throwaway probe tests: to observe real provider behaviour (adapter calls, cursor position) before deciding on a fix, write a scratch zz*.test.tsx in the package's __tests__, have it appendFileSync its observations to a scratch file (vitest's reporter hides console.info from a grepped run), run it, then delete it and confirm git status --short is clean. To prove a new test is RED without the fix: git stash push <the one source file>, run the test, git stash pop. Read WHY it failed: when the stashed file depends on something else the branch changed (a field removed from a context), the old file fails for that reason and proves nothing; git checkout main -- <file> after committing, then git checkout HEAD -- <file>, has the same trap. And when two changes each make a test pass (a guard plus a recovery path), reverting one leaves it green; say so rather than claim the test covers it.
  • A sentence that says a component "ignores X" needs a test that passes X in the form that reaches the other branch. SmartChannel was documented as ignoring renderMode for a clip with notes, and its test passed renderMode="spectrogram" without the spectrogram props, so it never entered the spectrogram branch that came first (#763, first review). Order the branches so the claim is true, and give the test every prop the competing branch requires.
  • Counting calls on an internal object of another package: vi.mock('@waveform-playlist/core', async (importOriginal) => …) returning the real module with one factory wrapped (the real createSourceLoader with setWanted and provide counted through vi.hoisted counters; arrangementSources.test.ts in engine).
  • When pinning an order, pin what each party can observe at each step. A statechange count and a call-order test passed while state read from INSIDE an adapter method was a version ahead (#845 review). For a per-change adapter contract, a replay() helper that keeps the set of track ids the adapter holds and records "told about a track it already has / does not have" as faults is easier to keep right than exact call lists (arrangementEdges.test.ts in engine).
  • Two ways a new test passes against the old code (#782). A fake that settles only the LATEST pending promise cannot show that an earlier call was cancelled: keep every pending call and settle them one by one. And in Node a DOMException is an Error, so instanceof Error (or a .toThrow() with no argument) does not tell an AbortError from a real failure: assert on name. Break the guarded line for every new test before the first review, tests in other packages (the engine) included.
  • A test on an element's inline style does not show the element is visible. A new theme key was applied to a background that an opaque wrapper covered; the unit test passed and a reviewer found it (#689). For a colour or size option, check what is on top (document.elementFromPoint, the computed style of the topmost element) in a browser with a non-default value.
  • Check that a test's fixture cannot satisfy the assertion by another route. A unit test for "Play plays the selection and stops at its end" used the selection 2 to 4 s over annotations 0 to 2 and 2 to 4; with the selection logic broken, playback still stopped at 4 s because the annotation ended there (found by the mutation run on #688 part 2). Choose ranges that coincide with nothing else in the fixture.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.