2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
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.
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.
26 The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
28 [jasmine-gem]: http://github.com/pivotal/jasmine-gem
34 * ## Require & Instantiate
36 * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
38 window.jasmine = jasmineRequire.core(jasmineRequire);
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.
43 jasmineRequire.html(jasmine);
46 * Create the Jasmine environment. This is used to run all specs in a project.
48 var env = jasmine.getEnv();
51 * ## The Global Interface
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.
55 var jasmineInterface = {
56 describe: function(description, specDefinitions) {
57 return env.describe(description, specDefinitions);
60 xdescribe: function(description, specDefinitions) {
61 return env.xdescribe(description, specDefinitions);
64 it: function(desc, func) {
65 return env.it(desc, func);
68 xit: function(desc, func) {
69 return env.xit(desc, func);
72 beforeEach: function(beforeEachFunction) {
73 return env.beforeEach(beforeEachFunction);
76 afterEach: function(afterEachFunction) {
77 return env.afterEach(afterEachFunction);
80 expect: function(actual) {
81 return env.expect(actual);
88 spyOn: function(obj, methodName) {
89 return env.spyOn(obj, methodName);
92 jsApiReporter: new jasmine.JsApiReporter({
93 timer: new jasmine.Timer()
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`.
100 if (typeof window == "undefined" && typeof exports == "object") {
101 extend(exports, jasmineInterface);
103 extend(window, jasmineInterface);
107 * Expose the interface for adding custom equality testers.
109 jasmine.addCustomEqualityTester = function(tester) {
110 env.addCustomEqualityTester(tester);
114 * Expose the interface for adding custom expectation matchers
116 jasmine.addMatchers = function(matchers) {
117 return env.addMatchers(matchers);
121 * Expose the mock interface for the JavaScript timeout functions
123 jasmine.clock = function() {
128 * ## Runner Parameters
130 * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
133 var queryString = new jasmine.QueryString({
134 getWindowLocation: function() { return window.location; }
137 var catchingExceptions = queryString.getParam("catch");
138 env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
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).
144 var htmlReporter = new jasmine.HtmlReporter({
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()
154 * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
156 env.addReporter(jasmineInterface.jsApiReporter);
157 env.addReporter(htmlReporter);
160 * Filter which specs will be run by matching the start of the full name against the `spec` query param.
162 var specFilter = new jasmine.HtmlSpecFilter({
163 filterString: function() { return queryString.getParam("spec"); }
166 env.specFilter = function(spec) {
167 return specFilter.matches(spec.getFullName());
171 * Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
173 window.setTimeout = window.setTimeout;
174 window.setInterval = window.setInterval;
175 window.clearTimeout = window.clearTimeout;
176 window.clearInterval = window.clearInterval;
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.
183 var currentWindowOnload = window.onload;
185 window.onload = function() {
186 if (currentWindowOnload) {
187 currentWindowOnload();
189 htmlReporter.initialize();
194 * Helper function for readability above.
196 function extend(destination, source) {
197 for (var property in source) destination[property] = source[property];