Sha256: 2c48ac9b95f15bc0bbffe677afbd2cb33cded3494311aaccda59389cbfa9d267

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

/*
 * Test runner for phantomjs
 */
var args = phantom.args;
var page = require('webpage').create();

page.onConsoleMessage = function(msg) {
  console.log(msg);
};

page.onInitialized = function() {
  page.evaluate(function () {
    window.OPAL_SPEC_PHANTOM = true;
  });
};

var system = require('system');
page.onCallback = function(data) {
  switch (data[0]) {
  case 'stdout':
    system.stdout.write(data[1] || '');
    break;
  case 'stderr':
    system.stderr.write(data[1] || '');
    break;
  default:
    console.error('Unknown callback data: ', data);
  }
};

/*
 * Exit phantom instance "safely" see - https://github.com/ariya/phantomjs/issues/12697
 * https://github.com/nobuoka/gulp-qunit/commit/d242aff9b79de7543d956e294b2ee36eda4bac6c
 */
function phantom_exit(code) {
  page.close();
  setTimeout(function () { phantom.exit(code); }, 0);
}

page.open(args[0], function(status) {
  if (status !== 'success') {
    console.error("Cannot load: " + args[0]);
    phantom_exit(1);
  } else {
    var timeout = parseInt(args[1] || 60000, 10);
    var start = Date.now();
    var interval = setInterval(function() {
      if (Date.now() > start + timeout) {
        console.error("Specs timed out");
        phantom_exit(124);
      } else {
        var code = page.evaluate(function() {
          return window.OPAL_SPEC_CODE;
        });

        if (code === 0 || code === 1) {
          clearInterval(interval);
          phantom_exit(code);
        }
      }
    }, 500);
  }
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opal-rspec-0.5.0.beta3 vendor/spec_runner.js