Command Palette

Search for a command to run...

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

model-based-testing

БесплатноЗапускает вложенные скриптыНе проверен

Write model-based tests with @xstate/test 2.0 beta, replace end-to-end tests with model-based tests without losing coverage, and visualize the model in…

statelyaiот statelyai★ 86 звёзд на GitHub

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

Model-based testing

Rules:

  • Read the docs that ship with the installed packages before writing code.
  • Show the model in Stately after every change.
  • Report only runs, coverage, and parity results that happened.
  • Delete a legacy test only after its parity entry passes the check and its negative controls.

Set up

  1. @xstate/test 2.x requires xstate 6. With no xstate, propose @xstate/test@beta xstate@beta fast-check as dev dependencies and say they are betas. With xstate 5, ask before upgrading, or put the model tests in a separate workspace package with xstate@beta.

  2. Read node_modules/@xstate/test/README.md (API) and node_modules/xstate/docs/model-based-testing.md. Write the machine in v6 syntax (node_modules/xstate/docs/agents.md or the xstate-v6 skill). If the packages are not installed, read the tarballs:

    dir=$(mktemp -d) && cd "$dir" && npm pack @xstate/test@beta xstate@beta && for f in *.tgz; do mkdir "${f%.tgz}" && tar xzf "$f" -C "${f%.tgz}"; done
    
  3. Use testPaths in CI (@xstate/test/paths needs no fast-check). Add propertyTest with until when payloads, ordering, or timing matter, or the graph is too large to enumerate. Use createPlaywrightSut for web pages.

Known issues in 2.0.0-beta.3 (check for a fixed release first):

  • failures works only with testPaths from @xstate/test (needs fast-check). From @xstate/test/paths it throws failureStore.load is not a function.
  • With @playwright/test 1.64+, createPlaywrightSut(page) fails to type-check (tracing.start() returns Promise<Disposable>). Pass page as Page & PlaywrightPage. Playwright does not type-check tests, so run tsc --noEmit.
  • A function transition (E: ({ context }) => ...) has one coverage id for all of its branches, so transitions: 1 passes when one branch ran. Give each branch a distinct target state and gate on stateNodes: 1, or check the branches in the coverage viewer.
  • A transition function whose branches return different shapes can widen literals ('existing' to string) and fail createMachine overloads. Add as const.

Write a model test

  1. Write the model from requirements and existing tests, not from the code under test. Mark parts taken from code and ask the user to confirm them.
  2. Model only what a user can see and do, one machine per set of screens a user can move between. Declare meta: types<{ requirements?: string | string[] }>() in schemas to use meta.requirements. Write each target literally in the transition, not in a helper, and start a transition function with its if, so the diagram draws each branch. Check that it does before trusting viewer counts.
  3. Visualize the model and confirm it with the user before writing the SUT.
  4. projectModel(snapshot) and read() return the same shape, containing only what the UI shows. If the UI depends on the pointer (hover), move the pointer to a neutral spot after every event except hover events. read() uses non-waiting calls (count, allTextContents), so a missing element is an observation, not a timeout. Keep transient UI such as toasts out of the projection, or make sure settle() returns before it disappears.
  5. The SUT resets in create() (Playwright: reset), waits in settle(), and stubs the network per event case with mocks or outcomes. Every path must start from the same app state. Decide what the reset covers (browser storage, server data, inboxes or other side channels the test reads) and how: fresh data with unique values per path, or a restored snapshot. For history, storage, and session tests, use a fresh browser context per path. Close it in dispose. Wait for an observable outcome or app readiness signal before comparing an observation.
  6. Model an input by its kind in cases ({ username: 'empty' }, { username: 'tooLong' }) and let the SUT supply concrete values, such as the path's own user data.
  7. Bound growing context with stopWhen or serializeState. Keep context that changes enabled transitions, observations, or required history. Count paths before attaching a browser. testPaths without a SUT returns coverage and results with zero SUT comparisons. Use the path count to size the browser test timeout.
  8. Gate with assertTestCoverage(coverage, { transitions: 1, stateNodes: 1, unknown: 'fail' }). Use unknown: 'fail' in coverage-based propertyTest stop conditions too, then assert coverage after the run. With older packages, explicitly check that coverage.transitions.unknown and coverage.stateNodes.unknown are empty. Check required named event cases and require positive coverage.sutComparisons when using projections. On versions that support it, set sutComparisons: 1 in assertTestCoverage. Use `failur
Полный SKILL.md на GitHub

Установить model-based-testing в Claude Code и Claude Desktop

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

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

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

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

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

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

Вложенные файлы

README.mdevals/evals.jsonreferences/parity-ledger.mdscripts/coverage-viewer.mjsscripts/parity-check.mjsscripts/parity-check.test.mjs

FAQ

Что делает скилл model-based-testing?

Write model-based tests with @xstate/test 2.0 beta, replace end-to-end tests with model-based tests without losing coverage, and visualize the model in Stately. Use for model-based testing, @xstate/test, generating tests from a state machine, testing every path, replacing Playwright, Cypress, Vitest, or Jest end-to-end tests with a model, coverage parity, or migrating from @xstate/test 0.x or 1.0 beta.

Как установить скилл model-based-testing?

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

Скилл model-based-testing запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

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

Сравнить model-based-testing с