Registry / testing / cht-conf-test-harness

cht-conf-test-harness

JSON →
library5.0.4jsnpmunverified

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-harness
INSTALL
IMPORT
SIG · CHT-CONF-TEST-HARN
C
cht-conf-test-harness
testingjavascriptv5.0.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TestHarness
import { TestHarness } from 'cht-conf-test-harness';
import TestHarness from 'cht-conf-test-harness';
The primary class for instantiating the test environment. It is a named export in ESM contexts. The CJS equivalent uses `TestRunner` as the default export.
TestRunner
const TestRunner = require('cht-conf-test-harness');
import { TestRunner } from 'cht-conf-test-harness';
This is the CommonJS default export, typically instantiated as `new TestRunner()`. For ESM, use the named export `TestHarness`.
expect
import { expect } from 'chai';
import { expect } from 'cht-conf-test-harness';
While used in test harness examples, `expect` typically comes from a separate assertion library like Chai, which is a common companion dependency.

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.

import { TestHarness } from 'cht-conf-test-harness'; import { expect } from 'chai'; describe('CHT Configuration Tests', () => { let harness; before(async () => { harness = new TestHarness({ // Optional: Specify CHT Core version to simulate coreVersion: '4.11', // Optional: Launch browser with GUI for debugging headless: true, verbose: false }); await harness.start(); // Initializes the simulated CHT environment }); after(async () => { await harness.stop(); // Cleans up the environment }); beforeEach(async () => { await harness.clear(); // Clears all data before each test }); afterEach(() => { // Ensure no unexpected console errors occurred during form evaluation expect(harness.consoleErrors).to.be.empty; }); it('should load a specific form successfully', async () => { const formName = 'patient_registration_form'; await harness.loadForm(`app/${formName}`); expect(harness.state.pageContent).to.include(`id="${formName}"`); }); it('should allow filling a form and verify report output', async () => { const formName = 'delivery_report'; // Simulate filling the form with specific inputs const result = await harness.fillForm(formName, [ 'patient_name:Jane Doe', 'delivery_outcome:live_birth' ]); // Verify form submission was successful and check report fields expect(result.errors).to.be.empty; expect(result.report.fields.patient_name).to.equal('Jane Doe'); expect(result.report.fields.delivery_outcome).to.equal('live_birth'); }); });
Debug
Known issues
breakingVersion 5.0.0 of `cht-conf-test-harness` introduced breaking changes by dropping support for CHT Core 4.6 and older, and adding support exclusively for CHT Core 4.11 and newer. Configurations for older CHT Core versions will no longer be compatible or testable with `cht-conf-test-harness` v5.x.
fix
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.
affects: >=5.0.0
gotchaThe `cht-conf-test-harness` relies on Puppeteer internally, which can sometimes fail to launch the browser process, especially in CI/CD environments or environments without necessary browser dependencies (e.g., `libatk-bridge2.0-0`, `libgbm-dev`).
fix
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.
affects: >=2.x
gotchaWhile `cht-conf-test-harness` provides the testing environment, it does not include a test runner or assertion library itself. Users must explicitly install and integrate frameworks like Mocha and assertion libraries like Chai to write and execute their tests effectively.
fix
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).
affects: >=2.x
Errors
Common errors & fixes
Error: Failed to launch the browser process!
Puppeteer, used internally, could not start a browser instance due to missing system dependencies or sandbox issues in certain environments (e.g., Docker, CI).
fix
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.
TypeError: TestRunner is not a constructor
Attempting to import `TestRunner` using ESM syntax (`import { TestRunner } from '...'`) when it is primarily a CommonJS default export or the default export is not named `TestRunner` in ESM.
fix
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()`.
expect is not defined
The `expect` assertion function is being used without being imported or correctly linked from an assertion library.
fix
Install `chai` (`npm install --save-dev chai`) and import `expect` explicitly in your test files: `import { expect } from 'chai';`.
Upgrade
Version history
5.0.4latest on npm
Audit
Dependencies
chaioptionalCommonly used assertion library alongside the test harness for writing test expectations.
mochaoptionalPopular test runner often used to execute tests defined with cht-conf-test-harness.
Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
2
Resources
cht-conf-test-harness — npm install cht-conf-test-harness · libregistry