2.0.0 • Published 2 years ago
@oat-sa/tao-qunit-testrunner v2.0.0
tao-qunit-testrunner-fe
TAO Frontend Unit & Integration Test Runner based on QUnit and Puppeteer
How to use
Run all tests:
npx qunit-testrunner
Run specific test:
npx qunit-testrunner <testname>
Enable coverage:
npx qunit-testrunner --cov
Display coverage report
Requirement: npm install nyc
npx nyc report
Generate html coverage report
Requirement: npm install nyc
npx nyc report --reporter=lcov
Environment variables
| Option name | Description | Type | Default |
|---|---|---|---|
| PARALLEL_TESTS | Define the amount of parallel tests | number | 5 |
| REDIRECT_CONSOLE | Redirects browser console to terminal | boolean | false |
Command line arguments
| Option name | Description | Type | Default |
|---|---|---|---|
| --config, -c | Define config file | string | .qunit-testrunner.config.json |
| --test-dir, -d | Test directory name in root | string | test |
| --root, -r | Root directory name | string | process.cwd() |
| --spec | Test files pattern | glob | **/test.html |
| --mock-api | Enables API Mock middleware | boolean | false |
| --without-server | Start testrunner without server | boolean | false |
| --reporter | Test result reporter (json, basic, stats | ||
| or custom path) | string | basic | |
| --verbose, -v, -vv ... | Verbose level | count | 0 |
| --help -h | Display help | boolean | false |
| Webserver options | |||
| --keepalive | Do not run tests just start webserver | boolean | false |
| --host | Webserver host | string | 127.0.0.1 |
| --port, -p | Webserver port | number | random free port |
| Coverage options | |||
| --coverage, --cov | Enable coverage measurement | boolean | false |
| --coverage-instrument-spec | Coverage instrument pattern from root | glob | src/**/*.js |
| --coverage-output-dir | Coverage output directory in root | string | .nyc_output |
| --clear-coverage-dir | Clear the coverage output directory before running | ||
| test, when coverage option is enabled | bool | true |
Config file
In the config file, all command line argument can be defined. If an argument is defined in config and in command line as well, the command line value overrides config value.
.qunit-testrunner.config.json:
{
"verbose": 1,
"testDir": "exampleTest",
"coverage": true,
"coverage-instrument-spec": "exampleSrc/**/*.js",
"port": 8082
}Recommended package.json scripts:
package.json:
"scripts": {
"test": "npx qunit-testrunner",
"test:keepAlive": "npx qunit-testrunner --keepalive",
"test:cov": "npx qunit-testrunner --cov",
"coverage": "nyc report",
"coverage:html": "nyc report --reporter=lcov && open-cli coverage/lcov-report/index.html"
}Coverage measurement description
- Source files are instrumented when they are requested.
--coverage-instrument-specdefines the pattern. QUnit.doneevent listener is injected into test.htmlfiles. Injector injects into every files based on--specpattern and puts event handler after<head>- Handler post
__coverage__result back to/__coverage__/[original path], like/test/foo/bar.html->/__coverage__/foo/bar.html. istanbulCoveragemiddleware collects coverage results and saves them into the directory provided by--coverage-output-dir. The file name is an md5 hash generated from coverage url.nyccan generate coverage report based on coverage measurement.nyc reportornyc report --reporter=lcov
Small hack that generates empty coverage objects, so report will show totally uncovered files as well:
npx nyc --instrument --include <src glob> --all --silent echo