All files / lib/agents d8.js

96.15% Statements 25/26
94.12% Branches 16/17
100% Functions 3/3
96.15% Lines 25/26

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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65    1x 1x 1x 1x   1x       151x 3x     151x 2x     151x   151x       150x 150x 117x   33x     33x     33x             33x               150x   150x 33x 33x     150x       1x   1x  
'use strict';
 
const fs = require('fs');
const runtimePath = require('../runtime-path');
const ConsoleAgent = require('../ConsoleAgent');
const ErrorParser = require('../parse-error.js');
 
const errorRe = /(.*?):(\d+): (([\w\d]+)(?:: (.*))?)[\w\W]*(\3((:?\s+at.*\r?\n)*)(\r?\n)+)?$/;
 
class D8Agent extends ConsoleAgent {
  async evalScript(code, options = {}) {
    if (options.module && this.args[0] !== '--module') {
      this.args.unshift('--module');
    }
 
    if (!options.module && this.args[0] === '--module') {
      this.args.shift();
    }
 
    this.args.push('--expose-gc');
 
    return super.evalScript(code, options);
  }
 
  parseError(str) {
    const match = str.match(errorRe);
    if(!match) {
      return null;
    }
    const stackStr = match[6] || '';
 
    let stack;
    Iif (stackStr.trim().length > 0) {
      stack = ErrorParser.parseStack(stackStr);
    } else {
      stack = [{
        source: match[0],
        fileName: match[1],
        lineNumber: match[2]
      }];
    }
 
    return {
      name: match[4],
      message: match[5],
      stack: stack,
    };
  }
 
  normalizeResult(result) {
    const match = result.stdout.match(errorRe);
 
    if (match) {
      result.stdout = result.stdout.replace(errorRe, '');
      result.stderr = match[0];
    }
 
    return result;
  }
}
 
D8Agent.runtime = fs.readFileSync(runtimePath.for('d8'), 'utf8');
 
module.exports = D8Agent;