function main()

in closure/testing/phantomjs_harness.js [260:304]


function main() {
  // construct the web page
  var body = fs.read(system.args[1]);
  if (body.match(/^<!/)) {
    system.stderr.writeLine('ERROR: Test html file must not have a doctype');
    phantom.exit(1);
  }
  var html = ['<!doctype html>', body];
  html.push('<script>\n' +
      '  // goog.require does not need to fetch sources from the local\n' +
      '  // server because everything is being loaded explicitly below\n' +
      '  var CLOSURE_NO_DEPS = true;\n' +
      '  var CLOSURE_UNCOMPILED_DEFINES = {\n' +
      // TODO(hochhaus): Set goog.ENABLE_DEBUG_LOADER=false
      // https://github.com/google/closure-compiler/issues/1815
      // '    "goog.ENABLE_DEBUG_LOADER": false\n' +
      '  };\n' +
      '</script>\n');
  for (var i = 2; i < system.args.length; i++) {
    var js = system.args[i];
    html.push('<script src="' + RUNFILES_PREFIX + js + '"></script>\n');
  }
  virtualPageHtml = html.join('');

  // start a local webserver
  var port = Math.floor(Math.random() * (60000 - 32768)) + 32768;
  server = webserver.create();
  server.listen('127.0.0.1:' + port, onRequest);
  url = 'http://localhost:' + port + VIRTUAL_PAGE;
  system.stderr.writeLine('Listening ' + url);

  // run the web page
  page = webpage.create();
  page.onAlert = onAlert;
  page.onCallback = onCallback;
  page.onConsoleMessage = onConsoleMessage;
  page.onError = onError;
  page.onLoadFinished = onLoadFinished;
  page.onResourceTimeout = onResourceTimeout;

  // XXX: If PhantomJS croaks, fail sooner rather than later.
  //      https://github.com/ariya/phantomjs/issues/10652
  page.settings.resourceTimeout = 2000;
  page.open(url);
}