@conterra/mapapps-mocha-runner
v1.1.1
Published
A support lib for mocha test integration into map.apps.
Downloads
961
Keywords
Readme
@conterra/mapapps-mocha-runner
A support lib for mocha as test runner in map.apps based projects. See https://mochajs.org/ how to write tests. The runner initializes the bdd test style of mocha.
Usage
If the module is available within the js-registry, tests can be executed with an URL like this:
This URL will load a test-init.js
file, which configures the AMD loader.
It will enable the intern
adapter to allow execution of old intern
based tests.
And it executes all tests specified by apprt-core/tests/intern-all
.
Possible URL parameters are:
| Name | Description | | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | boot | comma separated list of initialization files | | test | comma separated list tests to load | | grep | A regular expressions, which filters the tests to execute | | timeout | default global timeout of test executions, defaults to 5000msec | | reporter | the reporter to use, defaults to 'html'. Use 'tap' for puppeteer test execution, see https://mochajs.org/#reporters | | reportOnEnd | Flag for the 'html' reporter. Use reportOnEnd=false, to enable appending the test reports during test execution (note: reduces performance) | | registerInternAdapter | Flag to register an amd module which mocks 'intern!object' and 'intern/chai!assert' imports and converts intern tests into mocha bdd tests |
Pre-Requisites
The 'mapapps-mocha-runner' requires the packages 'mocha' and 'chai' to work correctly. Both packages must be available in one of the js-registries.
The packages are normally made available inside a project using the packages.json
:
"devDependencies": {
...
"@conterra/mapapps-mocha-runner": "^1.0.2",
"chai": "^4.3.4",
"mocha": "^10.0.0"
...
}
Additionally, the js-registry needs to be configured to serve these packages. This part depends on the registry implementation used and can be configured. If the java (embedded) js-registry (since 1.4.3) is used, there are two properties, which allow the scanning of the 'node_modules' folder for dev dependencies:
jsregistry.directoryscanner.npmfolder=${basedir}/node_modules
jsregistry.directoryscanner.npmincludes=mocha,chai,@conterra,@conterra/mapapps-mocha-runner
If the browser-sync
js-registry is used, then in the gulpfile.js
the packages needs to be listed:
mapappsBrowserSync.registerTask(
{
port: 8080,
jsreg: {
npmModules: ["mocha", "chai", "@conterra/mapapps-mocha-runner"]
}
},
gulp
);
Configuration
A test-init.js
is responsible to configure the AMD loader, and e.g. define which js-registries should be requested for packages.
It may look like:
testConfig({
// (optional) load apprt-polyfill before all tests start
deps: ["apprt-polyfill"],
// (optional) which js registry should be requested for packages
// if left out the default registry and and all packages within the registry are registered
jsregistry: [
{
// (optional) if left out the default registry is used
root: "url to registry..",
// packages: ["*"] means all packages of the registry
packages: [
// list of packages registered from this registry
"app-uitest-support",
"test-utils",
"uitest",
"apprt",
"apprt-core"
]
}
],
// (optional) register custom manual packages
packages: [
{
name: "test-apps",
location: "@@application.base.url@@/js/tests/test-apps"
}
]
});