Event coverage and debugging (#160)
This patch introduces event coverage for DEBUG module and API coverage. Closes #50.
This commit is contained in:
parent
3c75767288
commit
8780fcb662
@ -137,13 +137,35 @@ class Helper {
|
||||
});
|
||||
}
|
||||
|
||||
if (classType.Events) {
|
||||
if (apiCoverage) {
|
||||
for (let event of Object.values(classType.Events))
|
||||
apiCoverage.set(`${className}.emit(${JSON.stringify(event)})`, false);
|
||||
}
|
||||
const method = Reflect.get(classType.prototype, 'emit');
|
||||
Reflect.set(classType.prototype, 'emit', function(event, ...args) {
|
||||
let argsText = [JSON.stringify(event)].concat(args.map(stringifyArgument)).join(', ');
|
||||
if (debug.enabled)
|
||||
debug(`${className}.emit(${argsText})`);
|
||||
if (apiCoverage && this.listenerCount(event))
|
||||
apiCoverage.set(`${className}.emit(${JSON.stringify(event)})`, true);
|
||||
return method.call(this, event, ...args);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Object} arg
|
||||
* @return {string}
|
||||
*/
|
||||
function stringifyArgument(arg) {
|
||||
if (typeof arg !== 'function')
|
||||
if (typeof arg !== 'function') {
|
||||
try {
|
||||
return JSON.stringify(arg);
|
||||
} catch (e) {
|
||||
// The object was recursive
|
||||
return arg.toString();
|
||||
}
|
||||
}
|
||||
let text = arg.toString().split('\n').map(line => line.trim()).join('');
|
||||
if (text.length > 20)
|
||||
text = text.substring(0, 20) + '…';
|
||||
|
@ -1423,7 +1423,7 @@ if (process.env.COVERAGE) {
|
||||
}
|
||||
|
||||
for (let method of coverage.keys()) {
|
||||
(disabled.has(method) ? xit : it)(`public method '${method}' should be called`, SX(async function(){
|
||||
(disabled.has(method) ? xit : it)(`public api '${method}' should be called`, SX(async function(){
|
||||
expect(coverage.get(method)).toBe(true);
|
||||
}));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user