Uname:Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64

403WebShell
403Webshell
Server IP : 82.148.16.210  /  Your IP : 216.73.216.249
Web Server : nginx/1.29.5
System : Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /srv/projects/env4/src/dev/frontend3/node_modules/table/node_modules/deadlink/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /srv/projects/env4/src/dev/frontend3/node_modules/table/node_modules/deadlink/tests/deadlink.js
'use strict';

var chai = require('chai'),
    expect = chai.expect,
    chaiAsPromised = require('chai-as-promised'),
    nock = require('nock'),
    Sinon = require('sinon'),
    requireNew = require('require-new');

chai.use(chaiAsPromised);

describe('deadlink', function () {
    var Deadlink,
        deadlink,
        sinon;
    beforeEach(function () {
        Deadlink = requireNew('../src/deadlink.js');
        deadlink = Deadlink();
        sinon = Sinon.sandbox.create();
    });
    afterEach(function () {
        sinon.restore();
    });
    describe('.resolveURL()', function () {
        it('Memoizes Deadlink.resolveURL() function', function () {
            var spy = sinon.spy(Deadlink, 'resolveURL');
            nock('http://gajus.com').get('/').reply(200, 'OK', {'content-type': 'text/html'});
            deadlink.resolveURL('http://gajus.com/');
            deadlink.resolveURL('http://gajus.com/');
            deadlink.resolveURL('http://gajus.com/');
            expect(spy.callCount).to.equal(1);
        });
    });
    describe('.resolveFragmentIdentifierDocument()', function () {
        it('promise is resolved with a Deadlink.fragmentIdentifierDocumentResolution', function () {
            return deadlink.resolveFragmentIdentifierDocument('foo', '<div id="foo"></div>')
                .then(function (FragmentIdentifierDocumentResolution) {
                    expect(FragmentIdentifierDocumentResolution).to.instanceof(Deadlink.FragmentIdentifierDocumentResolution);
                });
        });
        it('multiple queries against the same document are cached', function () {
            var spy = sinon.spy(Deadlink, 'getDocumentIDs');
            deadlink.resolveFragmentIdentifierDocument('foo', '<div id="foo"></div>');
            deadlink.resolveFragmentIdentifierDocument('bar', '<div id="foo"></div>');
            deadlink.resolveFragmentIdentifierDocument('baz', '<div id="foo"></div>');
            expect(spy.callCount).to.equal(1);
        });
        describe('Deadlink.FragmentIdentifierDocumentResolution', function () {
            describe('successful resolution of the fragment identifier', function () {
                it('has fragmentIdentifier', function () {
                    return deadlink.resolveFragmentIdentifierDocument('foo', '<div id="foo"></div>')
                        .then(function (FragmentIdentifierDocumentResolution) {
                            expect(FragmentIdentifierDocumentResolution).to.deep.equal({fragmentIdentifier: 'foo'});
                        });
                });
            });
            describe('unsuccessful resolution of the fragment identifier', function () {
                it('has fragmentIdentifier and error', function () {
                    return deadlink.resolveFragmentIdentifierDocument('foo', '<div></div>')
                        .then(function (FragmentIdentifierDocumentResolution) {
                            expect(FragmentIdentifierDocumentResolution).to.deep.equal({fragmentIdentifier: 'foo', error: 'Fragment identifier not found in the document.'});
                        });
                });
            });
        });
    });

    describe('.resolveFragmentIdentifierURL()', function () {
        it('throws an error if URL does not have a fragment identifier', function () {
            var promise = deadlink.resolveFragmentIdentifierURL('http://gajus.com');
            return expect(promise).rejectedWith(Error, 'URL does not have a fragment identifier.');
        });
        it('uses deadlink.resolveURL() to resolve URL', function () {
            var spy = sinon.spy(deadlink, 'resolveURL');
            nock('http://gajus.com').get('/').reply(200, '<div id="foo"></div>', {'content-type': 'text/html'});
            deadlink.resolveFragmentIdentifierURL('http://gajus.com/#foo');
            expect(spy.calledWith('http://gajus.com/#foo')).to.equal(true);
        });
        it('uses deadlink.resolveFragmentIdentifierDocument() to look up the fragment', function () {
            var spy = sinon.spy(deadlink, 'resolveURL');
            nock('http://gajus.com').get('/').reply(200, '<div id="foo"></div>', {'content-type': 'text/html'});
            deadlink.resolveFragmentIdentifierURL('http://gajus.com/#foo');
            expect(spy.calledWith('http://gajus.com/#foo')).to.equal(true);
        });
        describe('successful resolution', function () {
            var promise;
            beforeEach(function () {
                nock('http://gajus.com').get('/').reply(200, '<div id="foo"></div>', {'content-type': 'text/html'});
                promise = deadlink.resolveFragmentIdentifierURL('http://gajus.com/#foo');
            });
            it('is resolved with Deadlink.FragmentIdentifierURLResolution', function () {
                return promise
                    .then(function (Resolution) {
                        expect(Resolution).to.instanceof(Deadlink.FragmentIdentifierURLResolution);
                    });
            });
            describe('Deadlink.FragmentIdentifierURLResolution', function () {
                it('has fragmentIdentifier and url', function () {
                    return promise
                        .then(function (Resolution) {
                            expect(Resolution).to.deep.equal({fragmentIdentifier: 'foo', url: 'http://gajus.com/#foo'});
                        });
                });
            });
        });
        describe('unsuccessful resolution', function () {
            describe('when resource is not loaded', function () {
                var promise;
                beforeEach(function () {
                    nock('http://gajus.com').get('/').reply(404);
                    promise = deadlink.resolveFragmentIdentifierURL('http://gajus.com/#foo');
                });
                it('is resolved with Deadlink.FragmentIdentifierURLResolution', function () {
                    return promise
                        .then(function (Resolution) {
                            expect(Resolution).to.instanceof(Deadlink.FragmentIdentifierURLResolution);
                        });
                });
                describe('Deadlink.FragmentIdentifierURLResolution', function () {
                    it('has error', function () {
                        return promise
                            .then(function (Resolution) {
                                expect(Resolution.error).to.instanceof(Deadlink.URLResolution);
                            });
                    });
                });
            });
            describe('when fragment is not found', function () {
                var promise;
                beforeEach(function () {
                    nock('http://gajus.com').get('/').reply(200, 'OK', {'content-type': 'text/html'});
                    promise = deadlink.resolveFragmentIdentifierURL('http://gajus.com/#foo');
                });
                it('is resolved with Deadlink.FragmentIdentifierURLResolution', function () {
                    return promise
                        .then(function (Resolution) {
                            expect(Resolution).to.instanceof(Deadlink.FragmentIdentifierURLResolution);
                        });
                });
                describe('Deadlink.FragmentIdentifierURLResolution', function () {
                    it('has error', function () {
                        return promise
                            .then(function (Resolution) {
                                expect(Resolution.error).to.instanceof(Deadlink.FragmentIdentifierDocumentResolution);
                            });
                    });
                });
            });
        });
    });
});

describe('Deadlink', function () {
    var Deadlink;
    beforeEach(function () {
        Deadlink = requireNew('../src/deadlink.js');
    });
    describe('.resolveURL()', function () {
        describe('when http:// URL', function () {
            it('promise is resolved with a Deadlink.URLResolution', function () {
                nock('http://gajus.com').get('/').reply(200, 'OK', {'content-type': 'text/html'});
                return Deadlink
                    .resolveURL('http://gajus.com')
                    .then(function (URLResolution) {
                        expect(URLResolution).to.instanceof(Deadlink.URLResolution);
                    });
            });
        });
        describe('when https:// URL', function () {
            it('promise is resolved with a Deadlink.URLResolution', function () {
                nock('https://gajus.com').get('/').reply(200, 'OK', {'content-type': 'text/html'});
                return Deadlink
                    .resolveURL('https://gajus.com')
                    .then(function (URLResolution) {
                        expect(URLResolution).to.instanceof(Deadlink.URLResolution);
                    });
            });
        });
        describe('Deadlink.URLResolution', function () {
            describe('resolution of HTML resource', function () {
                var promise;
                beforeEach(function () {
                    nock('http://gajus.com').get('/').reply(200, 'OK', {'content-type': 'text/html'});
                    promise = Deadlink
                        .resolveURL('http://gajus.com/');
                });
                it('has URL and response body', function () {
                    return promise.then(function (URLResolution) {
                        expect(URLResolution).to.deep.equal({url: 'http://gajus.com/', contentType: 'text/html', body: 'OK'});
                    });
                });
            });
            describe('resolution of resource other than HTML', function () {
                var promise;
                beforeEach(function () {
                    nock('http://gajus.com').get('/').reply(200, 'OK', {'content-type': 'application/json'});
                    promise = Deadlink
                        .resolveURL('http://gajus.com/');
                });
                it('has URL and content type', function () {
                    return promise.then(function (URLResolution) {
                        expect(URLResolution).to.deep.equal({url: 'http://gajus.com/', contentType: 'application/json'});
                    });
                });
            });
            describe('resolution of status code >=400', function () {
                var promise;
                beforeEach(function () {
                    nock('http://gajus.com').get('/').reply(404, 'OK', {'content-type': 'text/html'});
                    promise = Deadlink
                        .resolveURL('http://gajus.com/');
                });
                it('has URL, error and status code', function () {
                    return promise.then(function (URLResolution) {
                        expect(URLResolution).to.deep.equal({url: 'http://gajus.com/', error: 'Resource not resolvable.', statusCode: 404});
                    });
                });
            });
            describe('resolution of HTML resource larger than 5MB', function () {
                var promise;
                beforeEach(function () {
                    nock('http://gajus.com').get('/').reply(200, Array(5 * 1000 * 1000 + 100).join('X'), {'content-type': 'text/html'});
                    promise = Deadlink
                        .resolveURL('http://gajus.com/');
                });
                it('is rejected', function () {
                    return expect(promise).rejectedWith(Error, 'Resource is larger than 1MB.');
                });
            });
        });
    });
    describe('.getDocumentIDs()', function () {
        it('returns IDs from the document', function () {
            return Deadlink.getDocumentIDs('<div id="foo"></div><div id="bar"></div><div id="baz"></div>')
                .then(function (ids) {
                    expect(ids).to.deep.equal(['foo', 'bar', 'baz']);
                });
        });
    });
});

Youez - 2016 - github.com/yon3zu
LinuXploit