Skip to content

Commit 1ad79ef

Browse files
author
Jeffery McRiffey
committed
added jasmine2.0 support
1 parent 08e7297 commit 1ad79ef

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-0
lines changed

lib/_patch/jasmine2-boot.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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`, 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 & 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+
* Create the Jasmine environment. This is used to run all specs in a project.
22+
*/
23+
var env = jasmine.getEnv();
24+
25+
/**
26+
* ## The Global Interface
27+
*
28+
* 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.
29+
*/
30+
var jasmineInterface = {
31+
describe: function(description, specDefinitions) {
32+
return env.describe(description, specDefinitions);
33+
},
34+
35+
xdescribe: function(description, specDefinitions) {
36+
return env.xdescribe(description, specDefinitions);
37+
},
38+
39+
it: function(desc, func) {
40+
return env.it(desc, func);
41+
},
42+
43+
xit: function(desc, func) {
44+
return env.xit(desc, func);
45+
},
46+
47+
beforeEach: function(beforeEachFunction) {
48+
return env.beforeEach(beforeEachFunction);
49+
},
50+
51+
afterEach: function(afterEachFunction) {
52+
return env.afterEach(afterEachFunction);
53+
},
54+
55+
expect: function(actual) {
56+
return env.expect(actual);
57+
},
58+
59+
pending: function() {
60+
return env.pending();
61+
},
62+
63+
spyOn: function(obj, methodName) {
64+
return env.spyOn(obj, methodName);
65+
},
66+
67+
jsApiReporter: new jasmine.JsApiReporter({
68+
timer: new jasmine.Timer()
69+
})
70+
};
71+
72+
/**
73+
* 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`.
74+
*/
75+
if (typeof window == "undefined" && typeof exports == "object") {
76+
extend(exports, jasmineInterface);
77+
} else {
78+
extend(window, jasmineInterface);
79+
}
80+
81+
/**
82+
* Expose the interface for adding custom equality testers.
83+
*/
84+
jasmine.addCustomEqualityTester = function(tester) {
85+
env.addCustomEqualityTester(tester);
86+
};
87+
88+
/**
89+
* Expose the interface for adding custom expectation matchers
90+
*/
91+
jasmine.addMatchers = function(matchers) {
92+
return env.addMatchers(matchers);
93+
};
94+
95+
/**
96+
* Expose the mock interface for the JavaScript timeout functions
97+
*/
98+
jasmine.clock = function() {
99+
return env.clock;
100+
};
101+
102+
/**
103+
* The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
104+
*/
105+
env.addReporter(jasmineInterface.jsApiReporter);
106+
107+
/**
108+
* Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
109+
*/
110+
window.setTimeout = window.setTimeout;
111+
window.setInterval = window.setInterval;
112+
window.clearTimeout = window.clearTimeout;
113+
window.clearInterval = window.clearInterval;
114+
115+
/**
116+
* ## Execution
117+
*
118+
* 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.
119+
*/
120+
var currentWindowOnload = window.onload;
121+
122+
window.onload = function() {
123+
if (currentWindowOnload) {
124+
currentWindowOnload();
125+
}
126+
env.execute();
127+
};
128+
129+
/**
130+
* Helper function for readability above.
131+
*/
132+
function extend(destination, source) {
133+
for (var property in source) destination[property] = source[property];
134+
return destination;
135+
}
136+
137+
}());

lib/_patch/jasmine2-plugin.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(function(){
2+
var checker = setInterval(function(){
3+
if(!jasmine.running){
4+
var results = {};
5+
var errors = [];
6+
var specs = jsApiReporter.specs();
7+
results.runtime = jsApiReporter.executionTime() * 1000;
8+
results.total = 0;
9+
results.passed = 0;
10+
results.failed = 0;
11+
results.tracebacks = [];
12+
13+
for(spec in specs){
14+
var s = specs[spec]
15+
16+
if (s.status === 'passed') {
17+
results.passed++;
18+
} else {
19+
results.tracebacks.push(s.description);
20+
results.failed = true;
21+
}
22+
}
23+
24+
results.total = results.passed + results.failed;
25+
results.url = window.location.pathname;
26+
BrowserStack.post("/_report", results, function(){});
27+
}
28+
clearInterval(checker);
29+
}, 1000);
30+
})();
31+

lib/server.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ exports.Server = function Server(bsClient, workers) {
7979
framework_scripts = {
8080
'qunit': ['qunit-plugin.js'],
8181
'jasmine': ['jasmine-jsreporter.js', 'jasmine-plugin.js'],
82+
'jasmine2': ['jasmine2-boot.js', 'jasmine2-plugin.js'],
8283
'mocha': ['mocha-plugin.js']
8384
};
8485

@@ -103,6 +104,10 @@ exports.Server = function Server(bsClient, workers) {
103104
patch += "<script type='text/javascript' src='/_patch/" + script + "'></script>\n";
104105
});
105106
patch += "<script type='text/javascript'>jasmine.getEnv().addReporter(new jasmine.JSReporter());</script>\n";
107+
} else if (config['test_framework'] && config['test_framework'] == "jasmine") {
108+
framework_scripts['jasmine2'].forEach(function(script) {
109+
patch += "<script type='text/javascript' src='/_patch/" + script + "'></script>\n";
110+
});
106111
} else if (config['test_framework'] && config['test_framework'] == "mocha") {
107112
framework_scripts['mocha'].forEach(function(script) {
108113
patch += "<script type='text/javascript' src='/_patch/" + script + "'></script>\n";

0 commit comments

Comments
 (0)