<commit_before>'use strict';

require('should');
var daemon = require('daemon');
var optionsParser = require('../lib/options_parser');
var daemonize = require('../lib/daemonize');
var sinon = require('sinon');
var fs = require('fs');

describe('daemonize', function () {
    beforeEach(function () {
        sinon.stub(daemon, 'daemon');
        daemon.daemon.returns({pid: 1000});
        sinon.stub(fs, 'writeFileSync');
        sinon.stub(fs, 'openSync');
    });

    afterEach(function () {
        daemon.daemon.restore();
        fs.writeFileSync.restore();
        fs.openSync.restore();
    });

    describe('should daemon', function () {
        it('current script', function () {
            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[0].should.match('script');
        });

        it('with hostname', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-h', '127.0.0.1']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.containDeep(['-h', '127.0.0.1']);
        });

        it('with port', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-p', '80']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.containDeep(['-p', 80]);
        });

        it('with lines number', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-n', '1']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.containDeep(['-n', 1]);
        });

        it('with lines stored in browser', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-l', '1']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.containDeep(['-l', 1]);
        });

        it('with theme', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-t', 'dark']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.containDeep(['-t', 'dark']);
        });

        it('with authorization', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-U', 'user', '-P', '<PASSWORD>w0rd']);

            daemonize('script', optionsParser, {doAuthorization: true});

            daemon.daemon.lastCall.args[1].should.containDeep(['-U', 'user', '-P', 'passw0rd']);
        });

        it('without authorization if option doAuthorization not passed', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-U', 'user', '-P', 'passw0rd']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.not.containDeep(['-U', 'user', '-P', 'passw0rd']);
        });

        it('with secure connection', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-k', 'key.file', '-c', 'cert.file']);

            daemonize('script', optionsParser, {doSecure: true});

            daemon.daemon.lastCall.args[1].should.containDeep(['-k', 'key.file', '-c', 'cert.file']);
        });

        it('without secure connection if option doSecure not passed', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-k', 'key.file', '-c', 'cert.file']);

            daemonize('script', optionsParser, {doSecure: true});

            daemon.daemon.lastCall.args[1].should.containDeep(['-k', 'key.file', '-c', 'cert.file']);
        });

        it('with hide-topbar option', function () {
            optionsParser.parse(['node', '/path/to/frontail', '--ui-hide-topbar']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.containDeep(['--ui-hide-topbar']);
        });<commit_msg>[#41] Add a test to verify the issue<commit_after>'use strict';

require('should');
var daemon = require('daemon');
var optionsParser = require('../lib/options_parser');
var daemonize = require('../lib/daemonize');
var sinon = require('sinon');
var fs = require('fs');

describe('daemonize', function () {
    beforeEach(function () {
        sinon.stub(daemon, 'daemon');
        daemon.daemon.returns({pid: 1000});
        sinon.stub(fs, 'writeFileSync');
        sinon.stub(fs, 'openSync');
    });

    afterEach(function () {
        daemon.daemon.restore();
        fs.writeFileSync.restore();
        fs.openSync.restore();
    });

    describe('should daemon', function () {
        it('current script', function () {
            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[0].should.match('script');
        });

        it('with hostname', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-h', '127.0.0.1']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.containDeep(['-h', '127.0.0.1']);
        });

        it('with port', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-p', '80']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.containDeep(['-p', 80]);
        });

        it('with lines number', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-n', '1']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.containDeep(['-n', 1]);
        });

        it('with lines stored in browser', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-l', '1']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.containDeep(['-l', 1]);
        });

        it('with theme', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-t', 'dark']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.containDeep(['-t', 'dark']);
        });

        it('with authorization', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-U', 'user', '-P', '<PASSWORD>w<PASSWORD>']);

            daemonize('script', optionsParser, {doAuthorization: true});

            daemon.daemon.lastCall.args[1].should.containDeep(['-U', 'user', '-P', 'passw0rd']);
        });

        it('without authorization if option doAuthorization not passed', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-U', 'user', '-P', 'passw0rd']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.not.containDeep(['-U', 'user', '-P', 'passw0rd']);
        });

        it('with secure connection', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-k', 'key.file', '-c', 'cert.file']);

            daemonize('script', optionsParser, {doSecure: true});

            daemon.daemon.lastCall.args[1].should.containDeep(['-k', 'key.file', '-c', 'cert.file']);
        });

        it('with ssh configuration', function () {
            optionsParser.parse(['node', '/path/to/frontail', '--remote-host', 'remoteHost', '--remote-user', 'remoteUser', '--remote-port', '23']);

            var sshOptions = {
                remoteHost: 'remoteHost',
                remoteUser: 'remoteUser',
                remotePort: '23'
            };

            daemonize('script', optionsParser, {sshOptions: sshOptions});

            daemon.daemon.lastCall.args[1].should.containDeep(['--remote-host', 'remoteHost', '--remote-user', 'remoteUser', '--remote-port', '23']);
        });

        it('without secure connection if option doSecure not passed', function () {
            optionsParser.parse(['node', '/path/to/frontail', '-k', 'key.file', '-c', 'cert.file']);

            daemonize('script', optionsParser, {doSecure: true});

            daemon.daemon.lastCall.args[1].should.containDeep(['-k', 'key.file', '-c', 'cert.file']);
        });

        it('with hide-topbar option', function () {
            optionsParser.parse(['node', '/path/to/frontail', '--ui-hide-topbar']);

            daemonize('script', optionsParser);

            daemon.daemon.lastCall.args[1].should.containDeep(['--ui-hide-topbar']);
        });
{'fraction_non_alphanumeric': 0.20324809114046782, 'fraction_numerical': 0.010422979032844504, 'mean_word_length': 2.524989320803076, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '5171344', 'n_tokens_mistral': 2539, 'n_tokens_neox': 2434, 'n_words': 415}