function readChecks(filename, timeout) {
  const checks = File.readFileSync(filename, 'utf-8')
    .split(/[\n\r]+/)                     // Split into lines
    .map(line => line.trim())             // Ignore leading/trailing spaces
    .filter(line => line.length)          // Ignore empty lines
    .filter(line => line[0] !== '#')      // Ignore comments
    .filter(line => !/^\w+=/.test(line))  // Ignore name = value pairs
    .map(function(line) {             // Split line to URL + expected value
      const match = line.match(/^(\S+)\s*(.*)/);
      return {
        url:      match[1],
        expected: match[2]
      };
    })
    .map(function(check) {            // Valid URLs only
      // URLs may be relative to the server, so contain an absolute path
      const url = URL.parse(check.url);
      assert(url.pathname && url.pathname[0] === '/', 'Check URL must have absolute pathname');
      assert(!url.protocol || /^https?:$/.test(url.protocol), 'Check URL may only use HTTP/S protocol');
      return check;
    })
    .reduce(function(memo, check) {
      const url = check.url;
      memo[url] = memo[url] || []; // eslint-disable-line
      if (check.expected)
        memo[url].push(check.expected);
      return memo;
    }, {});

  // Returns a check function that will use these checks / settings
  const context = {
    checks:   checks,
    timeout:  timeout
  };
  debug('Added %d checks', checks.length);

  return checkFunction.bind(context);
}
// Read the checks file and returns a check function (see checkFunction).
Read the checks file and returns a check function .
Read the checks file and returns a check function .
function readChecks(filename, timeout) {
  const checks = File.readFileSync(filename, 'utf-8')
    .split(/[\n\r]+/)                     
    .map(line => line.trim())             
    .filter(line => line.length)          
    .filter(line => line[0] !== '#')      
    .filter(line => !/^\w+=/.test(line))  
    .map(function(line) {             
      const match = line.match(/^(\S+)\s*(.*)/);
      return {
        url:      match[1],
        expected: match[2]
      };
    })
    .map(function(check) {            
      const url = URL.parse(check.url);
      assert(url.pathname && url.pathname[0] === '/', 'Check URL must have absolute pathname');
      assert(!url.protocol || /^https?:$/.test(url.protocol), 'Check URL may only use HTTP/S protocol');
      return check;
    })
    .reduce(function(memo, check) {
      const url = check.url;
      memo[url] = memo[url] || []; 
      if (check.expected)
        memo[url].push(check.expected);
      return memo;
    }, {});
  const context = {
    checks:   checks,
    timeout:  timeout
  };
  debug('Added %d checks', checks.length);
  return checkFunction.bind(context);
}
function readChecks ( filename , timeout ) { const checks = File . readFileSync ( filename , 'utf-8' ) . split ( / [\n\r]+ / ) . map ( line => line . trim ( ) ) . filter ( line => line . length ) . filter ( line => line [ 0 ] !== '#' ) . filter ( line => ! / ^\w+= / . test ( line ) ) . map ( function ( line ) { const match = line . match ( / ^(\S+)\s*(.*) / ) ; return { url : match [ 1 ] , expected : match [ 2 ] } ; } ) . map ( function ( check ) { const url = URL . parse ( check . url ) ; assert ( url . pathname && url . pathname [ 0 ] === '/' , 'Check URL must have absolute pathname' ) ; assert ( ! url . protocol || / ^https?:$ / . test ( url . protocol ) , 'Check URL may only use HTTP/S protocol' ) ; return check ; } ) . reduce ( function ( memo , check ) { const url = check . url ; memo [ url ] = memo [ url ] || [ ] ; if ( check . expected ) memo [ url ] . push ( check . expected ) ; return memo ; } , { } ) ; const context = { checks : checks , timeout : timeout } ; debug ( 'Added %d checks' , checks . length ) ; return checkFunction . bind ( context ) ; }
Read the checks file and returns a check function (see checkFunction).
Read the checks file and returns a check function ( see checkFunction ) .
// Split into lines // Ignore leading/trailing spaces // Ignore empty lines // Ignore comments // Ignore name = value pairs // Split line to URL + expected value // Valid URLs only // URLs may be relative to the server, so contain an absolute path // eslint-disable-line // Returns a check function that will use these checks / settings