<commit_before>var chai = require('chai');
var gulp = require('gulp-help')(require('gulp'));
var proxyquire = require('proxyquire');

chai.should();

describe('gulp serve', function() {
    describe('serve:browsersync', function() {
        it('should start BrowserSync with the correct options', function(done) {
            proxyquire('../gulp/serve', {'browser-sync': {
                init: function(opts) {
                    (typeof opts.port).should.not.equal('undefined');
                    opts.files.should.be.false;
                    opts.proxy.match('http://localhost:').should.be.ok;
                    opts.tunnel.should.be.true;
                    opts.open.should.be.false;
                    done();
                }
            }})(gulp);

            gulp.start(['serve:browsersync']);
        });
    });

    describe('serve', function() {
        it('should start BrowserSync and then create an ecstatic server', function(done) {
            proxyquire('../gulp/serve', {
                'browser-sync': {
                    init: function(opts, next) {
                        next();
                    }
                },
                'http': {
                    createServer: function() {
                        arguments[0].name.should.equal('middleware');
                        done();

                        return {
                            listen: function() {}
                        };
                    }
                }
            })(gulp);

            gulp.tasks.serve.dep.length.should.equal(1);
            gulp.tasks.serve.dep[0].should.equal('serve:browsersync');<commit_msg>Add test for localtunnel crash handler<commit_after>var chai = require('chai');
var gulp = require('gulp-help')(require('gulp'));
var proxyquire = require('proxyquire');

chai.should();

describe('gulp serve', function() {
    describe('serve:browsersync', function() {
        it('should start BrowserSync with the correct options', function(done) {
            proxyquire('../gulp/serve', {'browser-sync': {
                init: function(opts) {
                    (typeof opts.port).should.not.equal('undefined');
                    opts.files.should.be.false;
                    opts.proxy.match('http://localhost:').should.be.ok;
                    opts.tunnel.should.be.true;
                    opts.open.should.be.false;
                    done();

                    return {
                        emitter: {
                            on: function() {}
                        }
                    };
                }
            }})(gulp);

            gulp.start(['serve:browsersync']);
        });

        it('should define a handler for an error emitted from BrowserSync\'s localtunnel instance',
            function(done) {
                proxyquire('../gulp/serve', {
                    'browser-sync': {
                        init: function() {
                            return {
                                emitter: {
                                    on: function(event, fn) {
                                        event.should.equal('service:running');
                                        fn.should.be.ok;
                                        fn();
                                    }
                                },

                                instance: {
                                    tunnel: {
                                        tunnel_cluster: { //eslint-disable-line
                                            on: function(event, fn) {
                                                event.should.equal('error');
                                                fn.should.be.ok;

                                                try {
                                                    fn('test');
                                                    chai.assert.fail();
                                                } catch(err) {
                                                    err.should.equal('test');
                                                }

                                                fn('check firewall');

                                                done();
                                            }
                                        }
                                    }
                                }
                            };
                        }
                    }
                })(gulp);

                gulp.start(['serve:browsersync']);
            }
        );
    });

    describe('serve', function() {
        it('should start BrowserSync and then create an ecstatic server', function(done) {
            proxyquire('../gulp/serve', {
                'browser-sync': {
                    init: function(opts, next) {
                        next();

                        return {
                            emitter: {
                                on: function() {}
                            }
                        };
                    }
                },
                'http': {
                    createServer: function() {
                        arguments[0].name.should.equal('middleware');
                        done();

                        return {
                            listen: function() {}
                        };
                    }
                }
            })(gulp);

            gulp.tasks.serve.dep.length.should.equal(1);
            gulp.tasks.serve.dep[0].should.equal('serve:browsersync');
{'fraction_non_alphanumeric': 0.11265320836337418, 'fraction_numerical': 0.0010814708002883922, 'mean_word_length': 0.8010386238234339, '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': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1311920', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1112, 'n_words': 186}