Skip to navigation

Installation

Downloading and running Doc Detective is straightforward. You can install Doc Detective using NPX (Node.js) or Docker. Follow the instructions for your preferred method:

Choose NPX if you have Node.js installed and want Doc Detective on your machine locally. Choose Docker if you can’t install applications locally or prefer containerized environments. It also suits you if you need to avoid a Node.js install, or want to isolate Doc Detective from your system.

  1. Install prerequisites:

  2. In a terminal, install Doc Detective globally:

    npm i -g doc-detective

    If you’re working in a local copy of the doc-detective repository, you need to run npm i to install local dependencies.

    To try pre-release features, install from the @next dist-tag: npm i -g doc-detective@next. For stable releases, use the default command above.

  3. Save this file to your current directory as sample.spec.json:

    sample.spec.json
    {
    "tests": [
    {
    "steps": [
    {
    "description": "Go to the specified URL",
    "goTo": "https://example.com"
    },
    {
    "description": "Verify the presence of the main heading",
    "find": "Example Domain"
    },
    {
    "description": "Verify that the 'Learn more' link is present and working",
    "click": "Learn more"
    },
    {
    "description": "Capture a screenshot of the resulting page",
    "screenshot": "example.png"
    }
    ]
    }
    ]
    }
  4. Run a test, pointing to the file you just created:

    npx doc-detective --input sample.spec.json

You’ve run your first test with Doc Detective. 🎉

You should see output in the terminal indicating the progress and results of the test. Results are also saved in the .doc-detective/runs/<runId>/ folder in the current directory, and this test saves a screenshot to example.png. To write the results somewhere else, pass --output <file> for the JSON results file or --output-dir <dir> for the run folder.

Runtime installation

Running npm i doc-detective installs the CLI and pre-installs heavy runtime assets. Those are browsers (Chrome, Firefox), drivers (ChromeDriver, Geckodriver), ffmpeg, and the npm packages that drive them, such as webdriverio, appium, and sharp. They land in your cache directory. This keeps your install ready to run tests without a separate step.

The pre-install runs in a child process and captures its output, so npm’s deprecation warnings from transitive dependencies won’t clutter your terminal.

Opt out of pre-installation

To skip the heavy asset pre-install, set DOC_DETECTIVE_AUTOINSTALL=0 (also accepts false, no, or off):

DOC_DETECTIVE_AUTOINSTALL=0 npm i doc-detective

With this option, the CLI install stays small. Heavy assets install lazily the first time a test needs them.

Pre-install manually

If you opted out or need to reinstall, pre-install all runtime assets:

doc-detective install all --yes

Install specific components

Install only what your tests need:

doc-detective install browsers chrome chromedriver
doc-detective install runtime webdriverio appium
doc-detective install agents

Check installation status

See what’s installed versus what the current version expects:

doc-detective install status

Each Doc Detective release pins every runtime npm package to the exact version its CI tested. install status marks a cached package at any other version, newer or older, as (outdated). You don’t need to fix it by hand. Doc Detective replaces it with the pinned version on the first run that loads it or on the next doc-detective install runtime. That includes a downgrade if the cached version is newer than the pin. The replacement needs network access and downloads only the packages that changed.

If you build a CI image or warm a shared cache, run doc-detective install runtime there after each upgrade so test jobs skip the download.

Override the cache location

The default cache location is $XDG_CACHE_HOME/doc-detective, or ~/.cache/doc-detective if XDG_CACHE_HOME isn’t set. On Windows, it’s %LOCALAPPDATA%\doc-detective. An existing ~/.doc-detective keeps being used. All of these persist across reboots. For containers, shared CI caches, or any environment where the cache belongs somewhere else, set a custom location:

DOC_DETECTIVE_CACHE_DIR=/opt/doc-detective doc-detective install all --yes

You can also set cacheDir in your .doc-detective.json config file or pass --cache-dir. When you set more than one, --cache-dir wins over DOC_DETECTIVE_CACHE_DIR, which wins over cacheDir. A relative cacheDir resolves against the folder that holds the config file, and a relative --cache-dir or DOC_DETECTIVE_CACHE_DIR resolves against the current directory. Test runs and install commands follow the same order, so with the same flags, variables, and config, they use the same cache.

Auto-update

By default, Doc Detective checks the npm registry on startup and updates itself when a newer version is available. In the commands below, <version> is that newer version:

  • Global installs (npm i -g doc-detective): Runs npm install -g doc-detective@<version> and re-executes.
  • npx invocations: Re-executes with npx -y doc-detective@<version>.
  • Local project installs: Prints an “update available” message with the npm i doc-detective@<version> command to run, instead of modifying your package.json.

Auto-update never crosses a major version. When a new major version is out, Doc Detective tells you and leaves the upgrade to you. See Upgrade to Doc Detective 5 for what changes in version 5.

To disable auto-update, use any of these methods:

  • Pass --no-auto-update on the CLI
  • Set autoUpdate: false in your .doc-detective.json config file
  • Set the DOC_DETECTIVE_SKIP_AUTO_UPDATE=1 environment variable

CI environments skip the update check automatically whenever the CI environment variable has a value.

Uninstall

To remove Doc Detective from a machine:

  1. Uninstall the package:

    npm uninstall -g doc-detective

    For a project install, run npm uninstall doc-detective in the project instead.

  2. Delete the cache directory, which holds browsers, drivers, and runtime packages. It’s the first of these that applies:

    • The path in DOC_DETECTIVE_CACHE_DIR, if you set it
    • ~/.doc-detective, if it exists
    • $XDG_CACHE_HOME/doc-detective or ~/.cache/doc-detective on macOS and Linux
    • %LOCALAPPDATA%\doc-detective on Windows

    If you set cacheDir in a config file or passed --cache-dir, delete that folder too.

  3. Delete your user config directory, which holds config.json and the record that you saw the telemetry notice. It’s $XDG_CONFIG_HOME/doc-detective or ~/.config/doc-detective on macOS and Linux, and %APPDATA%\doc-detective on Windows.

Your projects keep their .doc-detective.json files and .doc-detective/runs/ folders. Delete those by hand if you no longer want them.

Next steps

Next up, take a look at the concepts native to Doc Detective. You can also work through the guided walkthroughs in Test your docs, or explore how to write tests and actions.