Guide

Testing Docusaurus documentation examples

Keep the site build and the reader-facing examples as separate checks, and decide which tab variants and MDX pages you actually test.

Published
Updated
November 10, 2026
Reading time
14 min
Facts checked against
Docusaurus documentation: code blocks, tabs, MDX, CLI and config (November 9, 2026)
Outlined documentation pages with a lime pulse line running out of the stack
On this pageThe short answerFind the source and define the test scopeUse the build and link settings as separate evidenceRead code blocks as both source and presentationSeparate MDX page components from reader examplesTreat tabs as alternative pathsRun each page in a clean containerTriage failures before editingChecklist for a Docusaurus example testWhat this does not replaceThe sources we checkedFAQ

The short answer

Test Docusaurus documentation examples as reader journeys as well as building the site. Run the production build with the site's actual configuration, inspect its link diagnostics, and separately execute the supported commands and code in clean environments. A build can succeed while a package name, API call or displayed result is wrong. A passing example can coexist with a broken page or link.

Start with the docs source and docusaurus.config.js, identify each fenced example and its prerequisites, and map tabs to alternatives. Run the steps in each page in order, then investigate the first failure with the environment and actual error in view. Keep skipped examples visible: a result for one install tab does not establish that every package manager works.

DocsAlive detects Docusaurus from docusaurus.config.*, reads MDX, recognizes Tabs as alternatives and picks one variant per group. It plans supported blocks in page order and uses a fresh sandbox container per page. It reports failures and their classifications, along with deliberate skips. It does not build or render the site, check links or test React components; keep those checks alongside it. The docs testing overview explains the wider approach, and how it works describes the pipeline.

Find the source and define the test scope

The Docusaurus configuration reference places docusaurus.config.js at the site root; it may be named docusaurus.config.ts in a TypeScript codebase. The Markdown features documentation describes the Markdown and MDX features that pages can use. Begin at the actual site root and inspect the repository's layout before selecting files. In a larger repository, the site root and repository root may be different, and an example scan pointed at the wrong directory can give a misleadingly small result.

Make an inventory of the pages intended for the test, their fenced blocks and the reader tasks they support. Record the page path and source line for each finding so the maintainer can locate it. Include installation instructions, quickstarts and API examples, not just blocks that look like complete programs. A shell command can be the first step of a tutorial even when its result is used only by later code.

Compare the inventory with the test report. A page omitted by an include pattern is different from an included page whose examples were skipped. A block may be present but intentionally illustrative, require credentials or use a language the runner does not execute. The useful question is not simply how many blocks exist; it is which promises have evidence and which still need a different check. The static-site guide covers the distinction between page source, the build and the site readers see.

The CLI reference says docusaurus build compiles the site for production. Run it with the configuration and dependencies intended for the site, and retain its diagnostics. A successful build is evidence about that compilation under those conditions. It is not evidence that a reader can install a package, authenticate, call an API or reproduce a code block's output.

The configuration reference documents onBrokenLinks and related handling for broken Markdown links and anchors. These settings determine how particular link problems are reported or treated, so inspect the actual configuration and diagnostic rather than assuming every link problem fails every build. The reference says onBrokenLinks controls detected broken links and defaults to throwing an error; detection is available in the production build. onBrokenAnchors applies to broken anchors declared with the Docusaurus Heading component and defaults to a warning. The older onBrokenMarkdownLinks setting is deprecated in favor of markdown.hooks.onBrokenMarkdownLinks. A warning and an error are different signals; ignored diagnostics are not evidence of working links. Review the applicable settings when the team changes its build policy.

Even a useful link diagnostic has a limited scope. It does not execute a shell command shown next to the link, verify that an external service behaves as the page promises, or establish that an interactive component works for a reader. Conversely, an example test does not validate site navigation. Keep the build result, link review and example report distinct enough that a reviewer knows what passed.

When a build fails, find the relevant page or config diagnostic and reproduce with the same configuration. When an example fails, inspect its command, prerequisites and actual error. These investigations can touch the same page but answer different questions. A build fix should not silently remove a failing example without deciding whether the reader still has a complete path.

Read code blocks as both source and presentation

The code blocks reference describes a language meta string for syntax highlighting, a title after the language, line ranges in metadata, and line-highlighting comments. It also describes line numbers and custom magic comments. With the live-code-block plugin, a block marked live can become an interactive editor. Those features affect what a reader sees and uses; they are not a guarantee that the source runs in the environment you intend to test.

The distinction matters especially for magic comments: the source says these directives are parsed and removed for presentation. A test reading the fenced source and a reader copying the rendered block may encounter different text. Check that the chosen test covers the reader-visible code and that any comment syntax is appropriate for the language. If line ranges are used, inspect the rendered emphasis after edits so a highlighted line still supports the surrounding explanation.

A title may identify a file the reader should create. Treat that filename and its role as part of the instruction, even if an execution tool reports only the block's source location. If the next command expects the file, verify that the reader has been told where to save it. Syntax coloring helps readers understand a block, but it does not show that the labeled language is supported by an example runner or that dependencies are installed.

For a live editor, separately inspect the interactive experience and the resulting behavior. A source-block execution result cannot demonstrate that the editor loads, that its controls work, or that the displayed result matches the surrounding prose. Similarly, a visually correct block is not a substitute for running a copyable command in a clean environment. Keep both forms of evidence when the page relies on both.

Separate MDX page components from reader examples

Docusaurus supports MDX and React in documentation, including imports and JSX in a page. An import of a tab component is part of assembling the page; it is not automatically a command that the reader should run. JSX used to render a callout or component can be essential to the site while having no role in a tutorial's runtime environment.

Identify the fenced blocks that make reader-facing promises and trace the prose around them. An MDX page may put an installation command inside a component, then use a normal fenced block later to demonstrate an API. The component supplies page structure; the two fenced blocks may form a sequence. Do not concatenate the page's React imports with a reader's shell session or report a component import as a missing tutorial dependency.

Component behavior deserves its own build and browser review. Check whether tabs show the right content, labels identify the choices, and formatting preserves the code readers should copy. If a component changes the visible instructions, check the resulting page as well as the authored source. The JavaScript documentation testing guide covers runtime examples; page component checks answer a separate question.

Treat tabs as alternative paths

The Tabs reference describes Tabs and TabItem components. Related groups with the same groupId synchronize choices; when a selected value is missing from another group, that group does not change to that value. This behavior affects the journey a reader sees across a page. Inspect the labels and values as well as the code under each tab.

Here is an illustrative MDX page excerpt. @acme/docs-demo is fictional, so the install commands are examples of documentation structure, not commands to validate a real distribution.

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Install the demo

Choose the package manager available in your environment.

<Tabs groupId="package-manager">
  <TabItem value="npm" label="npm">

```bash
npm install @acme/docs-demo
```

  </TabItem>
  <TabItem value="yarn" label="Yarn">

```bash
yarn add @acme/docs-demo
```

  </TabItem>
  <TabItem value="pnpm" label="pnpm">

```bash
pnpm add @acme/docs-demo
```

  </TabItem>
</Tabs>

A reader normally chooses one installation method. Running all three consecutively in a single environment would test a different path and can conceal a missing prerequisite. Test each variant you promise from an equivalent clean starting state, with the selected package manager available. Follow each choice through any subsequent commands that depend on the installation. If another synchronized group supplies run commands, verify that each matching value leads to a coherent end-to-end path.

DocsAlive recognizes tab groups as alternatives, picks one variant and marks the others alt-variant. Its selection is not evidence that all npm, yarn and pnpm instructions passed. Review the report, record the chosen path, and arrange separate checks for the remaining variants. Do not infer synchronized browser behavior from a source scan. The installation testing guide offers more on isolating install paths.

Run each page in a clean container

A page often introduces a variable, creates a file or installs a package before using it. Run dependent blocks in their documented order, preserving state within that page. Start a new clean environment for the next independent page so that a previous installation does not accidentally satisfy an undocumented prerequisite. If a tutorial explicitly crosses pages, also test that complete journey separately: isolated page runs cannot by themselves establish the handoff.

DocsAlive keeps blocks in page order and starts a fresh container per page. Containers run as an unprivileged user with a read-only root filesystem, dropped Linux capabilities, no privilege escalation, and resource and time limits. The plan can execute, syntax-check or skip a block with a reason. It extracts an output block shown immediately after code for comparison. A pass can therefore mean execution or a syntax check; inspect the treatment before describing a whole page as executed.

Separate test harness setup from instructions readers receive. The CLI's repeatable --setup runs a shell command at the start of each page container. This can provide a necessary environment, but it can also mask a missing installation instruction if nobody records it. Note the package or artifact under test, the setup command, and whether the page tells the reader to perform an equivalent step. The CLI reference explains selection and reports.

Network access, external services and local fixtures also influence results. A test with no network answers a different question from an install that must download a package. If a page expects a local file, either document how the reader obtains it or clearly describe it as a prerequisite. Keep the first error and surrounding evidence; later failures can merely follow from an earlier missing step.

A generic CI outline

From the site root, with site dependencies and the product CLI already available, the following shell commands illustrate separate checks. The build command assumes the site's build script invokes docusaurus build; use the site's actual invocation if it differs. Adjust the scan target and include pattern to the repository layout.

npm run build
docsalive scan . --execute --include 'docs/**' --out docs-test-report

Review docs-test-report/report.md and docs-test-report/report.json, including categories, reasons, hints and skipped blocks. The scan runs supported extracted examples according to its plan; it does not run the build command on your behalf. If the docs need a specific setup, add a documented --setup command and consider whether it hides a reader-facing omission. Repeat checks for relevant changes, releases and dependency drift, keeping a record of the artifact tested. The quickstart testing guide helps map a longer path.

Choose what a passing result means

Before wiring the checks into a required workflow, agree on the evidence a reviewer needs for each type of page. An install page should identify the package and the environment in which its command was tried. A tutorial should show that its later steps received the state created by earlier ones. A reference example may need an assertion or a stable output comparison to establish more than successful process completion. Record the selected artifact and prerequisites with each result.

Coverage can change without a page disappearing. A new tab, a change from JavaScript to JSX, or a newly credential-gated request can turn a previously executed path into a skip. Compare skips and selection with the previous review, and give an owner to important gaps. If the test harness supplies setup on every page, periodically check the instructions without that hidden help so an omitted installation step stays visible. A passing build and passing selected examples are valuable evidence when their limits are clear to the person approving the change.

Triage failures before editing

A nonzero result is a starting point for investigation. Compare the actual error with the documented steps, the installed artifact and the setup supplied by the test. DocsAlive classifies results using the actual error rather than the exit code alone. Its report includes a category and reason so a maintainer can distinguish likely documentation bugs from environment and coverage issues.

Finding What to investigate Next action
api-drift An import, attribute or argument may no longer match the installed API Reproduce with the intended package and correct the instruction or prerequisite
invalid-syntax A complete block may not parse Correct the code; identify deliberate fragments clearly
stale-output A working example shows output from an older runtime Verify the intended result before updating the output
package-not-found A documented pip or npm package name does not exist Verify its name and distribution path
missing-install-step The page imports a package it never installs Review the hint and decide what the reader needs
needs-credentials The example needs credentials Record the gap and arrange a separate authorized check
missing-fixture or depends-on-context A file or context is expected Trace the prerequisite and page sequence
alt-variant or unsupported-lang A block was deliberately skipped Record the gap and arrange coverage for important paths

Timeouts, runtime errors and some external network results need review rather than automatic treatment as docs bugs. Output can differ because of timestamps or ordering, but a changed value may be material. Preserve actual and expected output until someone understands the difference. Fix the source, rerun the relevant page, and confirm that the correction does not invalidate another tab or later step.

The API reference testing guide is useful when an example depends on a changing API. For a repository landing page outside the docs tree, add a README check. Each reader entry point can make a different promise even when the snippets look similar.

Checklist for a Docusaurus example test

Check Evidence to retain
Identify site root, config and docs scope Configuration and selected source paths
Build with the intended settings Build result and link diagnostics
Inventory blocks and page components Reader examples distinguished from MDX structure
Inspect rendered code presentation Titles, highlighting and copyable content checked against source
Map tabs and synchronized choices Each promised path, selected variant and remaining coverage
Start independent pages clean Environment, network policy and harness setup
Preserve page order Prerequisites, first failing step and later dependencies
Compare promised output Expected and actual output, including variable fields
Triage and rerun Category, decision and verification of the changed page
Review gaps Skips, credentials, unsupported languages and component checks

Use the broader docs testing checklist to assign owners and decide when each check runs. A skipped path remains a coverage decision even when every executed block passes. Review the inventory after navigation, package-manager choices or the page's prerequisites change.

What this does not replace

DocsAlive does not build or render a Docusaurus site, check links, or test React components. Keep the production build, link diagnostics and browser review. Human review is still needed for clarity, accessibility and whether the prose teaches the intended task. A command that executes can still be the wrong command for the reader.

JSX and TSX are not judged yet, and full TypeScript is not judged; simple type annotations can be stripped for execution. Go, Rust, Java and other recognized languages are not executed. Credential examples are classified rather than executed with real keys; customer-provided test credentials are not currently supported. Record these boundaries in the report and use separate checks for important untested paths.

The free health check lets you send a public repository you own or maintain; the team runs the engine on up to 40 of its docs pages and emails the real report within 2 business days; the checkout is deleted after the run. Pricing is Open source $0/month, Team $299/month, Growth $699/month, and Scale from $1,499/month.

The sources we checked

Source What it covers
Docusaurus CLI Production build command
Docusaurus configuration Site config and broken-link handling
Markdown features Documentation source and Markdown features
Code blocks Metadata, highlighting, magic comments and live blocks
Tabs Alternative content and synchronized groups
MDX and React Imports and components in pages

FAQ

Does docusaurus build run documentation examples?

The command compiles the site for production. A successful build does not establish that the commands and code shown to readers execute successfully. Run an example check separately and keep both results.

The settings govern how relevant link problems are handled. Inspect the actual settings and diagnostics; a warning or ignored issue is not a passing link test. Link checks also do not validate the code on a destination page.

Should every package-manager tab be tested?

Test every variant you promise, from equivalent clean environments. DocsAlive selects one variant per group and skips the others, so one run leaves alternatives to cover separately.

Does groupId test synchronized paths?

It synchronizes related choices in the site. It is not an execution test. Inspect the rendered groups and separately run the commands for each coherent reader path, including later steps.

Are MDX imports runnable examples?

Imports and JSX used to assemble a page are page implementation. Identify the fenced code intended for readers, and test the React components through a separate site check.

Why preserve block order?

A later block can depend on an earlier installation, variable or file. Preserving the sequence models the page; starting each page clean helps reveal prerequisites that were never supplied.

What does an alt-variant skip mean?

The block is another choice in a group and was deliberately not run in that selection. It is not a pass or a failure. Record the untested path and arrange coverage if readers are promised it.

Can the product replace a site review?

No. It does not render the site, check links or test React components. Continue those checks alongside execution. For another MDX framework's workflow, see the Mintlify testing guide.

Keep reading
Outlined documentation pages with a lime pulse line running out of the stackGuide

Docs Testing: How to Test the Code Samples in Your Docs

Why code examples in documentation break, the ways teams test them (doctest, docs-as-tests, CI runners) and how to run every sample on each release.

Two lenses held over the same documentation page, each bringing a different layer into focusComparison

Vale vs markdownlint: What Each Docs Linter Catches

Vale checks prose style; markdownlint checks Markdown structure. What each catches, sample configs, running both in CI and what neither one tests.

Blueprint of two documentation pages: one with a handwritten test script, one whose code blocks are framed and checkedComparison

Doc Detective vs DocsAlive: Testing the Code in Your Docs

Doc Detective is a free, open-source docs-as-tests framework; DocsAlive is a hosted docs CI for code examples. Features, price, setup and when to use each.

A machine blueprint above a ruled documentation page, with a caliper measuring between themComparison

Promptless Alternative: Promptless vs DocsAlive Compared

Promptless drafts docs updates from what you ship; DocsAlive runs the code examples you've published. Features, pricing, security and when to use each.

A long workbench of outlined testing instruments, each with a small lime light, beside a stack of documentation pagesGuide

Best Free Tools to Test Code Examples in Documentation

Free, open-source tools that run the code examples in your docs: rustdoc, Go examples, doctest, pytest plugins, Sphinx doctest, Doc Detective and byexample.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing SDK Docs Before Every Release: A Release-Gate Guide

Test SDK and client-library docs against the package you ship: build the wheel or npm tarball, install it clean, run every example, and gate the release in CI.

Outlined documentation pages with a lime pulse line running out of the stackGuide

How to Test Quickstarts and Tutorials in Your Docs

Test the onboarding path a new reader follows: run quickstarts in a clean environment, in page order, sort real bugs from credentials and fragments, and wire it into CI.

Outlined documentation pages with a lime pulse line running out of the stackGuide

How to Test CLI Documentation: Commands, Flags and Output

Test the commands a CLI page promises: install in a clean container, run examples in order, compare flags with --help, check exit codes and output, and run it in CI.

Outlined documentation pages with a lime pulse line running out of the stackGuide

How to Test API Reference Docs: Requests, Responses and SDKs

Test API reference pages against the contract they publish: methods, parameters, request and response examples, SDK snippets, status codes and OpenAPI samples.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Docs testing for API-first companies

Keep API quickstarts, SDK snippets and curl examples working across releases.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Docs testing for CLI and developer-tool vendors

Test developer-tool install paths, package managers and command examples across releases.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing README Code Examples: Install, Usage and CI

Keep README install commands and usage examples working with clean environments, output checks and CI.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Notebooks and Executable Docs: Cells, Kernels and Output

Test notebooks in fresh kernels, check meaningful output and manage dependencies, data and drift in CI.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Docs in GitHub Actions: Pull Requests and Scheduled Checks

Run documentation example checks in GitHub Actions with practical guidance on schedules, path filters, caching, secrets and reports.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Code Examples in MkDocs, Docusaurus and Sphinx Sites

Find and test documentation examples in Markdown, MDX and reStructuredText, alongside site builds and link checks.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Python Docs Testing: Doctest, Pytest and Markdown

Test Python documentation with doctest, pytest, Markdown example execution and isolated environments.

Outlined documentation pages with a lime pulse line running out of the stackGuide

JavaScript Docs Testing: Node, TypeScript and Modules

Test Node and TypeScript documentation examples across module formats, package versions and type checks.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Go documentation examples

Test Go example functions and Markdown snippets against the intended module versions in clean environments.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Sphinx Docs Testing: doctest, code-block and MyST

Test Sphinx documentation examples: what the doctest and linkcheck builders prove, code-block and literalinclude, MyST fences, and what a Markdown scan covers.

Outlined documentation pages with a lime pulse line running out of the stackGuide

ReadMe Docs Testing: CLI, OpenAPI and Code Examples

Test ReadMe documentation examples: docs-as-code and bi-directional sync, what lint and oas:validate prove, Tabs variants and runnable code.

Outlined documentation pages with a lime pulse line running out of the stackGuide

TypeScript Docs Testing: tsc --noEmit and Runtime

Test TypeScript documentation examples: type-check snippets with tsc --noEmit in a consumer project, then run them, and what each check proves.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Mintlify Docs Testing: CodeGroup, Tabs and the CLI

Test Mintlify documentation examples: docs.json, MDX pages, CodeGroup and Tabs variants, what mint broken-links and mint validate prove, and clean runs.

Outlined documentation pages with a lime pulse line running out of the stackGuide

MkDocs Docs Testing: Code Examples, Tabs and Snippets

Test MkDocs documentation examples: strict builds, Material tabs, Snippets includes, mkdocstrings pages and clean-container runs.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Installation Instructions: pip, npm and Containers

Test documented install steps in clean environments: pip and extras, venv, npm install vs npm ci, containers and the first import.

Outlined documentation pages with a lime pulse line running out of the stackGuide

AI SDK Docs Testing: LLM Examples, Keys and Drift

Test AI and LLM SDK documentation examples: requests, responses, streaming, tool calls, credentials, model retirements and CI.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing migration guides and changelog examples

Test before and after examples against the right releases and make migration documentation part of the release gate.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Docs Testing Checklist: Code Examples Before Release

A practical pre-release checklist for testing documentation examples, reviewing gaps and verifying published packages.

Outlined documentation pages with a lime pulse line running out of the stackGuide

The Cost of Broken Code Examples in Documentation

Understand how broken documentation examples create friction in developer adoption and support, and how to reduce it.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Rust documentation examples

Test Rust rustdoc examples and cargo documentation tests, and keep native Rust checks because compiled Rust fences are recognized but not executed.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing VitePress documentation examples

Test VitePress Markdown examples separately from the site build, including code groups, includes and what a plain Markdown scan covers.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing docs in GitLab CI

Run documentation example checks in GitLab CI jobs, keep site builds separate from execution, and review what a scan covers and skips.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing JSON, TOML and YAML examples in docs

Test JSON, TOML and YAML config examples in documentation: parse, schema and tool checks, honest fence labels, fragments, CI jobs and what a scan covers.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Java documentation examples

Test Java examples in READMEs, SDK docs and Javadoc: the source launcher, javac, JShell scripts, assertions, @snippet files, CI and what a scan covers.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing PHP documentation examples

Test PHP examples in docs: php -l lint, clean-directory runs, assertions with zend.assertions, Composer scratch projects, PHPUnit, CI and scan coverage.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing docs examples that need API keys

Test credential-gated docs examples: honest placeholders, offline stubs and fixtures, live sandbox jobs, CI secrets and fork rules, and how a scan classifies them.

A machine blueprint above a ruled documentation page, with a caliper measuring between themGuide

Documentation Drift: How to Detect It Before Users Do

What documentation drift is, why code examples drift first, and practical ways to detect it: ownership, release checks, link and execution tests.

See which of your code samples still run.

Send us a public repository. Our team runs DocsAlive on its docs and emails you the real report within 2 business days. Free, no signup.