all files / montage-testing/ run.js

36.73% Statements 18/49
45.45% Branches 10/22
33.33% Functions 5/15
36.73% Lines 18/49
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97                                                                                                                                                             
//
//
//
 
global.createJavaScriptContext = function createJavaScriptContext() {
    var iframe = document.createElement("iframe"),
        context = {};
 
    iframe.style.display = "none";
    document.body.appendChild(iframe);
    ["Object", "String", "Number", "RegExp", "Array", "Boolean"]
    .forEach(function (key) {
        context[key] = iframe.contentWindow[key];
    });
    context.document = iframe.contentDocument;
    iframe.parentNode.removeChild(iframe);
 
    return context;
}
 
global.waitsThen = function waitsThen(promise, resolved) {
    waitsFor(function () {
        return promise.isResolved();
    }, "promise", 500);
    runs(function () {
        resolved(promise.valueOf());
    })
}
 
global.expectationToDispatch = function expectationToDispatch(object, expectation, handleEvent) {
 
    var handler = {
        handleEvent: handleEvent? handleEvent : function (event) {}
    };
 
    if (typeof expectation === "string") {
        // expect event name
        spyOn(handler, "handleEvent").andCallThrough();
        object.addEventListener(expectation, handler, false);
    }
 
    return function (negate) {
        if (negate) {
            expect(handler.handleEvent).not.toHaveBeenCalled();
        } else {
            expect(handler.handleEvent).toHaveBeenCalled();
        }
    }
}
 
global.addMontageMetadataToProto = function (objectName, moduleId, proto) {
    Object.defineProperty(proto, "_montage_metadata", { value: { moduleId: moduleId, objectName: objectName, isInstance: false }, enumerable: false});
};
 
 
global.expectConsoleCallsFrom = function expectConsoleCallsFrom(procedure, global, logLevel) {
    logLevel = logLevel ? logLevel : "log";
    var old = global.console[logLevel];
    var spy = jasmine.createSpy(logLevel + "-spy");
 
    global.console[logLevel] = spy;
    procedure();
    global.console[logLevel] = old;
 
    return expect(spy);
};
 
exports.run = function run (suiteRequire, modules) {
 
    // Filter node:false
    modules = modules.filter(function (module) {
        if (typeof module === "object") {
            Iif (module.node === false && typeof process !== "undefined") {
                return false;
            } else Iif (module.browser === false && typeof window !== "undefined") {
                return false;
            }
        }
        return true;
    }).map(function (module) {
        if (typeof module === "object") {
            return module.name;
        } else {
            return module;
        }
    });
 
    return Promise.all(modules.map(suiteRequire.deepLoad)).then(function () {
        modules.forEach(suiteRequire);
    }).then(function() {
        Eif (global.__karma__) {
            global.__karma__.start();
        } else {
            jasmine.getEnv().execute();    
        }
    });
}