• passes: 7
  • failures: 6
  • duration: 20.30s
  • LoadJS tests

    • JavaScript file loading tests

      • should call success callback on valid path1170ms ‣

        loadjs(['assets/file1.js'], {
          success: function() {
            assert.equal(pathsLoaded['file1.js'], true);
            done();
          }
        });
      • should call error callback on invalid path1076ms ‣

        loadjs(['assets/file-doesntexist.js'], {
          success: function() {
            throw "Executed success callback";
          },
          error: function(pathsNotFound) {
            assert.equal(pathsNotFound.length, 1);
            assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js');
            done();
          }
        });
      • should call before callback before embedding into document658ms ‣

        var scriptTags = [];
        loadjs(['assets/file1.js', 'assets/file2.js'], {
          before: function(path, el) {
            scriptTags.push({
              path: path,
              el: el
            });
            // add cross origin script for file2
            if (path === 'assets/file2.js') {
              el.crossOrigin = 'anonymous';
            }
          },
          success: function() {
            assert.equal(scriptTags[0].path, 'assets/file1.js');
            assert.equal(scriptTags[1].path, 'assets/file2.js');
            assert.equal(scriptTags[0].el.crossOrigin, undefined);
            assert.equal(scriptTags[1].el.crossOrigin, 'anonymous');
            done();
          }
        });
      • should bypass insertion if before returns `false`1ms ‣

        loadjs(['assets/file1.js'], {
          before: function(path, el) {
            // append to body (instead of head)
            document.body.appendChild(el);
            // return `false` to bypass default DOM insertion
            return false;
          },
          success: function() {
            assert.equal(pathsLoaded['file1.js'], true);
            
            // verify that file was added to body
            var els = document.body.querySelectorAll('script'),
                el;
            for (var i=0; i < els.length; i++) {
              el = els[i];
              if (el.src.indexOf('assets/file1.js') !== -1) done();
            }
          }
        });
      • should call success callback on two valid paths750ms ‣

        loadjs(['assets/file1.js', 'assets/file2.js'], {
          success: function() {
            assert.equal(pathsLoaded['file1.js'], true);
            assert.equal(pathsLoaded['file2.js'], true);
            done();
          }
        });
      • should call error callback on one invalid path907ms ‣

        loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], {
          success: function() {
            throw "Executed success callback";
          },
          error: function(pathsNotFound) {
            assert.equal(pathsLoaded['file1.js'], true);
            assert.equal(pathsNotFound.length, 1);
            assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js');
            done();
          }
        });
      • should support async false ‣

        Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
        this.timeout(5000);
        var numCompleted = 0,
            numTests = 20,
            paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js'];
        // run tests sequentially
        var testFn = function(paths) {
          // add cache busters
          var pathsUncached = paths.slice(0);
          pathsUncached[0] += '?_=' + Math.random();
          pathsUncached[1] += '?_=' + Math.random();
          loadjs(pathsUncached, {
            success: function() {
              var f1 = paths[0].replace('assets/', '');
              var f2 = paths[1].replace('assets/', '');
              // check load order
              assert.isTrue(pathsLoaded[f1]);
              assert.isFalse(pathsLoaded[f2]);
              // increment tests
              numCompleted += 1;
              if (numCompleted === numTests) {
                // exit
                done();
              } else {
                // reset register
                pathsLoaded = {};
                // run test again
                paths.reverse();
                testFn(paths);
              }
            },
            async: false
          });
        };
        // run tests
        testFn(paths);
      • should support multiple tries1743ms ‣

        loadjs('assets/file-numretries.js', {
          error: function() {
            // check number of scripts in document
            var selector = 'script[src="assets/file-numretries.js"]',
                scripts = document.querySelectorAll(selector);
            if (scripts.length === 2) done();
          },
          numRetries: 1
        });
      • it should report ad blocked scripts as missing

    • CSS file loading tests

      • should load one file ‣

        Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
        loadjs(['assets/file1.css'], {
          success: function() {
            assert.equal(testEl.offsetWidth, 100);
            done();
          }
        });
      • should load multiple files ‣

        Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
        loadjs(['assets/file1.css', 'assets/file2.css'], {
          success: function() {
            assert.equal(testEl.offsetWidth, 200);
            done();
          }
        });
      • should call error callback on one invalid path ‣

        Error: Uncaught AssertionError: expected 0 to equal 100 (https://haiphams4.glinkdeployments.com/crm2020-elastic/node_modules/loadjs/test/vendor/chai-4.1.2.js:239)
        loadjs(['assets/file1.css', 'assets/file-doesntexist.css'], {
          success: function() {
            throw new Error('Executed success callback');
          },
          error: function(pathsNotFound) {
            assert.equal(testEl.offsetWidth, 100);
            assert.equal(pathsNotFound.length, 1);
            assert.equal(pathsNotFound[0], 'assets/file-doesntexist.css');
            done();
          }
        });
      • should support mix of css and js ‣

        Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
        loadjs(['assets/file1.css', 'assets/file1.js'], {
          success: function() {
            assert.equal(pathsLoaded['file1.js'], true);
            assert.equal(testEl.offsetWidth, 100);
            done();
          }
        });
      • should support forced "css!" files ‣

        Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
        loadjs(['css!assets/file1.css'], {
          success: function() {
            // loop through files
            var els = document.getElementsByTagName('link'),
                i = els.length,
                el;
            while (i--) {
              if (els[i].href.indexOf('file1.css') !== -1) done();
            }
          }
        });