Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

writing-tests

БесплатноБез исполняемых скриптовНе проверен

How to write tests in the Portable Text Editor monorepo. Use whenever writing or editing tests in PTE packages. Covers test placement, harnesses…

portabletextот portabletext★ 290 звёзд на GitHub

Об этом скилле

Writing PTE tests

Test placement

Before writing any test, find its existing home. Always search for an established suite covering the domain (ls tests/ | grep -i <topic>, rg -l <mechanism> tests/) and read its scenario list before creating a file. The canonical suites are broad (behavior-api.test.tsx carries 30+ Behavior contract scenarios); a contract pin belongs next to its siblings, where reviewers and future failures will look for it. A new file is the exception, for a genuinely new domain, not the default. Also check whether the contract is already pinned in a different form before adding it at all.

The file extension is the discriminator, never a .browser suffix:

  • *.test.tsx runs in the browser project (playwright: chromium, firefox, webkit)
  • *.test.ts runs in the unit project (node)
  • *.test-d.ts is type-level, using expectTypeOf from vitest
  • gherkin-tests/*.feature + racejar for behavior specs (Feature({featureText, stepDefinitions, parameterTypes}))

When scaffolding a new package, mirror plugin-paste-link's vitest config: a browser project including src/**/*.test.tsx and a unit project including src/**/*.test.ts.

Choosing the form

  • When textspec can state the case (the document and selection before, the action, the document and selection after), write it as a Gherkin scenario using the existing steps. Editor scenarios go in gherkin-spec/, plugin scenarios in a .feature next to the plugin source.
  • When textspec can't state it (emitted events or patches, paths, or anything else outside the notation), write a plain test with every value written out, even when that makes the file long. Don't bend a scenario to fit by adding steps that take or check JSON.
  • No .each whose rows are built by helpers. A table of fixture builders, path builders and wrappers makes the reader assemble each case in their head. Write each case out as its own test.

Harnesses

  • Editor integration tests: createTestEditor from @portabletext/editor/test/vitest (inside the editor package: ../src/test/vitest). Returns {editor, locator}. Plugins and probes go in as children, but note they mount as siblings after PortableTextEditable; a provider that must wrap the editable needs a hand-rolled render with a comment explaining why.
  • Selector/pure-function tests: createTestSnapshot (in the editor package: test-utils/create-test-snapshot; in plugins: duplicate it locally on public types, it is ~30 lines).
  • Keys: always createTestKeyGenerator from @portabletext/test. It is deterministic (k0, k1, ...), which is what makes full-literal assertions possible. Generated keys may be asserted literally.

Triggers

  • Real user interaction via userEvent (userEvent.type(locator, 'foo')). Typing with no caret set lands at the block start.
  • Everything else via editor.send({type: ...}) with full payloads. This includes native-shaped events: drag.dragover, drag.drop etc. accept complete position/dragOrigin/originEvent objects, so no DOM event simulation is needed to test a behavior.
  • The exception is a test of the editable's own handling of a native event that userEvent cannot produce, such as a beforeinput input type keyboard input never fires. Set a real DOM selection and dispatch the real event on the editable (new InputEvent('beforeinput', {inputType, bubbles: true, cancelable: true})).
  • Wait for content to render before focusing or selecting in it. A focus or select sent straight after inserting blocks can land before the DOM exists and fail silently.
  • Async settling via vi.waitFor around the assertion that proves the trigger landed. Debounced channels (the mutation batcher) need their own vi.waitFor; comparing them synchronously after another assertion passes is a race.
  • Every DOM query goes inside the retried callback. A querySelector run once before vi.waitFor is never re-run, so the wait checks the same stale element or null on every retry.
  • A lone locator assertion is awaited directly: await expect.element(locator).toBeVisible(), not wrapped in vi.waitFor. expect.element already retries until its own timeout, and the wrapper cuts that to vi.waitFor's 1s default. Pass a longer timeout to expect.element itself (expect.element(locator, {timeout: 10_000})).
  • Never sleep (setTimeout, arbitrary delays), even for negative asserts. To prove "nothing was emitted", create a deterministic flush point: perform a local edit through the same ordered channel and assert the full emission list contains exactly that edit's patches, a would-be echo would have to surface no later than the edit's own emission. This also upgrades the negative assert to a full-value pin. The only exception is a wait with no observable signal to anchor on, such as a real IME sequence driven through CDP, and it carries a comment naming the missing signal.
  • Simulated races are event-driven, never clock-driven. To reco
Полный SKILL.md на GitHub

Установить writing-tests в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл writing-tests?

How to write tests in the Portable Text Editor monorepo. Use whenever writing or editing tests in PTE packages. Covers test placement, harnesses, deterministic fixtures, and the house assertion style (no indirection, full values with toEqual).

Как установить скилл writing-tests?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл writing-tests запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить writing-tests с