tests/checkout.test.yaml in the same diff, and CI runs that version of the
test against that branch’s preview deployment. Reach for this setup when the
tests must match the branch, not main.
Where the tests live
Put the tests in one directory at the root of the project, or next to the app in a monorepo:momentic.config.yaml sets the project and the test discovery globs. Run
npx momentic init in that directory to create it, or copy one from another
app. In a monorepo with several apps, each app keeps its own
momentic.config.yaml, and a momentic.workspace.yaml at the repository root
lists them as workspaces.
apps/shop/momentic.config.yaml
The test
A test is a plain YAML file. Keep the shared steps, such as logging in, in a module that the tests import:apps/shop/tests/checkout.test.yaml
url is the default target. CI overrides it per branch with
--url-override, so the same file runs against the preview deployment of any
branch.
Run the branch’s tests locally
Before you push, run the tests that your change touches from the app directory:--ai-select reads the diff between your branch and origin/main and picks the
tests that cover the changed code. Pass a path
(npx momentic run tests/checkout.test.yaml) to run one test, and --start to
boot the dev server first. See
momentic run.
Run the branch’s tests in CI
The workflow checks out the branch, so the tests it runs are the ones in the pull request, and it waits for the preview deployment before it starts. The example uses GitHub Actions with a provider that posts a GitHub deployment, such as Vercel:.github/workflows/branch-tests.yml
- The
ifguard runs the job for a ready preview deployment only.Previewis the environment name Vercel posts; use your provider’s name, so a production deployment does not start the tests. actions/checkoutputs the branch’s YAML in the job, so a test edited in the pull request runs in its edited form.--url-overridepoints every test at the preview URL of the deployment that triggered the job.--upload-resultsattaches the run to the dashboard, so a failed check links to the video, the screenshots, and the trace of the failing step.MOMENTIC_API_KEYis a repository secret. See GitHub Actions.
Run the whole suite on main
The pull request job runs a subset. Run every test on each merge tomain, or
on a schedule, against staging:
.github/workflows/regression.yml
momentic run step without --ai-select, and add a matrix with
--shard-index ${{ matrix.shard }} --shard-count 4 to split the suite across
jobs. See Common CI setups for the full workflow.
Notes
- A test that a coding agent writes on the branch runs in the same job. The agent commits the YAML, CI runs it, and the structured failure comes back on the pull request. See Momentic MCP server.
--ai-selectneeds the full Git history in CI. Withoutfetch-depth: 0the diff againstorigin/mainis empty and no test is selected.- Quarantined tests still run but do not fail the check by default. See quarantine.