{"size": 913, "ext": "js", "max_stars_repo_path": "original/angular.js-1.7.5/test/e2e/tools/util.js", "max_stars_repo_name": "skylarkfw/skylark-angular2", "max_stars_repo_stars_event_min_datetime": "2015-01-01T00:37:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T19:56:53.000Z", "max_issues_repo_path": "test/e2e/tools/util.js", "max_issues_repo_name": "gbtec-reneschanzenbaecher/angular.js", "max_issues_repo_issues_event_min_datetime": "2015-01-01T01:54:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T03:50:58.000Z", "max_forks_repo_path": "test/e2e/tools/util.js", "max_forks_repo_name": "gbtec-reneschanzenbaecher/angular.js", "max_forks_repo_forks_event_min_datetime": "2015-01-01T04:57:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T06:56:41.000Z"}
{"max_stars_count": 41342, "max_issues_count": 7460, "max_forks_count": 28291, "avg_line_length": 20.2888888889, "max_line_length": 64, "alphanum_fraction": 0.6067907996}
'use strict';

var fs = require('fs');
var path = require('path');

var root = path.resolve(__dirname, '..');
var tests = path.resolve(root, 'fixtures');

function stat(path) {
  try {
    return fs.statSync(path);
  } catch (e) {
    // Ignore ENOENT.
    if (e.code !== 'ENOENT') {
      throw e;
    }
  }
}

function testExists(testname) {
  var s = stat(path.resolve(tests, testname));
  return s && s.isDirectory();
}

function rewriteTestFile(testname, testfile) {
  if (testfile.search(/^https?:\/\//) === 0) {
    return testfile;
  }

  var i = 0;
  while (testfile[i] === '/') ++i;
  testfile = testfile.slice(i);
  var s = stat(path.resolve(tests, testname, testfile));
  if (s && (s.isFile() || s.isDirectory())) {
    return ['/test/e2e/fixtures', testname, testfile].join('/');
  }
  return false;
}

module.exports = {
  stat: stat,
  testExists: testExists,
  rewriteTestFile: rewriteTestFile
};
