<commit_before>'use strict';

var inherit = require('inherit'),
    _ = require('lodash'),
    q = require('q'),
    Runner = require('../runner'),

    RunnerEvents = require('../../constants/runner-events'),
    PrivateEvents = require('../private-events'),

    NoRefImageError = require('../../errors/no-ref-image-error'),
    StateError = require('../../errors/state-error');

var StateRunner = inherit(Runner, {
    __constructor: function(state, browserSession, config) {
        this._state = state;
        this._browserSession = browserSession;
        this._config = config;
        this._stateInfo = {
            suite: state.suite,
            state: state,
            browserId: browserSession.browser.id,
            sessionId: browserSession.browser.sessionId
        };
    },

    run: function(stateProcessor) {
        var _this = this;

        _this.emit(RunnerEvents.BEGIN_STATE, this._stateInfo);

        var session = this._browserSession;

        return session.runActions(this._state.actions)
            .then(function() {
                return session.prepareScreenshot(_this._state, {coverage: _this._config.isCoverageEnabled()});
            })
            .fail(function(e) {
                return session.extendWithPageScreenshot(e)
                    .thenReject(e);
            })
            .then(function(pageDisposition) {
                return _this._capture(stateProcessor, pageDisposition);
            })
            .fail(function(e) {
                _.extend(e, _this._stateInfo);

                if (e instanceof NoRefImageError || e instanceof StateError) {
                    _this.emit(RunnerEvents.ERROR, e);
                } else {
                    return q.reject(e);
                }
            })
            .fin(function() {
                _this.emit(RunnerEvents.END_STATE, _this._stateInfo);<commit_msg>Always emit an error event if a state failed<commit_after>'use strict';

var inherit = require('inherit'),
    _ = require('lodash'),
    Runner = require('../runner'),

    RunnerEvents = require('../../constants/runner-events'),
    PrivateEvents = require('../private-events');

var StateRunner = inherit(Runner, {
    __constructor: function(state, browserSession, config) {
        this._state = state;
        this._browserSession = browserSession;
        this._config = config;
        this._stateInfo = {
            suite: state.suite,
            state: state,
            browserId: browserSession.browser.id,
            sessionId: browserSession.browser.sessionId
        };
    },

    run: function(stateProcessor) {
        var _this = this;

        _this.emit(RunnerEvents.BEGIN_STATE, this._stateInfo);

        var session = this._browserSession;

        return session.runActions(this._state.actions)
            .then(function() {
                return session.prepareScreenshot(_this._state, {coverage: _this._config.isCoverageEnabled()});
            })
            .fail(function(e) {
                return session.extendWithPageScreenshot(e)
                    .thenReject(e);
            })
            .then(function(pageDisposition) {
                return _this._capture(stateProcessor, pageDisposition);
            })
            .fail(function(e) {
                _.extend(e, _this._stateInfo);

                return _this.emit(RunnerEvents.ERROR, e);
            })
            .fin(function() {
                _this.emit(RunnerEvents.END_STATE, _this._stateInfo);
{'fraction_non_alphanumeric': 0.12102093490106108, 'fraction_numerical': 0.0, 'mean_word_length': 1.9409780775716694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5030194', 'n_tokens_mistral': 938, 'n_tokens_neox': 893, 'n_words': 158}