jasmine-helper.js
1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Is injected into the spec runner file
* Copyright (c) 2012 Camille Reynders
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
/*global jasmine:true, alert:true*/
// Send messages to the parent phantom.js process via alert! Good times!!
function sendMessage(){
var args = [].slice.call( arguments );
alert( JSON.stringify( args ) );
}
var GruntReporter = function(){
this._started = this._getTime();
};
GruntReporter.prototype = {
_getTime : function(){
return new Date().getTime();
},
/**
* @param {jasmine.Suite} suite
*/
_getSuitesToRoot : function( suite ){
var result = [];
do{
result.unshift( suite.description );
suite = suite.parentSuite;
}while( suite );
return result;
},
/**
* @param {jasmine.Suite} suite
*/
reportRunnerResults : function( runner ){
var elapsed = this._getTime() - this._started;
sendMessage( 'done', elapsed );
},
/**
*
* @param {jasmine.Spec} spec
*/
reportSpecResults : function( spec ){
var results = spec.results();
var suites = this._getSuitesToRoot( spec.suite );
sendMessage( 'testDone', suites.join( ' ' ), spec.description, results.totalCount, results.passedCount, results.failedCount, results.skipped );
}
};
jasmine.getEnv().addReporter( new GruntReporter() );