assert.strictEqual(sinon?.constructor?.name, 'Sandbox', 'sinon dependency not recognized');
this.sinon = sinon;
const logger = (process.env.VERBOSE_TESTS || verbose) ? console : this.constructor._nullLogger;
- Object.keys(this.constructor._nullLogger).forEach((level) => {
- this[level] = logger[level]; // eslint-disable-line security/detect-object-injection
- this.sinon.spy(this, level);
- });
+ // eslint-disable-next-line security/detect-object-injection
+ this.constructor._levels.forEach((level) => this[level] = logger[level]);
+ this._spy();
}
+ /**
+ * Default log levels are nop.
+ * @returns {object} nop log levels
+ */
static get _nullLogger() {
return {
error: () => undefined,
};
}
+ /**
+ * Returns names of all log levels.
+ * @returns {string[]} list of log level names
+ */
static get _levels() {
return Object.keys(this._nullLogger);
}
+ /**
+ * Install spies on all log levels.
+ */
+ _spy() {
+ this.constructor._levels.forEach((level) => this.sinon.spy(this, level));
+ }
+
+ /**
+ * Reset spies on all log levels.
+ */
_reset() {
this.constructor._levels.forEach((level) => this[level].resetHistory()); // eslint-disable-line security/detect-object-injection
}