kaukau
v4.0.0
Published
JS test tools, Mocha wrapper
Downloads
40
Readme
kaukau
NodeJS test tools, Mocha wrapper.
Install
npm install kaukau --save-dev
Usage
CLI
Set up config file:
kaukau setup
kaukau setup --config kaukau-config.js
kaukau setup --config kaukau-config.js --file tests/
Run tests/
:
kaukau --file tests/
Run custom config:
kaukau --config kaukau-config.js
Run tests/
with custom config:
kaukau start --config kaukau-config.js --file tests/
Other options are available.
Display help:
kaukau --help
Programmatically
Run:
const Kaukau = require('kaukau');
const config = require('./kaukau-config');
const kaukau = new Kaukau(config);
kaukau.run()
// kaukau events
.on('done', function(){ /* done testing */ })
// mocha events (https://mochajs.org/api/runner)
.on('test', function(test) {})
.on('test end', function(test) {})
.on('pass', function(test) {})
.on('fail', function(test, err) {})
.on('end', function() {});
Configuration
A JSON object with the following properties:
enableLogs
: (boolean) Enable/disable kaukau logs. Default:true
.logLevel
: (string)error
,warn
,info
,verbose
,debug
,silly
. Default:silly
. Learn usage here.exitOnFail
: (boolean) Exit after a set of tests fails so it won't execute tests for the next sets of parameters if there are some. Default:false
.files
: (string|string[]) Files and/or directories to be loaded for execution. Default:[]
.ext
: (string) File extensions to be loaded iffiles
contains path to directories. Default:'.js'
.options
: Seemocha
options there.parameters
: (object|object[]) Learn more aboutparameters
option here.
Example:
{
/* kaukau options */
"enableLogs": true,
"exitOnFail": false,
"files": [], // Test files/directories to execute. (e.g.: [ "tests/test01.js" ])
"options": {
/* mocha options */
},
/* sets of parameters */
"parameters": [
{
"kaukauOptions":{
/* Overwrite kaukau options */
},
"mochaOptions":{
/* Overwrite mocha options */
}
/* custom parameters */
// ...
}
]
}
Helpers
The following helpers come with kaukau
.
Parameters
Usefull if you need to run the same tests with different parameters and options.
If you define sets of parameters
in your configuration, the test scripts will be executed for each set.
You can access parameters for the current set running as:
describe('test 01', function() {
const { params } = this.ctx.kaukau;
/**
* In configuration:
* parameters: [
* {
* host: "test.com",
* credentials: {
* email: "[email protected]"
* }
* }
* ]
*/
let host = params('host'); // "test.com"
let email = params('credentials.email'); // "[email protected]"
});
Parameters can overwrite the main configuration by using the properties kaukauOptions
and mochaOptions
.
kaukauOptions
can overwrite files
and ext
.
mochaOptions
can overwrite all mocha options.
Logger
Logging utility.
describe('test 02', function() {
const { logger } = this.ctx.kaukau;
logger.silly('silly level');
logger.debug('debug level');
logger.log('verbose level');
logger.info('info level');
logger.warn('warn level');
logger.error('error level');
});
Tester
Example:
// chai@4
const { expect } = require('chai');
describe('test 03', function() {
const { params, tester } = this.ctx.kaukau;
// set default options (axios.defaults)
tester.setRequestDefaults({});
// overwrite default options
tester.updateRequestDefaults({});
/* request */
it('should be ok', async () => {
const res = await tester.request({
method: 'GET',
url: params('host')
});
expect(res.status).to.equal(200);
});
// or
tester.save({
method: 'GET',
url: params('host')
});
it('should be ok', function(){
expect(this.err).to.equal(null);
expect(this.res.status).to.equal(200);
});
});
Learn more about the options for tester.request
and tester.save
at Axios Request Config.