← Blog

Browser-free test runs for coding agents: a fast tier to run on every edit, and a browser tier to leave for CI

How to split a project's tests so a coding agent's loop never needs a real browser: node and DOM-emulated tests first, browser end-to-end tests last. Vitest projects, jsdom and happy-dom limits, pytest markers, Node's test runner, Playwright tags and go test -short, plus how to make a filtered run fail loudly instead of passing by running nothing.

Short answer: Give the agent one command that runs the tests that need no browser, and keep the real-browser tests for CI or a person. The agent then gets a verdict on every edit from a Node, Python or Go process, and a Node or Python process is what a sandbox’s default image is built for. The split costs you something, so this post says what the fast tier cannot see and how to stop a filter from quietly selecting nothing.

Sources, read in November 2026: the docs of Vitest (projects, environments and CLI), jsdom, Jest, pytest (marks and exit codes), Node’s test runner, Playwright (tags and CLI) and Go’s testing package; Sandscale’s CLI reference.

Three tiers

  1. Logic tests. Functions, parsers, reducers, API handlers. They run in plain Node, Python or Go and need no DOM.
  2. DOM-emulated tests. Component tests that need document and window, run in Node against an emulation. jsdom and happy-dom are the usual ones.
  3. Browser tests. End-to-end tests and anything that depends on layout, real navigation or a browser’s own behaviour.

The agent’s loop wants tiers 1 and 2. Tier 3 belongs in CI, or in a run you start on purpose. We make no claim in this post about running a browser in a sandbox; the point is that the loop does not need one.

What tier 2 cannot see

An emulated DOM is a subset, and the projects say so themselves. jsdom’s README lists two major features outside its scope: navigation, and layout, which affects methods such as getBoundingClientRects() and properties such as offsetTop. It adds that jsdom returns zeros for many layout-related properties and emits a “not implemented” error to its virtual console for navigation. Without the optional @napi-rs/canvas package, <canvas> elements behave like <div>s.

happy-dom is described in Vitest’s environment docs as lacking some APIs, and the part of Vitest’s CLI reference that covers its doctor command, which can try happy-dom in place of jsdom, warns that tests depending on layout or navigation should be verified before adopting the swap.

So a green tier 2 means the component logic and markup behave as the test expects in an emulation. It does not mean the page looks right or that a real click navigates. Keep that sentence in the agent’s instructions; see below.

Choose a tier per runner

Vitest

Vitest’s environment option picks node (the default), jsdom, happy-dom or edge-runtime, and a // @vitest-environment jsdom comment at the top of a file overrides it for that file. For project-wide splits, define projects with names:

// vitest.config.ts
import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    projects: [
      { test: { name: 'unit', environment: 'node', include: ['src/**/*.unit.test.ts'] } },
      { test: { name: 'dom', environment: 'jsdom', include: ['src/**/*.dom.test.ts'] } },
    ],
  },
})

Vitest’s docs recommend naming inline projects, and project names must be unique. If you also have a browser-mode project, Vitest’s environment page says browser mode is not an environment and should be its own project. The CLI can then leave it out, using the negation syntax from the CLI reference:

vitest run --project '!browser'

The reference says a project runs if it matches no negated pattern, and that you can combine patterns, as in --project 'unit*' --project '!unit (browser)'. Replace browser with whatever you called that project.

Jest

Jest picks the environment with testEnvironment. Its jsdom environment is the separate jest-environment-jsdom package, which the configuration docs name next to jest-environment-node. Split by file name or folder, and keep browser tests out of the Jest run altogether.

Node’s test runner

node --test runs the built-in runner, and --test-skip-pattern skips tests whose names match a regular expression (patterns can be given more than once). That is a name filter, so it only works if you name browser-dependent tests consistently. Separate directories are sturdier.

pytest

Register a marker and deselect it:

# pytest.toml
[pytest]
markers = [
  "browser: needs a real browser (deselect with '-m \"not browser\"')",
]
addopts = ["--strict-markers"]
pytest -q -m "not browser"

pytest’s marker documentation shows registering custom marks in configuration and the -m "not slow" form for deselecting one. It also describes --strict-markers, which turns an unknown mark into an error, so a typo in a marker name fails instead of silently running or skipping the wrong thing. The TOML in the example has the shape that page shows; if your project keeps pytest’s configuration in pytest.ini or pyproject.toml, use the form that file expects (the same page shows an ini version).

Playwright

Playwright’s test CLI has --grep and --grep-invert, and its tags start with @. If your end-to-end tests are Playwright tests, they are tier 3 by definition: the agent’s fast command does not call them. If you want the agent to run one on request, tag it and select by tag:

npx playwright test --grep @smoke

Go

go test -short sets the flag that testing.Short() reports, so a test can skip itself when it is set:

func TestAgainstRealService(t *testing.T) {
    if testing.Short() {
        t.Skip("needs the real service")
    }
    // ...
}

Build tags are the other mechanism: -tags takes a comma-separated list of tags considered satisfied, and files marked with a matching //go:build line are included only then.

Make the filter fail loudly

The worst outcome of a filtered run is a pass that ran nothing. A few documented guards:

  • pytest exits with code 5 when no tests were collected, which is distinct from 0 for success and 1 for failures. Treat only 0 as a pass.
  • Vitest has a --passWithNoTests flag, described as “pass when no tests are found”. Do not add it to the agent’s command, so an empty selection is not reported as a pass.
  • With pytest’s --strict-markers, as above, an unregistered marker is an error.

Have the command print the tier name and the count of tests it ran, so the agent’s report can say “fast tier, N tests” instead of “tests passed”. What the count means depends on your runner’s output, which we are not reproducing here.

Tell the agent what the fast tier is

Put the command and its limits in the instructions the agent already reads (AGENTS.md, .cursor/rules, CLAUDE.md, a Cline rule or an OpenHands repository skill). For example:

# Tests

Run `npm run test:fast` after every change. It runs unit and jsdom tests only.
It does not run browser tests and cannot check layout, navigation or real
browser behaviour. When you finish, report the command you ran, how many tests
it ran and its exit code, and say that browser tests were not run.
Do not edit tests to make them pass without saying so.

This is an instruction, not a control. If the agent can run any command, it can run others; the point is to make the fast command the obvious one and the report honest about its limits.

Run the fast tier in a sandbox

Nothing about the fast tier is Sandscale-specific, which is the reason it travels well: a Node, Python or Go process with your dependencies installed. With the CLI, the run is one command against a sandbox you created (see How to run your test suite in a clean microVM with the Sandscale CLI for creating one and getting the project in):

sandscale sandbox run SANDBOX_ID "npm ci && npm run test:fast" \
  --workdir /workspace/project --yes

Two things from that guide matter here. The network is off by default, and a run that installs packages needs a network mode your plan and organization allow, so check sandscale sandbox launch-options. And the exit code of run is 0 when the command exited 0 and 1 otherwise, with the command’s own code on standard error, so a failing run and a CLI failure share code 1 and the streamed output tells you which. To give the agent a report it can act on rather than a log, see Giving a coding agent test results it can act on.

Stop or terminate the sandbox when the work is done; a sandbox ends after its TTL, which defaults to 3600 seconds, as a backstop.

What you give up

  • Anything that only a browser shows: layout, real navigation, canvas output without the optional backend, browser-specific bugs.
  • Some DOM API coverage, depending on the emulation you choose.
  • A single “all green” signal. You now have a fast verdict and a slower one, and the agent’s report should name which one it has.

The trade is deliberate: an edit-test loop that depends on a browser has more that can go wrong for reasons unrelated to the change. Keep the browser tier in CI so the merge still depends on it.

FAQ

How do I run Vitest without browser tests?

Name your browser-mode project and exclude it with vitest run --project '!browser'. Vitest documents the ! negation for project names.

Is jsdom enough to test components?

For logic and markup, often. jsdom’s README says it does not do layout or navigation, so tests that depend on them need a real browser.

How do I skip browser tests in pytest?

Register a marker, mark those tests, and run pytest -m "not browser". Add --strict-markers so a misspelled marker is an error.

Can a filtered run pass without running any tests?

It can, if you let it. pytest exits with code 5 when nothing is collected, and Vitest has a --passWithNoTests flag precisely to make an empty run pass, so leave it off. Check the exit code and report the test count.

Run your agents in a box of their own

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

Start free

Keep reading