bin/src/cli-main.js
function validateFile(file) {
  let data;
  let err = null;

  // Try to read and parse the file
  try {
    data = JSON.parse(fs.readFileSync(file, 'utf-8'));
  } catch (e) {
    if (e.code === 'ENOENT') {
      err = ERRORS.NOT_FOUND;
    } else if (JsonErrRegex.test(e.message)) {
      err = ERRORS.INVALID_JSON([ e ]);
    } else {
      err = ERRORS.GENERIC;
    }
  }

  // If the file was loaded successfully,
  // validate the json against the TestReport schema
  if (data) {
    const validationResult = t.validate(data, types.TestReport, { strict: true });
    if (!validationResult.isValid()) {
      err = ERRORS.INVALID_JSON(validationResult.errors);
    } else {
      validFiles += 1;
    }
  }

  return {
    filename: file,
    data,
    err
  };
}
function validateFile(file) {
  let data;
  let err = null;

  // Try to read and parse the file
  try {
    data = JSON.parse(fs.readFileSync(file, 'utf-8'));
  } catch (e) {
    if (e.code === 'ENOENT') {
      err = ERRORS.NOT_FOUND;
    } else if (JsonErrRegex.test(e.message)) {
      err = ERRORS.INVALID_JSON([ e ]);
    } else {
      err = ERRORS.GENERIC;
    }
  }

  // If the file was loaded successfully,
  // validate the json against the TestReport schema
  if (data) {
    const validationResult = t.validate(data, types.TestReport, { strict: true });
    if (!validationResult.isValid()) {
      err = ERRORS.INVALID_JSON(validationResult.errors);
    } else {
      validFiles += 1;
    }
  }

  return {
    filename: file,
    data,
    err
  };
}
function validateFile ( file ) { let data ; let err = null ; // Try to read and parse the file try { data = JSON . parse ( fs . readFileSync ( file , 'utf-8' ) ) ; } catch ( e ) { if ( e . code === 'ENOENT' ) { err = ERRORS . NOT_FOUND ; } else if ( JsonErrRegex . test ( e . message ) ) { err = ERRORS . INVALID_JSON ( [ e ] ) ; } else { err = ERRORS . GENERIC ; } } // If the file was loaded successfully, // validate the json against the TestReport schema if ( data ) { const validationResult = t . validate ( data , types . TestReport , { strict : true } ) ; if ( ! validationResult . isValid ( ) ) { err = ERRORS . INVALID_JSON ( validationResult . errors ) ; } else { validFiles += 1 ; } } return { filename : file , data , err } ; }
Validate the data file

@typedef {Object} File
@property {string} filename Name of the file
@property {object} data JSON test data
@property {object} err Error object

@param {string} file File to load/validate

@return {File} Validated file with test data, `err` will be null if valid
Validate the data file