Initial OpenECOMP SDC commit
[sdc.git] / catalog-fe / src / test / jasmine-standalone-2.0.0 / lib / jasmine-2.0.0 / boot.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 /**
22  Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
23
24  If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
25
26  The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
27
28  [jasmine-gem]: http://github.com/pivotal/jasmine-gem
29  */
30
31 (function() {
32
33   /**
34    * ## Require & Instantiate
35    *
36    * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
37    */
38   window.jasmine = jasmineRequire.core(jasmineRequire);
39
40   /**
41    * Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
42    */
43   jasmineRequire.html(jasmine);
44
45   /**
46    * Create the Jasmine environment. This is used to run all specs in a project.
47    */
48   var env = jasmine.getEnv();
49
50   /**
51    * ## The Global Interface
52    *
53    * Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
54    */
55   var jasmineInterface = {
56     describe: function(description, specDefinitions) {
57       return env.describe(description, specDefinitions);
58     },
59
60     xdescribe: function(description, specDefinitions) {
61       return env.xdescribe(description, specDefinitions);
62     },
63
64     it: function(desc, func) {
65       return env.it(desc, func);
66     },
67
68     xit: function(desc, func) {
69       return env.xit(desc, func);
70     },
71
72     beforeEach: function(beforeEachFunction) {
73       return env.beforeEach(beforeEachFunction);
74     },
75
76     afterEach: function(afterEachFunction) {
77       return env.afterEach(afterEachFunction);
78     },
79
80     expect: function(actual) {
81       return env.expect(actual);
82     },
83
84     pending: function() {
85       return env.pending();
86     },
87
88     spyOn: function(obj, methodName) {
89       return env.spyOn(obj, methodName);
90     },
91
92     jsApiReporter: new jasmine.JsApiReporter({
93       timer: new jasmine.Timer()
94     })
95   };
96
97   /**
98    * Add all of the Jasmine global/public interface to the proper global, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
99    */
100   if (typeof window == "undefined" && typeof exports == "object") {
101     extend(exports, jasmineInterface);
102   } else {
103     extend(window, jasmineInterface);
104   }
105
106   /**
107    * Expose the interface for adding custom equality testers.
108    */
109   jasmine.addCustomEqualityTester = function(tester) {
110     env.addCustomEqualityTester(tester);
111   };
112
113   /**
114    * Expose the interface for adding custom expectation matchers
115    */
116   jasmine.addMatchers = function(matchers) {
117     return env.addMatchers(matchers);
118   };
119
120   /**
121    * Expose the mock interface for the JavaScript timeout functions
122    */
123   jasmine.clock = function() {
124     return env.clock;
125   };
126
127   /**
128    * ## Runner Parameters
129    *
130    * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
131    */
132
133   var queryString = new jasmine.QueryString({
134     getWindowLocation: function() { return window.location; }
135   });
136
137   var catchingExceptions = queryString.getParam("catch");
138   env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
139
140   /**
141    * ## Reporters
142    * The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
143    */
144   var htmlReporter = new jasmine.HtmlReporter({
145     env: env,
146     onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
147     getContainer: function() { return document.body; },
148     createElement: function() { return document.createElement.apply(document, arguments); },
149     createTextNode: function() { return document.createTextNode.apply(document, arguments); },
150     timer: new jasmine.Timer()
151   });
152
153   /**
154    * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results  from JavaScript.
155    */
156   env.addReporter(jasmineInterface.jsApiReporter);
157   env.addReporter(htmlReporter);
158
159   /**
160    * Filter which specs will be run by matching the start of the full name against the `spec` query param.
161    */
162   var specFilter = new jasmine.HtmlSpecFilter({
163     filterString: function() { return queryString.getParam("spec"); }
164   });
165
166   env.specFilter = function(spec) {
167     return specFilter.matches(spec.getFullName());
168   };
169
170   /**
171    * Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
172    */
173   window.setTimeout = window.setTimeout;
174   window.setInterval = window.setInterval;
175   window.clearTimeout = window.clearTimeout;
176   window.clearInterval = window.clearInterval;
177
178   /**
179    * ## Execution
180    *
181    * Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
182    */
183   var currentWindowOnload = window.onload;
184
185   window.onload = function() {
186     if (currentWindowOnload) {
187       currentWindowOnload();
188     }
189     htmlReporter.initialize();
190     env.execute();
191   };
192
193   /**
194    * Helper function for readability above.
195    */
196   function extend(destination, source) {
197     for (var property in source) destination[property] = source[property];
198     return destination;
199   }
200
201 }());