<commit_before>'use strict';

var _ = require('lodash'),
    inherit = require('inherit'),
    lib = require('./lib'),
    TestCounter = require('../utils/test-counter');

var NO_STATE = 'NO_STATE';

module.exports = inherit({
    /**
     * @constructor
     */
    __constructor: function() {
        this._tree = {name: 'root'};
        this._skips = [];
        this._counter = new TestCounter();
    },

    /**
     * @param {StateResult} result
     */
    addSkipped: function(result) {
        this._addTestResult(result, {
            name: result.browserId,
            skipped: true,
            reason: result.suite.skipComment
        });

        var comment = result.suite.skipComment
            && result.suite.skipComment.replace(/https?:\/\/[^\s]*/g, function(url) {
                return '<a target="_blank" href="' + url + '">' + url + '</a>';
            });
        this._skips.push({suite: result.suite.fullName, browser: result.browserId, comment: comment});

        this._counter.onSkipped(result);
    },

    /**
     * @param {TestStateResult} result
     */
    addSuccess: function(result) {
        this._addTestResult(result, {
            name: result.browserId,
            success: true,
            actualPath: lib.currentPath(result),
            expectedPath: lib.referencePath(result)
        });

        this._counter.onPassed(result);
    },

    /**
     * @param {TestStateResult} result
     */
    addFail: function(result) {
        this._addTestResult(result, {
            name: result.browserId,
            fail: true,
            actualPath: lib.currentPath(result),
            expectedPath: lib.referencePath(result),
            diffPath: lib.diffPath(result)
        });

        this._counter.onFailed(result);
    },

    /**
     * @param {ErrorStateResult} result
     */
    addError: function(result) {
        this._addTestResult(result, {
            name: result.browserId,
            actualPath: result.state? lib.currentPath(result) : '',
            error: true,
            image: !!result.image || !!result.currentPath,
            reason: (result.stack || result.message || result || '')
        });

        this._counter.onFailed(result);
    },

    /**
     * @param {WarningStateResult} result
     */
    addWarning: function(result) {
        this._addTestResult(result, {
            name: result.browserId,
            warning: true,
            actualPath: lib.currentPath(result),
            reason: (result.message || '')
        });

        this._counter.onSkipped(result);
    },

    /**
     * @returns {ViewModelResult}
     */
    getResult: function() {
        return _.extend(this._counter.getResult(), {
            skips: _.uniq(this._skips, JSON.stringify),
            suites: this._tree.children
        });<commit_msg>Show page screenshot on error<commit_after>'use strict';

var _ = require('lodash'),
    inherit = require('inherit'),
    lib = require('./lib'),
    TestCounter = require('../utils/test-counter');

var NO_STATE = 'NO_STATE';

module.exports = inherit({
    /**
     * @constructor
     */
    __constructor: function() {
        this._tree = {name: 'root'};
        this._skips = [];
        this._counter = new TestCounter();
    },

    /**
     * @param {StateResult} result
     */
    addSkipped: function(result) {
        this._addTestResult(result, {
            name: result.browserId,
            skipped: true,
            reason: result.suite.skipComment
        });

        var comment = result.suite.skipComment
            && result.suite.skipComment.replace(/https?:\/\/[^\s]*/g, function(url) {
                return '<a target="_blank" href="' + url + '">' + url + '</a>';
            });
        this._skips.push({suite: result.suite.fullName, browser: result.browserId, comment: comment});

        this._counter.onSkipped(result);
    },

    /**
     * @param {TestStateResult} result
     */
    addSuccess: function(result) {
        this._addTestResult(result, {
            name: result.browserId,
            success: true,
            actualPath: lib.currentPath(result),
            expectedPath: lib.referencePath(result)
        });

        this._counter.onPassed(result);
    },

    /**
     * @param {TestStateResult} result
     */
    addFail: function(result) {
        this._addTestResult(result, {
            name: result.browserId,
            fail: true,
            actualPath: lib.currentPath(result),
            expectedPath: lib.referencePath(result),
            diffPath: lib.diffPath(result)
        });

        this._counter.onFailed(result);
    },

    /**
     * @param {ErrorStateResult} result
     */
    addError: function(result) {
        this._addTestResult(result, {
            name: result.browserId,
            actualPath: result.state? lib.currentPath(result) : '',
            error: true,
            image: !!result.imagePath || !!result.currentPath,
            reason: (result.stack || result.message || result || '')
        });

        this._counter.onFailed(result);
    },

    /**
     * @param {WarningStateResult} result
     */
    addWarning: function(result) {
        this._addTestResult(result, {
            name: result.browserId,
            warning: true,
            actualPath: lib.currentPath(result),
            reason: (result.message || '')
        });

        this._counter.onSkipped(result);
    },

    /**
     * @returns {ViewModelResult}
     */
    getResult: function() {
        return _.extend(this._counter.getResult(), {
            skips: _.uniq(this._skips, JSON.stringify),
            suites: this._tree.children
        });
{'fraction_non_alphanumeric': 0.1443699258736322, 'fraction_numerical': 0.0, 'mean_word_length': 1.9317123642007243, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2992465', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1573, 'n_words': 274}