source: pyenvjasmine/pyenvjasmine/envjasmine/lib/jasmine-3.1.0/boot.js@ 36:4c964b691922

Last change on this file since 36:4c964b691922 was 36:4c964b691922, checked in by Mauro Molino <mauro@…>, 6 years ago

Selectable engine (phantom with jasmine3, rhino with jasmine1)

File size: 5.1 KB
Line 
1/**
2 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` and `jasmine_html.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.
3
4 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.
5
6 The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
7
8 [jasmine-gem]: http://github.com/pivotal/jasmine-gem
9 */
10
11(function() {
12
13 /**
14 * ## Require &amp; Instantiate
15 *
16 * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
17 */
18 window.jasmine = jasmineRequire.core(jasmineRequire);
19
20 /**
21 * 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.
22 */
23 jasmineRequire.html(jasmine);
24
25 /**
26 * Create the Jasmine environment. This is used to run all specs in a project.
27 */
28 var env = jasmine.getEnv();
29
30 /**
31 * ## The Global Interface
32 *
33 * 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.
34 */
35 var jasmineInterface = jasmineRequire.interface(jasmine, env);
36
37 /**
38 * Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
39 */
40 extend(window, jasmineInterface);
41
42 /**
43 * ## Runner Parameters
44 *
45 * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
46 */
47
48 var queryString = new jasmine.QueryString({
49 getWindowLocation: function() { return window.location; }
50 });
51
52 var filterSpecs = !!queryString.getParam("spec");
53
54 var stoppingOnSpecFailure = queryString.getParam("failFast");
55 env.stopOnSpecFailure(stoppingOnSpecFailure);
56
57 var throwingExpectationFailures = queryString.getParam("throwFailures");
58 env.throwOnExpectationFailure(throwingExpectationFailures);
59
60 var random = queryString.getParam("random");
61
62 if (random !== undefined && random !== "") {
63 env.randomizeTests(random);
64 }
65
66 var seed = queryString.getParam("seed");
67 if (seed) {
68 env.seed(seed);
69 }
70
71 /**
72 * ## Reporters
73 * 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).
74 */
75 var htmlReporter = new jasmine.HtmlReporter({
76 env: env,
77 navigateWithNewParam: function(key, value) { return queryString.navigateWithNewParam(key, value); },
78 addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); },
79 getContainer: function() { return document.body; },
80 createElement: function() { return document.createElement.apply(document, arguments); },
81 createTextNode: function() { return document.createTextNode.apply(document, arguments); },
82 timer: new jasmine.Timer(),
83 filterSpecs: filterSpecs
84 });
85
86 /**
87 * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
88 */
89 env.addReporter(jasmineInterface.jsApiReporter);
90 env.addReporter(htmlReporter);
91
92 /**
93 * Filter which specs will be run by matching the start of the full name against the `spec` query param.
94 */
95 var specFilter = new jasmine.HtmlSpecFilter({
96 filterString: function() { return queryString.getParam("spec"); }
97 });
98
99 env.specFilter = function(spec) {
100 return specFilter.matches(spec.getFullName());
101 };
102
103 /**
104 * Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
105 */
106 window.setTimeout = window.setTimeout;
107 window.setInterval = window.setInterval;
108 window.clearTimeout = window.clearTimeout;
109 window.clearInterval = window.clearInterval;
110
111 /**
112 * ## Execution
113 *
114 * 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.
115 */
116 var currentWindowOnload = window.onload;
117
118 window.onload = function() {
119 if (currentWindowOnload) {
120 currentWindowOnload();
121 }
122 htmlReporter.initialize();
123 env.execute();
124 };
125
126 /**
127 * Helper function for readability above.
128 */
129 function extend(destination, source) {
130 for (var property in source) destination[property] = source[property];
131 return destination;
132 }
133
134}());
Note: See TracBrowser for help on using the repository browser.