Doc Detective Core is a low-code documentation testing framework that validates docs through browser automation, shell commands, HTTP requests, and content analysis. It's the engine behind the Doc Detective CLI tool.
- Input Resolution (
doc-detective-resolver): Detects tests from docs/specs → resolves to executable format - Test Orchestration (
src/tests.js):runSpecs()→ spec → test → context → step hierarchy - Browser Automation (
src/tests.js): Appium server manages WebDriver sessions (Chrome/Firefox/Safari) - Step Execution: Each step type has dedicated handler in
src/tests/(e.g.,httpRequest.js,runShell.js)
src/index.js: Entry point exposingrunTests()functionsrc/tests.js: Core test runner with Appium/WebDriver orchestration (600+ LOC orchestrator)src/config.js: Configuration validation, environment detection, browser discoverysrc/openapi.js: OpenAPI integration for HTTP request validation/mockingsrc/expressions.js: Runtime expression resolver supporting meta values ($$response.body.field) and operators (jq(),extract())src/tests/: Individual step action implementations
npm test # Run full test suite (mocha)
node dev # Development/manual testing
npm run depcheck # Check for unused dependenciesThree GitHub Actions workflows automate releases and testing:
-
Auto Dev Release (
auto-dev-release.yml): Triggers on push tomain- Skips on
[skip ci]commits, release commits, or docs-only changes - Increments dev version (
3.4.0-dev.1→3.4.0-dev.2) - Publishes to npm with
devtag - Users install with
npm install doc-detective-core@dev - Version strategy: Checks npm for latest dev number, increments, updates
package.json, commits with[skip ci], creates git tag
- Skips on
-
Test & Publish (
npm-test.yaml): Cross-platform testing + release publishing- Test matrix: Ubuntu/Windows/macOS × Node 18/20/22/24 (15 min timeout)
- Triggers: Push to
main, PRs (opened/reopened/synced), manual dispatch - On release publish: Runs
npm publishto npm registry - Post-publish: Triggers downstream
doc-detectivepackage update via repository dispatch
-
Update Resolver (
update-resolver.yaml): Dependency sync workflow- Trigger: Repository dispatch from
doc-detective-resolverreleases OR manual with version input - Process: Installs specified resolver version + matching
doc-detective-commonversion → runs tests → bumps version → creates release with resolver changelog - Version bumping: Uses
scripts/bump-sync-version-resolver.jsto increment patch version - Release notes: Aggregates merged PRs since last tag + resolver release notes
- Trigger: Repository dispatch from
- Post-install (
scripts/postinstall.js): Auto-downloads Chrome/Firefox/ChromeDriver tobrowser-snapshots/ - Browsers MUST match platform (detected via
@puppeteer/browsers) - Appium drivers installed:
chromium,gecko,safari(Mac only) - Timeout: All drivers default to 10 minutes (
newCommandTimeout: 600)
- Dev releases:
X.Y.Z-dev.Nformat (auto-incremented on every main push) - Stable releases: Manual GitHub releases trigger npm publish
- Dependency sync: Resolver updates trigger automated core updates
- Commit conventions: Use
[skip ci]to avoid triggering auto-dev-release
- Create handler in
src/tests/[actionName].jsexporting async function - Add action to
driverActionsarray insrc/tests.jsif requires browser - Add case in
runStep()switch statement - Follow validation pattern: validate schema → resolve to object → set defaults
- Return
{ status: "PASS"|"FAIL"|"WARNING", description: string, outputs: {} }
Tests follow nested hierarchy:
spec (file) → test → context (browser/platform combo) → step (action)
- Contexts run serially and skip if platform/browser unsupported
- Steps skip after first failure in context (stepExecutionFailed flag)
- Unsafe steps (
step.unsafe = true) requireconfig.allowUnsafeSteps = true
- Config validated via
doc-detective-commonschemas (validate({ schemaKey: "config_v3", object })) - File types (
markdown,asciidoc,html) define inline test detection regexes - Environment variables loaded via
loadEnvs()and replaced viareplaceEnvs()using$VAR_NAMEsyntax - OpenAPI definitions loaded and dereferenced at config time (stored in
config.integrations.openApi[].definition)
- Meta values:
$$response.body.users[0].nameaccesses runtime data - Embedded expressions:
"User ID is {{$$response.body.id}}"for string interpolation - Operators:
jq($$response.body, ".users[0].name"),extract($$output, "ID: (\d+)") - Variables set via
step.variables = { MY_VAR: "$$response.body.token" }→ stored as env vars
- Example compilation: Extracts request/response examples from OpenAPI spec
- Schema validation: Uses AJV to validate payloads against OpenAPI schemas
- Mock responses: Set
step.httpRequest.openApi.mockResponse = trueto skip actual HTTP call - Operations referenced by
operationId(e.g.,step.httpRequest.openApi.operationId = "getUserById")
- Use
log(config, level, message)where level = "debug"|"info"|"warning"|"error" - Config object MUST be passed as first param to log functions
- Step failures should return
{ status: "FAIL", description: "Detailed error message" } - Always handle driver cleanup in try/finally blocks
- Appium must be running for any driver-based step (auto-started if needed, but check
appiumRequiredflag) - Browser paths are platform-specific: Use
getAvailableApps()to detect installed browsers - JSON pointer syntax: Use
#/path/to/fieldafter meta value (e.g.,$$response#/body/users/0/name) - Viewport vs Window size:
setViewportSize()calculates delta to set inner dimensions - Fractional variation (
maxVariation): Value is a decimal fraction (0.1 = 10% tolerance). Comparisons use fractions directly. - File overwrite modes: "false" (never), "true" (always), "aboveVariation" (only if content differs > maxVariation)
- Tests in
test/core.test.jsuse mocha withthis.timeout(0)for indefinite timeout - Test server runs on port 8092 (
test/server/) for HTTP request tests - Artifacts stored in
test/artifacts/(specs, configs, test files) - Use
fs.writeFileSync()+fs.unlinkSync()for temp test files in try/finally blocks
webdriverio(8.45.0): WebDriver protocol implementationappium: Browser automation server@puppeteer/browsers: Browser binary managementaxios: HTTP client for requestsajv: JSON schema validationjq-web: JQ expression evaluationdoc-detective-common: Shared schemas/utilitiesdoc-detective-resolver: Test detection/resolution
- Main docs at https://doc-detective.com
- Schemas at https://doc-detective.com/reference/schemas/
- Report issues to https://github.com/doc-detective/doc-detective-core/issues