Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

after 3 with 4, I have a client side function, and all it does it stops processing #3059

Closed
4 tasks done
p3x-robot opened this issue Oct 6, 2017 · 1 comment
Closed
4 tasks done

Comments

@p3x-robot
Copy link

Prerequisites

  • Checked that your issue isn't already filed by cross referencing issues with the common mistake label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
    node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend avoiding the use of globally installed Mocha.

Description

Steps to Reproduce

I found the file that stops, do you have an idea why it stops the processing?
Although, I am using Chrome instead of PhatomJs, but it is an older functions, so it works with very old functions as well, so it is so weird.

(function(window, document, navigator) {
    'use strict';
    if (window.corifeusCssFiles === undefined && window.corifeusScriptFiles === undefined) {
        window.corifeusCssFiles = [];
        window.corifeusScriptFiles = [];
    }
    window.corifeus = {
        booted: false,
        core: {
            http: {
                counter: 0
            }
        }
    }
    window.corifeusPreloader = {
        wait: navigator.userAgent === 'corifeus-server-renderer',
        status: {
            corifeus: window.corifeus
        }
    }

    'GENERATED-HEAD';

    if (!document.getElementById) {
        document.getElementById = function() {};
    }

    var cssFiles = window.corifeusCssFiles;
    var scriptFiles = window.corifeusScriptFiles;
    var files = cssFiles.concat(scriptFiles);
    var progress = {};
    var responseText = {};
    var started = new Date().getTime();

    function formatBytes(bytes,decimals) {
        if(bytes == 0) return '0 Byte';
        var k = 1000; // or 1024 for binary
        var dm = decimals + 1 || 3;
        var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
        var i = Math.floor(Math.log(bytes) / Math.log(k));
        return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
    }
    var formatTime = function(time) {
        var seconds = Math.floor(time / 1000);
        var minutes = Math.floor(seconds / 60);
        var hours = Math.floor(minutes / 60);
        var days = Math.floor(hours / 24);

        hours = hours - (days * 24);
        minutes = minutes - (days * 24 * 60) - (hours * 60);
        seconds = seconds - (days * 24 * 60 * 60) - (hours * 60 * 60) - (minutes * 60);
        if (days < 10) days = '0' + days;
        if (hours < 10) hours = '0' + hours;
        if (minutes < 10) minutes = '0' + minutes;
        if (seconds < 10) seconds = '0' + seconds;

        var template = '';
        if (days != '00') {
            template += days + ':';
        }
        if (hours != '00' || days != '00') {
            template += hours + ':';
        }
        template += minutes + ':';
        template += seconds

        return template;
    }
    function loadFile(url) {
        var xhr = new XMLHttpRequest();
        xhr.open("GET", url, true);
        xhr.onreadystatechange = function() {
            if (this.readyState == this.DONE) {
                responseText[url] = xhr.responseText;
                fire(true, this.responseText);
            }
        };
        xhr.onprogress = function(event) {
            progress[url] = event;
            fire();
        }
        xhr.send();
    }
    function iterate(cb) {
        for(var index = 0; index < files.length; index++) {
            var file = files[index];
            cb(file);
        }
    }
    function includesCss(file) {
        for(var index = 0; index < cssFiles.length; index++) {
            var cssFile = cssFiles[index];
            if (cssFile === file) {
                return true;
            }
        }
        return false;
    }
    var total = 0;
    var loaded = 0;
    var counter = 0;
    var totalDone = false;
    var frame = 33;
    var computable = true;
    var overlayPercent = function(percent) {
        document.getElementById('cory-loader-progress-overlay').style.height = Math.round(percent) + '%';
        document.getElementById('cory-loader-progress-overlay').style.width = '100%';
    }

    var loop = (function() {
        if (totalDone) {
            return;
        }
        if (document.getElementById('cory-loader-progress-bottom')) {
            var percentRaw = (loaded / total);
            var percent = (percentRaw * 100).toFixed(2);
            var totalMB = formatBytes(total, 1);
            var loadedMB = formatBytes(loaded, 1);
            if (isNaN(percent)) {
                percent = 0.5;
            }
            var current = new Date().getTime() - started;
            var maxTime = current / percent * 100;
            var left = maxTime - current;

            overlayPercent(percent);
            var top = document.getElementById('cory-loader-progress-top');
            var bottom = document.getElementById('cory-loader-progress-bottom');

            if (computable) {
                top.innerHTML = formatTime(left);
                bottom.innerHTML  = percent + '%' + '<div class="cory-loader-progress-info">' + loadedMB + ' / ' + totalMB + '</br>' + formatTime(current) + ' / ' + formatTime(maxTime) + '</div>';
            } else {
                top.innerHTML = '<div class="cory-loader-progress-info">gzip</div>';
                bottom.innerHTML = formatTime(current) + '</br></br>' + loadedMB;
            }
        }
        setTimeout(loop, frame);
    });
    loop();

    function fire(isDone) {
        total = 0;
        loaded = 0;
        iterate(function(file) {
            if (progress[file] !== undefined) {
                if (progress[file].lengthComputable === false) {
                    computable = false;
                    total += progress[file].loaded;
                } else {
                    total += progress[file].total;
                }
                loaded += progress[file].loaded;
            }
        })

        totalDone = isDone === true && ++counter == files.length;

    }
    var final = function() {
//        document.getElementById('cory-loader-progress-top').innerHTML = '<div></div>';
//        document.getElementById('cory-loader-progress-bottom').innerHTML = '<span class="cory-loader-progress-start">START</span>';
        overlayPercent(100);
        setTimeout(function() {
            iterate(function(file) {
                var body = document.querySelector('body');
                var head = document.querySelector('head');
                // it is important so that the css is in the head
                if (includesCss(file)) {
                    /*
                    var style = document.createElement('style');
                    style.type = 'text/css';
                    style.innerHTML = responseText[file];
                     head.appendChild(style)
                    */
                    var link = document.createElement('link');
                    link.rel = 'stylesheet';
                    link.href = file;
                    link.type = 'text/css';
                    head.appendChild(link);
                } else {
                    var script = document.createElement("script");
                    script.type = 'text/javascript';
                    script.defer = true;
                    script.src = file;
                    /*
                    script.innerHTML= responseText[file];
                    */
                    body.appendChild(script);
                }
            })
            var booted = function() {
                if (window.corifeus.booted === true) {
                    var removeMe = document.getElementById('cory-loader');
                    if (removeMe !== null) {
                        removeMe.parentNode.removeChild(removeMe);
                    }
                }
                else {
                    setTimeout(booted, 100);
                }

            }
            booted();
        }, frame)
    }

    iterate(function(file) {
        loadFile(file, fire)
    })

    var waitForDone = function() {
        if (totalDone && !window.corifeusPreloader.wait) {
            final();
            return;
        }
        window.corifeusPreloader.status.corifeus = window.corifeus;
        setTimeout(waitForDone, frame);
    }
    waitForDone();
})(typeof(window) === 'undefined' ? this : window, typeof(document) === 'undefined' ? {} : document, typeof(navigator) === 'undefined' ? { userAgent : 'corifeus-server-renderer'} : navigator);

Expected behavior: [What you expect to happen]

Continue to process with mocha (with v4 or above)

Actual behavior: [What actually happens]

Stops processing.

Reproduces how often: [What percentage of the time does it reproduce?]

Versions

Pure Js, no transpiler, although
4.0.1

Additional Information

image

Although, there are other files, but I choose js only.

@boneskull
Copy link
Member

I'm going to guess you didn't actually do step one in the template, but that's ok.

duplicate of #3044 and all over the changelog...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants