Code coverage report for appium-instruments/lib/streams.js

Statements: 36.36% (16 / 44)      Branches: 40% (4 / 10)      Functions: 10% (1 / 10)      Lines: 17.65% (6 / 34)      Ignored: 1 branch     

All files » appium-instruments/lib/ » streams.js
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61        1                   1                               1                     1                           1          
import log from './logger';
import through from 'through';
 
 
function clearBufferChars (output) {
  // Instruments output is buffered, so for each log output we also output
  // a stream of very many ****. This function strips those out so all we
  // get is the log output we care about
  let re = /(\n|^)\*+\n?/g;
  output = output.toString();
  output = output.replace(re, "");
  return output;
}
 
function outputStream () {
  return through(function outputStreamHandler (output) {
    output = clearBufferChars(output);
 
    // if we have multiple log lines, indent non-first ones
    if (output !== '') {
      output = output.replace(/\n$/m, '');
      output = output.replace(/\n/m, '\n       ');
      output = `[INST] ${output}`;
      output = output.green;
      log.debug(output);
    }
    this.queue(output);
  });
}
 
function errorStream () {
  return through(function (output) {
    output = output.replace(/\n$/m, '');
    this.queue(output);
 
    output = (`[INST STDERR] ${output}`);
    output = output.yellow;
    log.debug(output);
  });
}
 
function webSocketAlertStream (webSocket) {
  return through(function (output) {
    if (webSocket) {
      let re = /Call to onAlert returned 'YES'/;
      let match = re.test(output);
      if (match) {
        log.debug('Emiting alert message...');
        webSocket.sockets.emit('alert', {message: output});
      }
    }
    this.queue(output);
  });
}
 
function dumpStream () {
  return through(function () {});
}
 
export { outputStream, errorStream, webSocketAlertStream, dumpStream };