Ejemplo n.º 1
0
    function init() {
        selectedSuites = (params.get("suite") || localStorage.getItem("SpecRunner.suite") || "unit").split(",");
        
        // Create a top-level filter to show/hide performance and extensions tests
        var runAll = (selectedSuites.indexOf("all") >= 0);
        
        var topLevelFilter = function (spec) {
            // special case "all" suite to run unit, perf, extension, and integration tests
            if (runAll) {
                return true;
            }

            var currentSuite = spec.suite,
                category = spec.category;

            if (!category) {
                // find the category from the closest suite
                while (currentSuite) {
                    if (currentSuite.category) {
                        category = currentSuite.category;
                        break;
                    }

                    currentSuite = currentSuite.parentSuite;
                }
            }
            
            // if unit tests are selected, make sure there is no category in the heirarchy
            // if not a unit test, make sure the category is selected
            return (selectedSuites.indexOf("unit") >= 0 && category === undefined) ||
                (selectedSuites.indexOf(category) >= 0);
        };
        
        /*
         * TODO (jason-sanjose): extension unit tests should only load the
         * extension and the extensions dependencies. We should not load
         * unrelated extensions. Currently, this solution is all or nothing.
         */
        
        // configure spawned test windows to load extensions
        SpecRunnerUtils.setLoadExtensionsInTestWindow(selectedSuites.indexOf("extension") >= 0);
        
        _loadExtensionTests(selectedSuites).always(function () {
            var jasmineEnv = jasmine.getEnv();
            jasmineEnv.updateInterval = 1000;
            
            _registerBeforeAfterHandlers();
            
            // Create the reporter, which is really a model class that just gathers
            // spec and performance data.
            reporter = new UnitTestReporter(jasmineEnv, topLevelFilter, params.get("spec"));
            SpecRunnerUtils.setUnitTestReporter(reporter);
            
            // Optionally emit JUnit XML file for automated runs
            if (resultsPath) {
                if (resultsPath.substr(-4) === ".xml") {
                    _patchJUnitReporter();
                    jasmineEnv.addReporter(new jasmine.JUnitXmlReporter(null, true, false));
                }

                // Close the window
                $(reporter).on("runnerEnd", _runnerEndHandler);
            } else {
                _writeResults.resolve();
            }
            
            jasmineEnv.addReporter(reporter);
            
            // Create the view that displays the data from the reporter. (Usually in
            // Jasmine this is part of the reporter, but we separate them out so that
            // we can more easily grab just the model data for output during automatic
            // testing.)
            reporterView = new BootstrapReporterView(document, reporter);
            
            // remember the suite for the next unit test window launch
            localStorage.setItem("SpecRunner.suite", selectedSuites);
            
            $(window.document).ready(_documentReadyHandler);
        });
        
        
        // Prevent clicks on any link from navigating to a different page (which could lose unsaved
        // changes). We can't use a simple .on("click", "a") because of http://bugs.jquery.com/ticket/3861:
        // jQuery hides non-left clicks from such event handlers, yet middle-clicks still cause CEF to
        // navigate. Also, a capture handler is more reliable than bubble.
        window.document.body.addEventListener("click", function (e) {
            // Check parents too, in case link has inline formatting tags
            var node = e.target, url;
            
            while (node) {
                if (node.tagName === "A") {
                    url = node.getAttribute("href");
                    if (url && url.match(/^http/)) {
                        NativeApp.openURLInDefaultBrowser(url);
                        e.preventDefault();
                    }
                    break;
                }
                node = node.parentElement;
            }
        }, true);
    }
Ejemplo n.º 2
0
 function init() {
     suite = params.get("suite") || localStorage.getItem("SpecRunner.suite") || "UnitTestSuite";
     
     // Create a top-level filter to show/hide performance and extensions tests
     var isPerfSuite = (suite === "PerformanceTestSuite"),
         isExtSuite = (suite === "ExtensionTestSuite");
     
     var topLevelFilter = function (spec) {
         var suite = spec.suite;
         
         // unit test suites have no category
         if (!isPerfSuite && !isExtSuite) {
             if (spec.category !== undefined) {
                 // if an individualy spec has a category, filter it out
                 return false;
             }
             
             while (suite) {
                 if (suite.category !== undefined) {
                     // any suite in the hierarchy may specify a category
                     return false;
                 }
                 
                 suite = suite.parentSuite;
             }
             
             return true;
         }
         
         var category = (isPerfSuite) ? "performance" : "extension";
         
         if (spec.category === category) {
             return true;
         }
         
         while (suite) {
             if (suite.category === category) {
                 return true;
             }
             
             suite = suite.parentSuite;
         }
         
         return false;
     };
     
     /*
      * TODO (jason-sanjose): extension unit tests should only load the
      * extension and the extensions dependencies. We should not load
      * unrelated extensions. Currently, this solution is all or nothing.
      */
     
     // configure spawned test windows to load extensions
     SpecRunnerUtils.setLoadExtensionsInTestWindow(isExtSuite);
     
     _loadExtensionTests(suite).done(function () {
         var jasmineEnv = jasmine.getEnv();
         
         // Initiailize unit test preferences for each spec
         beforeEach(function () {
             // Unique key for unit testing
             localStorage.setItem("preferencesKey", SpecRunnerUtils.TEST_PREFERENCES_KEY);
         });
         
         afterEach(function () {
             // Clean up preferencesKey
             localStorage.removeItem("preferencesKey");
         });
         
         jasmineEnv.updateInterval = 1000;
         
         // Create the reporter, which is really a model class that just gathers
         // spec and performance data.
         reporter = new UnitTestReporter(jasmineEnv, topLevelFilter, params.get("spec"));
         
         // Optionally emit JSON for automated runs
         if (params.get("resultsPath")) {
             $(reporter).on("runnerEnd", _runnerEndHandler);
         }
         
         jasmineEnv.addReporter(reporter);
         
         // Create the view that displays the data from the reporter. (Usually in
         // Jasmine this is part of the reporter, but we separate them out so that
         // we can more easily grab just the model data for output during automatic
         // testing.)
         reporterView = new BootstrapReporterView(document, reporter);
         
         // remember the suite for the next unit test window launch
         localStorage.setItem("SpecRunner.suite", suite);
         
         $(window.document).ready(_documentReadyHandler);
     });
 }
Ejemplo n.º 3
0
    function init() {
        // Start up the node connection, which is held in the
        // _nodeConnectionDeferred module variable. (Use 
        // _nodeConnectionDeferred.done() to access it.
        
        // This is in SpecRunner rather than SpecRunnerUtils because the hope
        // is to hook up jasmine-node tests in this test runner.
        
        // TODO: duplicates code from StaticServer
        // TODO: can this be done lazily?
        
        var connectionTimeout = setTimeout(function () {
            console.error("[SpecRunner] Timed out while trying to connect to node");
            _nodeConnectionDeferred.reject();
        }, NODE_CONNECTION_TIMEOUT);
        
        var _nodeConnection = new NodeConnection();
        _nodeConnection.connect(true).then(function () {
            var domainPath = FileUtils.getNativeBracketsDirectoryPath() + "/" + FileUtils.getNativeModuleDirectoryPath(module) + "/../test/node/TestingDomain";
            
            _nodeConnection.loadDomains(domainPath, true)
                .then(
                    function () {
                        clearTimeout(connectionTimeout);
                        _nodeConnectionDeferred.resolve(_nodeConnection);
                    },
                    function () { // Failed to connect
                        console.error("[SpecRunner] Failed to connect to node", arguments);
                        clearTimeout(connectionTimeout);
                        _nodeConnectionDeferred.reject();
                    }
                );
        });

        selectedSuites = (params.get("suite") || localStorage.getItem("SpecRunner.suite") || "unit").split(",");
        
        // Create a top-level filter to show/hide performance and extensions tests
        var runAll = (selectedSuites.indexOf("all") >= 0);
        
        var topLevelFilter = function (spec) {
            // special case "all" suite to run unit, perf, extension, and integration tests
            if (runAll) {
                return true;
            }

            var currentSuite = spec.suite,
                category = spec.category;

            if (!category) {
                // find the category from the closest suite
                while (currentSuite) {
                    if (currentSuite.category) {
                        category = currentSuite.category;
                        break;
                    }

                    currentSuite = currentSuite.parentSuite;
                }
            }
            
            // if unit tests are selected, make sure there is no category in the heirarchy
            // if not a unit test, make sure the category is selected
            return (selectedSuites.indexOf("unit") >= 0 && category === undefined) ||
                (selectedSuites.indexOf(category) >= 0);
        };
        
        /*
         * TODO (jason-sanjose): extension unit tests should only load the
         * extension and the extensions dependencies. We should not load
         * unrelated extensions. Currently, this solution is all or nothing.
         */
        
        // configure spawned test windows to load extensions
        SpecRunnerUtils.setLoadExtensionsInTestWindow(selectedSuites.indexOf("extension") >= 0);
        
        _loadExtensionTests(selectedSuites).done(function () {
            var jasmineEnv = jasmine.getEnv();
            
            // Initiailize unit test preferences for each spec
            beforeEach(function () {
                // Unique key for unit testing
                localStorage.setItem("preferencesKey", SpecRunnerUtils.TEST_PREFERENCES_KEY);

                // Reset preferences from previous test runs
                localStorage.removeItem("doLoadPreferences");
                localStorage.removeItem(SpecRunnerUtils.TEST_PREFERENCES_KEY);
            });
            
            afterEach(function () {
                // Clean up preferencesKey
                localStorage.removeItem("preferencesKey");
            });
            
            jasmineEnv.updateInterval = 1000;
            
            // Create the reporter, which is really a model class that just gathers
            // spec and performance data.
            reporter = new UnitTestReporter(jasmineEnv, topLevelFilter, params.get("spec"));
            
            // Optionally emit JUnit XML file for automated runs
            if (resultsPath) {
                if (resultsPath.substr(-4) === ".xml") {
                    _patchJUnitReporter();
                    jasmineEnv.addReporter(new jasmine.JUnitXmlReporter(null, true, false));
                }

                // Close the window
                $(reporter).on("runnerEnd", _runnerEndHandler);
            } else {
                _writeResults.resolve();
            }
            
            jasmineEnv.addReporter(reporter);
            
            // Create the view that displays the data from the reporter. (Usually in
            // Jasmine this is part of the reporter, but we separate them out so that
            // we can more easily grab just the model data for output during automatic
            // testing.)
            reporterView = new BootstrapReporterView(document, reporter);
            
            // remember the suite for the next unit test window launch
            localStorage.setItem("SpecRunner.suite", selectedSuites);
            
            $(window.document).ready(_documentReadyHandler);
        });
    }
Ejemplo n.º 4
0
    function init() {
        // Start up the node connection, which is held in the
        // _nodeConnectionDeferred module variable. (Use 
        // _nodeConnectionDeferred.done() to access it.
        
        // This is in SpecRunner rather than SpecRunnerUtils because the hope
        // is to hook up jasmine-node tests in this test runner.
        
        // TODO: duplicates code from StaticServer
        // TODO: can this be done lazily?
        
        var connectionTimeout = setTimeout(function () {
            console.error("[SpecRunner] Timed out while trying to connect to node");
            _nodeConnectionDeferred.reject();
        }, NODE_CONNECTION_TIMEOUT);
        
        var _nodeConnection = new NodeConnection();
        _nodeConnection.connect(true).then(function () {
            var domainPath = FileUtils.getNativeBracketsDirectoryPath() + "/" + FileUtils.getNativeModuleDirectoryPath(module) + "/../test/node/TestingDomain";
            
            _nodeConnection.loadDomains(domainPath, true)
                .then(
                    function () {
                        clearTimeout(connectionTimeout);
                        _nodeConnectionDeferred.resolve(_nodeConnection);
                    },
                    function () { // Failed to connect
                        console.error("[SpecRunner] Failed to connect to node", arguments);
                        clearTimeout(connectionTimeout);
                        _nodeConnectionDeferred.reject();
                    }
                );
        });

        selectedSuite = params.get("suite") || localStorage.getItem("SpecRunner.suite") || "UnitTestSuite";
        
        // Create a top-level filter to show/hide performance and extensions tests
        var runAll = (selectedSuite === "all"),
            isPerfSuite = (selectedSuite === "PerformanceTestSuite"),
            isExtSuite = (selectedSuite === "ExtensionTestSuite"),
            isIntegrationSuite = (selectedSuite === "IntegrationTestSuite"),
            category;
            
        if (isPerfSuite) {
            category = "performance";
        } else if (isIntegrationSuite) {
            category = "integration";
        } else if (isExtSuite) {
            category = "extension";
        }
        
        var topLevelFilter = function (spec) {
            // special case "all" suite to run unit, perf, extension, and integration tests
            if (runAll) {
                return true;
            }

            var currentSuite = spec.suite;
            
            // unit test suites have no category
            if (!isPerfSuite && !isExtSuite && !isIntegrationSuite) {
                if (spec.category !== undefined) {
                    // if an individualy spec has a category, filter it out
                    return false;
                }
                
                while (currentSuite) {
                    if (currentSuite.category !== undefined) {
                        // any suite in the hierarchy may specify a category
                        return false;
                    }
                    
                    currentSuite = currentSuite.parentSuite;
                }
                
                return true;
            }
            
            if (spec.category === category) {
                return true;
            }
            
            while (currentSuite) {
                if (currentSuite.category === category) {
                    return true;
                }
                
                currentSuite = currentSuite.parentSuite;
            }
            
            return false;
        };
        
        /*
         * TODO (jason-sanjose): extension unit tests should only load the
         * extension and the extensions dependencies. We should not load
         * unrelated extensions. Currently, this solution is all or nothing.
         */
        
        // configure spawned test windows to load extensions
        SpecRunnerUtils.setLoadExtensionsInTestWindow(isExtSuite);
        
        _loadExtensionTests(selectedSuite).done(function () {
            var jasmineEnv = jasmine.getEnv();
            
            // Initiailize unit test preferences for each spec
            beforeEach(function () {
                // Unique key for unit testing
                localStorage.setItem("preferencesKey", SpecRunnerUtils.TEST_PREFERENCES_KEY);
            });
            
            afterEach(function () {
                // Clean up preferencesKey
                localStorage.removeItem("preferencesKey");
            });
            
            jasmineEnv.updateInterval = 1000;
            
            // Create the reporter, which is really a model class that just gathers
            // spec and performance data.
            reporter = new UnitTestReporter(jasmineEnv, topLevelFilter, params.get("spec"));
            
            // Optionally emit JSON for automated runs
            if (params.get("resultsPath")) {
                $(reporter).on("runnerEnd", _runnerEndHandler);
            }
            
            jasmineEnv.addReporter(reporter);
            
            // Create the view that displays the data from the reporter. (Usually in
            // Jasmine this is part of the reporter, but we separate them out so that
            // we can more easily grab just the model data for output during automatic
            // testing.)
            reporterView = new BootstrapReporterView(document, reporter);
            
            // remember the suite for the next unit test window launch
            localStorage.setItem("SpecRunner.suite", selectedSuite);
            
            $(window.document).ready(_documentReadyHandler);
        });
    }