UNPKG

apex-mutation-testing

Version:

Apex mutation testing plugin

43 lines 1.62 kB
// @ts-ignore: Just a proxy doing accumulation of mutations export class MutationListener { coveredLines; listeners; _mutations = []; getMutations() { return this._mutations; } constructor(listeners, coveredLines) { this.coveredLines = coveredLines; this.listeners = listeners; // Share mutations array across all listeners this.listeners .filter(listener => '_mutations' in listener) .forEach(listener => { ; listener._mutations = this._mutations; }); // Create a proxy that automatically forwards all method calls to listeners return new Proxy(this, { get: (target, prop) => { if (prop in target) { return target[prop]; } // Return a function that calls the method on all listeners that have it return (...args) => { if (Array.isArray(args) && args.length > 0) { const ctx = args[0]; if (this.coveredLines.has(ctx?.start?.line)) { this.listeners.forEach(listener => { if (prop in listener && typeof listener[prop] === 'function') { ; listener[prop].apply(listener, args); } }); } } }; }, }); } } //# sourceMappingURL=mutationListener.js.map