All files dev.ts

100% Statements 34/34
100% Branches 10/10
100% Functions 5/5
100% Lines 34/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46          1x 13x 13x 13x   13x 13x 13x 13x 13x   13x 78x 50x 50x 28x 78x   13x 15x 2x 2x 13x 13x 13x 15x   13x 2x 1x 1x 1x 1x 1x 2x 13x   1x   1x  
export interface DevMessage {
  type: 'warn' | 'notice';
  args: unknown[];
}
 
class DevMessages {
  _skip = false;
  displayed: DevMessage[] = [];
  skipped: DevMessage[] = [];
 
  constructor() {
    this.skip = this.skip.bind(this);
    this.warn = this.warn.bind(this);
    this.notice = this.notice.bind(this);
  }
 
  skip(skip?: boolean) {
    if (skip === undefined) {
      return this._skip;
    }
    return (this._skip = skip);
  }
 
  warn(...args: unknown[]) {
    if (!this._skip) {
      this.displayed.push({ type: 'warn', args });
      console.warn(...args);
    } else {
      this.skipped.push({ type: 'warn', args });
    }
  }
 
  notice(...args: unknown[]) {
    if (!this._skip) {
      this.displayed.push({ type: 'notice', args });
      console.trace('⚠️', ...args);
    } else {
      this.skipped.push({ type: 'notice', args });
    }
  }
}
 
const devMessages = new DevMessages();
export { devMessages };
export const skipDevMessages = devMessages.skip;