<commit_before>/**
 * This is the PhantomJS runtime script that invokes the Girder app in test
 * mode. The test mode page is built with grunt and lives at:
 * girder/web_client/static/built/testing/testEnv.html. It then executes a Jasmine spec within
 * the context of that test application, and afterwards runs our custom coverage
 * handler on the coverage data.
 */
/* eslint-disable node/no-deprecated-api */
/* globals phantom, WebPage, jasmine, girderTest */

var fs = require('fs');

var system = require('system');
require('event-source/global');

var args = phantom.args ? phantom.args : system.args.slice(1);

if (args && args.length < 2) {
    console.error('Usage: phantomjs phantom_jasmine_runner.js <page> <spec> [<covg_output> [<default jasmine timeout>]');
    console.error('  <page> is the path to the HTML page to load');
    console.error('  <spec> is the path to the Jasmine spec to run.');
    console.error('  <default Jasmine timeout> is in milliseconds.');
    console.error('  <spec options> is any special spec options, to disambiguate to output filenames.');
    phantom.exit(2);
}

var env = system.env;

var pageUrl = args[0];
var spec = args[1];
var page = new WebPage();

// Determine the test name to be used for output files
var specPathComponents = spec.split('/');
var pluginName =
    specPathComponents[specPathComponents.length - 2] === 'plugin_tests'
        ? specPathComponents[specPathComponents.length - 3]
        : 'core';
var specName = specPathComponents[specPathComponents.length - 1].replace(/\.js$/, '');
var specOptions = args[3];
var testName = pluginName + '_' + specName + (specOptions ? '_' + specOptions : '');

var coverageDir = 'build/test/coverage/web_temp';
fs.makeTree(coverageDir);
var coverageFile = coverageDir + '/coverage_' + testName + '.json';
if (fs.exists(coverageFile)) {
    fs.remove(coverageFile);
}
// write coverage results to a file
function reportCoverage() {
    var cov = page.evaluate(function () {
        return window.__coverage__;
    });
    cov = cov || {};
    fs.write(coverageFile, JSON.stringify(cov), 'w');
}

// Set decent viewport size for screenshots.
page.viewportSize = {
    width: 1024,
    height: 769
};

var artifactDir = 'build/test/artifacts';
fs.makeTree(artifactDir);
page.onConsoleMessage = function (msg) {
    if (msg.indexOf('__SCREENSHOT__') === 0) {
        var screenshotTime = msg.substring('__SCREENSHOT__'.length);
        var screenshotFile = artifactDir + '/screenshot_' + testName + '_' + screenshotTime + '.png';
        page.render(screenshotFile);
        console.log('Created screenshot: ' + screenshotFile);

        if (env['PHANTOMJS_OUTPUT_AJAX_TRACE'] === undefined ||
            env['PHANTOMJS_OUTPUT_AJAX_TRACE'] === 1 ||
            env['PHANTOMJS_OUTPUT_AJAX_TRACE'] === true) {
            console.log(page.evaluate(function () {
                var log = girderTest.ajaxLog(true);
                return 'XHR log (last ' + log.length + '):\n' + JSON.stringify(log, null, '  ');
            }));
        }
        return;
    } else if (msg === 'ConsoleReporter finished') {
        var success = this.page.evaluate(function () {
            return window.jasmine_phantom_reporter.status === 'success';
        });
        if (success) {<commit_msg>Removed unused code from specRunner.js<commit_after>/**
 * This is the PhantomJS runtime script that invokes the Girder app in test
 * mode. The test mode page is built with grunt and lives at:
 * girder/web_client/static/built/testing/testEnv.html. It then executes a Jasmine spec within
 * the context of that test application, and afterwards runs our custom coverage
 * handler on the coverage data.
 */
/* eslint-disable node/no-deprecated-api */
/* globals phantom, WebPage, jasmine, girderTest */

var fs = require('fs');

var system = require('system');
require('event-source/global');

var args = phantom.args ? phantom.args : system.args.slice(1);

if (args && args.length < 2) {
    console.error('Usage: phantomjs phantom_jasmine_runner.js <page> <spec> [<covg_output> [<default jasmine timeout>]');
    console.error('  <page> is the path to the HTML page to load');
    console.error('  <spec> is the path to the Jasmine spec to run.');
    console.error('  <default Jasmine timeout> is in milliseconds.');
    console.error('  <spec options> is any special spec options, to disambiguate to output filenames.');
    phantom.exit(2);
}

var pageUrl = args[0];
var spec = args[1];
var page = new WebPage();

// Determine the test name to be used for output files
var specPathComponents = spec.split('/');
var pluginName =
    specPathComponents[specPathComponents.length - 2] === 'plugin_tests'
        ? specPathComponents[specPathComponents.length - 3]
        : 'core';
var specName = specPathComponents[specPathComponents.length - 1].replace(/\.js$/, '');
var specOptions = args[3];
var testName = pluginName + '_' + specName + (specOptions ? '_' + specOptions : '');

var coverageDir = 'build/test/coverage/web_temp';
fs.makeTree(coverageDir);
var coverageFile = coverageDir + '/coverage_' + testName + '.json';
if (fs.exists(coverageFile)) {
    fs.remove(coverageFile);
}
// write coverage results to a file
function reportCoverage() {
    var cov = page.evaluate(function () {
        return window.__coverage__;
    });
    cov = cov || {};
    fs.write(coverageFile, JSON.stringify(cov), 'w');
}

// Set decent viewport size for screenshots.
page.viewportSize = {
    width: 1024,
    height: 769
};

var artifactDir = 'build/test/artifacts';
fs.makeTree(artifactDir);
page.onConsoleMessage = function (msg) {
    if (msg.indexOf('__SCREENSHOT__') === 0) {
        var screenshotTime = msg.substring('__SCREENSHOT__'.length);
        var screenshotFile = artifactDir + '/screenshot_' + testName + '_' + screenshotTime + '.png';
        page.render(screenshotFile);
        console.log('Created screenshot: ' + screenshotFile);

        return;
    } else if (msg === 'ConsoleReporter finished') {
        var success = this.page.evaluate(function () {
            return window.jasmine_phantom_reporter.status === 'success';
        });
        if (success) {
{'fraction_non_alphanumeric': 0.1354420113544201, 'fraction_numerical': 0.0056772100567721, 'mean_word_length': 3.5238444607483492, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4874828', 'n_tokens_mistral': 1929, 'n_tokens_neox': 1831, 'n_words': 526}