Code coverage report for lib/utils/tabtabDebug.js

# All files / lib/utils tabtabDebug.js

51.85% Statements 14/27
84.62% Branches 11/13
0% Functions 0/1
51.85% Lines 14/27

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
    271x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x

    1x
    1x
    1x
    1xconst debug = require('debug')('tabtab');
    const fs = require('fs');
    const util = require('util');

    /**
     * If TABTAB_DEBUG env is set, make it so that debug statements are also log to
     * TABTAB_DEBUG file provided.
     */
    const tabtabDebug = () => {
      if (process.env.TABTAB_DEBUG) {
        const stream = fs.createWriteStream(process.env.TABTAB_DEBUG, {
          flags: 'a+'
        });

        debug.log = (...args) => {
          args = args.map(arg => {
            if (typeof arg === 'string') return arg;
            return JSON.stringify(arg);
          });

          stream.write(`${util.format(...args)}\n`);
        };
      }
    };

    module.exports = tabtabDebug;