This module exposes a wrapper testRunner
around the ACT Rules Testcases for each of the rules in ACT Rules Repository, thereby allowing to execute a given evaluation function against the test case as a document context.
Code snippet, showing various ways to use the testRunner
.
const testRunner = require('testrunner')
// testrunner refers to file entry file `src/index.js`
// execute async
const results = await testRunner(config);
// or execute as a promise chain
testRunner(options)
.then(results => {
// explore results
})
.catch(error => {
// handle error
})
Members of the config
object passed to the testRunner
.
Name | Type | Default Value | Description |
---|---|---|---|
config.debug |
Boolean |
false |
(Optional) Runs the testRunner in debug mode, which launches each test case page in a chromium (non-headless) mode |
config.injectScripts |
Array<String>[] |
undefined |
(Optional) A list of path or url of scripts to be injected into the puppeteer page context |
config.globals |
Object |
undefined |
(Mandatory) An object containing key-value pairs of variables or functions to be mounted as a global variable in the puppeteer page context for usage by the evaluate function |
config.globals.rulesMap |
Object |
- | (Mandatory) An object containing key-value pairs of ruleId of each act-r rule mapped to a uniqueId of rule(s) to run against a chosen test tool |
config.evaluate |
Function |
-` | (Mandatory) A function containing logic to be evaluated on the page context |
An example configuration object is as below:
const config = {
debug: false,
injectScripts: [
'https://code.jquery.com/jquery-3.3.1.min.js'
// can be relative paths to any scripts as well, (eg: `../../myscript.js`)
],
globals: {
rulesMap
// this can also contain functions to be made available on the page context
// eg: myLogger: function(data) { console.log(data) }
},
evaluate: () => {
// logic to be evaluated within the page context.
}
}
To help define a 1 to 1
or 1 to Many
relationship between ACT Rules and the test tool, an object of key-value
pairs must be defined with the key rulesMap
in the config.globals
.
A sample template to build mappings, showing each of the ACT Rules with their ids, can be seen here
An example mapping is as below:
const rulesMap = {
'SC1-3-5-autocomplete-valid': ['autocomplete-valid']
}
If no mapping is defined an error is thrown by the module.
Some notable libraries used to build this module are:
- axios for
XMLHttpRequest
management. - puppeteer for executing a given test case in a headless chromium page context.
- jest for testing.
For a full list of dependencies refer package.json
src
directory contains the library code.test
directory contains testing code.example
directory shows a sample usage of the module.
There is no build
mechanism for this module. The entry point is set to src/index.js
npm run dev
runsprettier
to format, thenlint
, thentest
, followed byexample
usage.npm run lint
runseslint
across all.js
files.npm run test
runs test and reports coverage both in terminal andcoverage
directory.npm run format
runsprettier
on the code base to format tostandard
code style.
For a full list of scripts refer package.json