JS test tools, Mocha wrapper
npm install kaukaubash
npm install kaukau --save-dev
`
Usage
$3
Set up config file:
`bash
kaukau setup
`
`bash
kaukau setup --config kaukau-config.js
`
`bash
kaukau setup --config kaukau-config.js --file tests/
`
Run tests/:
`bash
kaukau --file tests/
`
Run custom config:
`bash
kaukau --config kaukau-config.js
`
Run tests/ with custom config:
`bash
kaukau start --config kaukau-config.js --file tests/
`
Other options are available.
Display help:
`bash
kaukau --help
`
$3
Run:
`js
const Kaukau = require('kaukau');
const config = require('./kaukau-config');
const kaukau = new Kaukau(config);
kaukau.run()
// kaukau events
.on('done', function(totalFailures){ / 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|string[]) File extensions to be loaded if files contains path to directories. Default: ['.js', '.mjs', '.cjs'].
- options: See mocha options there.
- parameters: (object|object[]) Learn more about parameters option here.
Example:
`js
{
/ 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.
$3
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:
`js
describe('test 01', function() {
const { params } = this.ctx.kaukau;
/**
* In configuration:
* parameters: [
* {
* host: "test.com",
* credentials: {
* email: "test@test.com"
* }
* }
* ]
*/
let host = params('host'); // "test.com"
let email = params('credentials.email'); // "test@test.com"
});
`
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.
$3
Logging utility.
`js
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');
});
`
$3
Example:
`js
// 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);
});
});
`
📝 Notes
* To run TypeScript test files (e.g. test/example.test.ts), make sure to install the required dependencies:
`sh
npm install --save-dev ts-node @types/mocha
`
* Then, you can run your test file using:
`sh
kaukau --require ts-node/register --file test/example.test.ts
`
> 💡 This enables TypeScript support via ts-node`, and provides the necessary type definitions for Mocha-style tests.