A simple Karma reporter for logging json messages from matchers and specs.
Install from NPM:
npm install karma-json-log-reporter
Required Karma configuration includes typical wire-up via Karma plug-ins and reporters, and optionally specifying the destination path for JSON output:
{
"jsonLogReporter": {
"outputPath": "test/some/path/"
},
"plugins": [
"karma-json-log-reporter"
],
"reporters": ["json-log"]
}
JSON logged via console.log and window.dump is sent to the default JSON file 'logFile_timestamp.json'.
window.dump( JSON.stringify( obj ) );
console.log( JSON.stringify( obj ) );
Alternatively, if an object is provided with a name and object, the object is logged to a file according to the specified name, ex. 'myObjectName.json'.
var obj = {
'name': 'myObjectName',
'object': objectToLog
};
window.dump( JSON.stringify( obj ) );
Note: if the target file exists with an object, the new object is merged with the existing object and the existing file is updated.
To overwrite, add to Karma configuration:
{
"jsonLogReporter": {
"overwrite": true
}
}