The `cht-conf-test-harness` is a JavaScript/TypeScript test framework designed specifically for validating configurations of applications built on the Community Health Toolkit (CHT) Core Framework. It simulates a CHT application instance, allowing developers to write and run automated tests against their app configurations without deploying to a live environment. The current stable version is 5.0.4, with frequent minor releases addressing bug fixes and major versions typically aligning with significant updates to the CHT Core Framework. A key differentiator is its explicit compatibility matrix, ensuring tests can target and validate against specific CHT Core versions (e.g., v5.x supports CHT Core 4.11.x+). It is commonly used with testing frameworks like Mocha and assertion libraries like Chai.
npm install cht-conf-test-harnessVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up, run, and clean up a CHT test harness instance using Mocha and Chai. It shows loading a form, simulating user input to fill a form, and asserting on the generated report data and console errors.
Upgrade your CHT Core Framework to version 4.11 or later, or remain on `cht-conf-test-harness` v4.x if testing older CHT Core versions is necessary.
Ensure your environment has all Puppeteer's required system dependencies. For Docker/CI, use a base image that includes these browser dependencies, or install them explicitly (e.g., `apt-get install -y libatk-bridge2.0-0 libgbm-dev`). Consider setting `headless: true` or `args: ['--no-sandbox', '--disable-setuid-sandbox']` in the harness options for CI environments.
Install `mocha` and `chai` as dev dependencies: `npm install --save-dev mocha chai`. Configure your `package.json` scripts to run Mocha, e.g., `"test": "mocha --require @babel/register your-tests/**/*.js"` (adjusting for your transpilation needs).
Install necessary browser dependencies (e.g., `libatk-bridge2.0-0`, `libgbm-dev` on Debian-based systems) or add `--no-sandbox` arguments to Puppeteer options if running in a trusted containerized environment.
For CommonJS, use `const TestRunner = require('cht-conf-test-harness');`. For ESM, use the named import `import { TestHarness } from 'cht-conf-test-harness';` and instantiate `new TestHarness()`.Install `chai` (`npm install --save-dev chai`) and import `expect` explicitly in your test files: `import { expect } from 'chai';`.