<commit_before>"use strict";

var browserSync   = require("../../../index");

var sinon   = require("sinon");
var assert  = require("chai").assert;

describe("E2E Responding to events", function () {

    var instance, socketsStub, clock;

    before(function (done) {

        var config = {
            server: {
                baseDir: __dirname + "/../../fixtures"
            },
            files: ["test/fixtures/assets/*.css"],
            debugInfo: false,
            open: false
        };

        instance = browserSync.init(config, function () {
            socketsStub = sinon.stub(instance.io.sockets, "emit");
            done();
        });

        clock = sinon.useFakeTimers();
    });

    afterEach(function () {
        socketsStub.reset();
        instance.paused = false;
    });
    after(function () {
        socketsStub.restore();
        instance.cleanup();
        clock.restore();
    });

    it("fires the file:reload event to the browser", function () {

        // Emit the event as it comes from the file-watcher
        instance.events.emit("file:changed", {path: "styles.css", log: true, namespace: "core"});

        clock.tick();

        var eventName = socketsStub.getCall(0).args[0];
        var args      = socketsStub.getCall(0).args[1];

        assert.equal(eventName, "file:reload");         // check correct event sent to client
        assert.equal(args.assetFileName, "styles.css"); // Check the asset name is sent
        assert.isFalse(instance.paused);
    });

    it("doesn't fire the file:reload event to the browser when paused", function () {
        instance.paused = true;

        // Emit the event as it comes from the file-watcher
        instance.events.emit("file:changed", {path: "styles.css", log: true, namespace: "core"});

        clock.tick();

        assert.isTrue(socketsStub.withArgs("file:reload").notCalled); // should not be called
        assert.isTrue(instance.paused);
    });

    it("Sets `log: false` if `log` is undefined in event", function () {

        // Emit the event as it comes from the file-watcher
        instance.events.emit("file:changed", {path: "styles.css", namespace: "core"});

        clock.tick();
<commit_msg>add test to ensure unpausing functions properly<commit_after>"use strict";

var browserSync   = require("../../../index");

var sinon   = require("sinon");
var assert  = require("chai").assert;

describe("E2E Responding to events", function () {

    var instance, socketsStub, clock;

    before(function (done) {

        var config = {
            server: {
                baseDir: __dirname + "/../../fixtures"
            },
            files: ["test/fixtures/assets/*.css"],
            debugInfo: false,
            open: false
        };

        instance = browserSync.init(config, function () {
            socketsStub = sinon.stub(instance.io.sockets, "emit");
            done();
        });

        clock = sinon.useFakeTimers();
    });

    afterEach(function () {
        socketsStub.reset();
    });
    after(function () {
        socketsStub.restore();
        instance.cleanup();
        clock.restore();
    });

    it("fires the file:reload event to the browser", function () {

        // Emit the event as it comes from the file-watcher
        instance.events.emit("file:changed", {path: "styles.css", log: true, namespace: "core"});

        clock.tick();

        var eventName = socketsStub.getCall(0).args[0];
        var args      = socketsStub.getCall(0).args[1];

        assert.equal(eventName, "file:reload");         // check correct event sent to client
        assert.equal(args.assetFileName, "styles.css"); // Check the asset name is sent
        assert.isFalse(instance.paused);
    });

    it("doesn't fire the file:reload event to the browser when paused", function () {
        instance.paused = true;

        // Emit the event as it comes from the file-watcher
        instance.events.emit("file:changed", {path: "styles.css", log: true, namespace: "core"});

        clock.tick();

        assert.isTrue(socketsStub.withArgs("file:reload").notCalled); // should not be called
        assert.isTrue(instance.paused);

        instance.paused = false;

        // Emit the event as it comes from the file-watcher
        instance.events.emit("file:changed", {path: "styles.css", log: true, namespace: "core"});

        clock.tick();

        assert.isTrue(socketsStub.withArgs("file:reload").called);
        assert.isFalse(instance.paused);
    });

    it("Sets `log: false` if `log` is undefined in event", function () {

        // Emit the event as it comes from the file-watcher
        instance.events.emit("file:changed", {path: "styles.css", namespace: "core"});

        clock.tick();

{'fraction_non_alphanumeric': 0.14573708525829485, 'fraction_numerical': 0.0020999580008399833, 'mean_word_length': 2.3007623007623006, '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': '801777', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1330, 'n_words': 345}