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★ 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
@xstate/test2.x requiresxstate6. With noxstate, propose@xstate/test@beta xstate@beta fast-checkas dev dependencies and say they are betas. Withxstate5, ask before upgrading, or put the model tests in a separate workspace package withxstate@beta.Read
node_modules/@xstate/test/README.md(API) andnode_modules/xstate/docs/model-based-testing.md. Write the machine in v6 syntax (node_modules/xstate/docs/agents.mdor thexstate-v6skill). 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}"; doneUse
testPathsin CI (@xstate/test/pathsneeds no fast-check). AddpropertyTestwithuntilwhen payloads, ordering, or timing matter, or the graph is too large to enumerate. UsecreatePlaywrightSutfor web pages.
Known issues in 2.0.0-beta.3 (check for a fixed release first):
failuresworks only withtestPathsfrom@xstate/test(needs fast-check). From@xstate/test/pathsit throwsfailureStore.load is not a function.- With
@playwright/test1.64+,createPlaywrightSut(page)fails to type-check (tracing.start()returnsPromise<Disposable>). Passpage as Page & PlaywrightPage. Playwright does not type-check tests, so runtsc --noEmit. - A function transition (
E: ({ context }) => ...) has one coverage id for all of its branches, sotransitions: 1passes when one branch ran. Give each branch a distinct target state and gate onstateNodes: 1, or check the branches in the coverage viewer. - A transition function whose branches return different shapes can widen
literals (
'existing'tostring) and failcreateMachineoverloads. Addas const.
Write a model test
- 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.
- 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[] }>()inschemasto usemeta.requirements. Write eachtargetliterally in the transition, not in a helper, and start a transition function with itsif, so the diagram draws each branch. Check that it does before trusting viewer counts. - Visualize the model and confirm it with the user before writing the SUT.
projectModel(snapshot)andread()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 suresettle()returns before it disappears.- The SUT resets in
create()(Playwright:reset), waits insettle(), and stubs the network per event case withmocksoroutcomes. 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 indispose. Wait for an observable outcome or app readiness signal before comparing an observation. - 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. - Bound growing context with
stopWhenorserializeState. Keep context that changes enabled transitions, observations, or required history. Count paths before attaching a browser.testPathswithout a SUT returnscoverageandresultswith zero SUT comparisons. Use the path count to size the browser test timeout. - Gate with
assertTestCoverage(coverage, { transitions: 1, stateNodes: 1, unknown: 'fail' }). Useunknown: 'fail'in coverage-basedpropertyTeststop conditions too, then assert coverage after the run. With older packages, explicitly check thatcoverage.transitions.unknownandcoverage.stateNodes.unknownare empty. Check required named event cases and require positivecoverage.sutComparisonswhen using projections. On versions that support it, setsutComparisons: 1inassertTestCoverage. Use `failur
Установить model-based-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
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 запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic