Adds support for CHT Core Framework version 4.6
. This version of the test harness is not backwards compatible with earlier versions of the CHT Core Framework.
- Uplift to use cht-form web component (#245)
- Fix filling out
time
questions (#250) (3eb9bc0f)
- fix(#240): contact-summary should be passed reports of selected contact and its children (#246) (bb51e1db)
- fix(#247): fill forms using the android app launcher (#248) (7a6b16d1)
- Support for cht-conf v3.19.0 and above (#243) (93ad986f)
- #239: fail to save app form due to TypeError (#241) (b9ce73be)
- #234: Update test harness name (d42ddc7a)
- Update formfiller to support elements with type datetime(6a327de9)
- Log errors thrown when filling a form (478e3426)
- Fix script paths for project-explorer js resources (#231) (ab7e4f9d)
- Disable db-object-widget (#210) (bf773b4e)
- Strip console.debug from cht-conf-test-harness build output (#227) (3c672753)
- Workaround for ERR_REQUEST_RANGE_NOT_SATISFIABLE (#225) (ce40429f)
- Add missing jQuery boilerplate from cht-core to handle self-closing tags in model.xml (#228) (3bda9f47)
- 113 - strip console debug statements (#226) (a93c267c)
- Add cht API as global to contact-summary (#215) (9a91335c)
- Label semver a production dependency (#209) (b1b2954e)
- Convert DateTime and Date objects to strings before passing to Form-Filler (#206) (19f22fb1)
- Re-build with latest cht-4-0 branch (#198) (cd7ebb34)
- Reference xsltproc dependencies from ext folder instead of node_modules (#202) (e03b2a64)
- Add support for cht-core 3.13 (including parse-timestamp-to-date) (#153) (562ed5b4)
- Improve check for DateTime/Duration (#146) (501c1ee6)
- Revert change in behaviour for RFC2822 date strings (#161) (983562b9)
- Support for cht-core v3.14 including new xpath functions for Bikram Sambat (55fd75e7)
- (a3615516)
- Support for cht-core v3.12 and the cht-script-api (#151) (764ca934)
- Gracefully handle empty forms (#132) (9478fcd0)
- Improve date handling (#118) (39fe990f)
- FillForm - Fails to answer questions with "falsey answers" like 0 (#128) (93de03c5)
- BUG - Fix compatibility for projects using rules.nools.js (#119) (a42a2ac2)
- Pass the userSettingsDoc into Enketo not the userContactDoc (#109) (a3615516)
The repository and npm package have been renamed to cht-conf-test-harness
.
For projects using the declarative configuration system, users can now set breakpoints in their CHT application code (eg. tasks.js
, targets.js
, etc). To do this, run mocha with the --dev
flag. This makes tests powered by your application's JavaScript directly - you don't need to run medic-conf compile-app-settings
, you can set breakpoints directly, get code coverage metrics, etc. Technical
The behaviour of the harness without --dev
more closely aligns with the behaviour of code in production. This is a productivity tool - the use of --dev is not recommended for official (CI) test runs.
Prior versions of the harness were powered by a system which “behaves like” cht-core v3.6. medic-conf-test-harness version 2
updates the harness to use actual cht-core code so tests behave like your production system. Based on the version of cht-core that your application is using in production, the harness can pull in the appropriate versioned components from cht-core to create an integration test experience which mirrors production.
The version of cht-core which is used to power your tests can be set in harness.defaults.json
:
{
"coreVersion": "3.10.3",
...
}
or each time the harness is instantiated:
const Harness = require('medic-conf-test-harness');
const harness = new Harness({ coreVersion: '3.10.3' });
harness.subject
is a new interface which allows for the easy manipulation and mocking of the contact that is being "acted on" -- "subject of the test". It is intended to replace logic which previously manipulated the awkward harness.content.contact
or harness.state.contacts[0]
.
- The
fillForm()
function simulates completing an app form on the subject's profile page. - The
getContactSummary()
function returns the contact summary displayed for the subject. - The
getTasks()
function returns the tasks listed on the subject's profile page.
harness.subject
can be assigned an object
or a string
.
Assign subject
the _id
together with minified mock contact documents. The harness will hydrate the specified contact.
{
"coreVersion": "3.10.3",
"subject": "patient_id",
"docs": [
{
"_id": "patient_id",
"name": "Sick Bob",
"type": "person",
"parent": {
"_id": "family_id",
"parent": {
"_id": "chw_area_id"
},
}
},
{
"_id": "family_id",
"type": "clinic",
"parent": {
"_id": "chw_area_id"
},
},
]
}
const Harness = require('medic-conf-test-harness');
const harness = new Harness({ subject: 'chw_id', user: 'supervisor_id' });
Assigning subject
an object
skips hydration or any manipulation of the value provided - the exact value set will be the data used. This is powerful and fast, useful for mocking and unit testing - but should likely be avoided for integration testing.
const Harness = require('medic-conf-test-harness');
const harness = new Harness();
harness.subject = {
_id: 'patient_id',
name: 'Sick Bob',
type: 'person',
parent: {
_id: 'family_id',
type: 'clinic',
foo: 'bar',
}
};
Scenario | Before | After |
---|---|---|
Get DoB of the contact I'm testing | harness.content.contact.date_of_birth |
harness.subject.date_of_birth |
Make this test for a family | harness.state.contacts[0] = { _id: 'family', type: 'clinic' } |
harness.subject = 'family_id'; |
What tasks are on the CHWs profile | harness.state.contacts.push(harness.user.parent.contact); |
harness.subject = harness.user; |
Only show tasks for contact I'm testing | harness.state.contacts = [harness.content.contact]; |
default behaviour |
- Tests are now powered by the RulesEngine v2 which was released in cht-core v3.8 which included numerous breaking changes
- Projects running cht-core <3.8 should continue to use medic-conf-test-harness@1.x.
- Typically, if a test breaks because of these changes - that’s a good thing. You have found a bug in the production behaviour of your application.
harness.defaults.json
- New optional string attribute
coreVersion
captures the cht-core version to power your tests (eg. “3.11.0”) - New optional array attribute
docs
defines initial documents in the system - New optional attribute
subject
(see above) - Existing attribute
user
can now also be a string id (see above)
- New optional string attribute
getTasks()
- Passing option
{ resolved: true }
is no longer supported. UsecountTaskDocsByState()
to make assertions about resolved tasks. - Passing option
{ now }
is no longer supported. UsesetNow()
for all datetime mocking. - Return value is now a Task Document. It previously was a task emission, which is equivalent to
ret.emission
except that: 1) emissions contain a minified contact object (name attribute only), 2) emissions contain attributecontent.contact
which is now a minimized contact object (_id
only)
- Passing option
getTargets()
- Passing option
{ now }
no longer supported. UsesetNow()
for all mocking. - Returns
{ total: 0 }
instead ofundefined
when a target has counted nothing.
- Passing option
pushMockedDoc()
- Mocked documents must have a unique
_id
- Stores minified documents (that is the same that the CHT stores)
- Mocked documents must have a unique
- Harness now requires node 10 or above (dropping support for legacy node versions)
getEmittedTargetInstances()
has been removedgetContactSummary
interface is nowasync
loadAction
- Now accepts task documents as input. So instead of callingloadAction(task.actions[0])
, the interface now acceptsloadAction(task)
for tasks with a single action. Useharness.loadAction(task.emission.actions[1])
for task documents with multiple actions.content
content.contact
is automatically populated withharness.subject
(hydrated) if undefinedcontent.contact
is undefined by default
- New interface
countTaskDocsByState()
counts the number of task documents grouped by state. Returns{ Completed: 1, Failed: 2, Ready: 1, ... }
- Enketo form filling updated to support x-path extensions added in cht-core v3.7
This is an experimental project which remains in alpha testing. There may be breaking changes released as patches until version 1.0 is published.
- Removes the
pushMockedReport
interface and replaces it with a newpushMockedDoc
which can accept either report or contact documents. - Deprecates the
loadForm
interface, users should use thefillForm
.