Skip to content

Get started on your computer

In this tutorial we’ll install Varar into a project, configure it, run a first oath, and then deliberately break it. By the end you will have seen an oath pass and fail as a test on your own machine.

Pick your preferred programming language in the language selector in the top-right corner of the page. Every command and code sample below follows that choice.

You need your language’s toolchain already installed — Varar adds a library and a test-framework adapter to a project you can already build and test.

Node.js 22.18 or newer. Node strips TypeScript types by itself from 22.18 on. Older versions fail the run with 'Unknown file extension ".ts"', and need NODE_OPTIONS=--experimental-strip-types.

  1. Install

    Terminal window
    pnpm add -D @varar/varar @varar/cli

    This adds Varar’s author API (the package your step definitions import) and the adapter that runs oaths in your test framework.

  2. Configure

    Varar is configured by one file, varar.config.json — the single source of truth for which Markdown files are oaths and which files bind their steps. Ports with a varar CLI scaffold it (and a working example) in one command; on the others you create it by hand.

    Terminal window
    pnpm exec varar init

    One command writes the config and a working example oath:

    created varar.config.json
    created varar/deep-thought.md
    created src/varar/deep-thought.steps.ts
    updated package.json (added "type": "module")

    varar.config.json decides which Markdown files are oaths and which files bind their steps:

    varar.config.json
    {
    "docs": { "include": ["varar/**/*.md"], "exclude": [] },
    "steps": ["src/varar/**/*.steps.ts"]
    }
  3. A first oath

    The example oath is plain Markdown with one concrete example — varar init already wrote it for you; if your port has no CLI, create it now, in the varar/ directory your config’s docs globs match:

    varar/deep-thought.md
    # Deep Thought
    You're really not going to like it.
    The answer to the great question of life, the universe and everything is 42.
    It was a tough assignment.

    Notice there are no keywords and no special syntax — it’s ordinary Markdown prose. One sentence makes a checkable claim; Varar matches that phrase, and everything around it is just documentation for the reader.

    The steps file binds that sentence to code. A sensor reads the software and returns what it actually produced, for Varar to compare against the number in the Markdown:

    src/varar/deep-thought.steps.ts
    import { steps } from '@varar/varar'
    const { sensor } = steps()
    sensor('life, the universe and everything is {int}', () => 42)
  4. Run it

    Terminal window
    pnpm vitest run

    Varar reports one example passing:

    varar/deep-thought.md
    ✓ Deep Thought
    1 example, 1 passed, 0 failed

    pytest, RSpec, JUnit, cargo test, dotnet test and go test each report the same example passing in their own format. The Markdown file just ran as a test, and the software kept its word.

  5. Watch it fail on purpose

    Never trust a test you haven’t seen fail. Open the steps file and change the answer the sensor returns from 42 to 43:

    sensor('life, the universe and everything is {int}', () => 43)

    Run Varar again. The example now fails: the oath still says 42, but the sensor observed 43. The output shows both values and points at the exact 42 in the Markdown where the promise broke.

    Revert the change and run once more — one example, one passed. You have seen both sides of the contract.