Created
April 20, 2011 19:22
-
-
Save djwhitt/932419 to your computer and use it in GitHub Desktop.
Jasmine setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Make Jasmine think this is a browser | |
// | |
setTimeout = function(fn) { fn(arguments); }; | |
clearTimeout = function() {}; | |
setInterval = function() {}; | |
clearInterval = function() {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function noop(){}; | |
jasmine.printRunnerResults = function(runner){ | |
var results = runner.results(); | |
var suites = runner.suites(); | |
var msg = ''; | |
msg += suites.length + ' test' + ((suites.length === 1) ? '' : 's') + ', '; | |
msg += results.totalCount + ' assertion' + ((results.totalCount === 1) ? '' : 's') + ', '; | |
msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + '\n'; | |
return msg; | |
}; | |
var columnCounter = 0; | |
var jasmineEnv = jasmine.getEnv(); | |
var log = []; | |
var start = 0; | |
var elapsed = 0; | |
var verbose = true; | |
jasmineEnv.reporter = { | |
log: function(str){ | |
}, | |
reportSpecStarting: function(runner) { | |
}, | |
reportRunnerStarting: function(runner) { | |
print('Started'); | |
start = Number(new Date); | |
}, | |
reportSuiteResults: function(suite) { | |
var specResults = suite.results(); | |
var path = []; | |
while(suite) { | |
path.unshift(suite.description); | |
suite = suite.parentSuite; | |
} | |
var description = path.join(' '); | |
if (verbose) | |
log.push('Spec ' + description); | |
specResults.items_.forEach(function(spec){ | |
if (spec.failedCount > 0 && spec.description) { | |
if (!verbose) | |
log.push(description); | |
log.push(' it ' + spec.description); | |
spec.items_.forEach(function(result){ | |
log.push(' ' + result.trace.stack + '\n'); | |
}); | |
} | |
}); | |
}, | |
reportSpecResults: function(spec) { | |
// TODO: figure out how to make this work | |
// var result = spec.results(); | |
// var msg = ''; | |
// if (result.passed()) { | |
// msg = '.'; | |
// } else { | |
// msg = 'F'; | |
// } | |
// print(msg); | |
// if (columnCounter++ < 50) return; | |
// columnCounter = 0; | |
// print('\n'); | |
}, | |
reportRunnerResults: function(runner) { | |
elapsed = (Number(new Date) - start) / 1000; | |
print('\n'); | |
log.forEach(function(log){ | |
print(log); | |
}); | |
print('Finished in ' + elapsed + ' seconds'); | |
var summary = jasmine.printRunnerResults(runner); | |
print(summary); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Load Jasmine + reporter | |
// | |
load('spec/spec_env.js'); | |
load('vendor/jasmine-1.0.1/jasmine.js'); | |
load('spec/spec_reporter.js'); | |
// | |
// Load helper | |
// | |
load('spec/spec_helper.js') | |
// | |
// Load ProjectX | |
// | |
load('lib/projectx.js'); | |
// | |
// Load specs | |
// | |
function load_specs(dir) { | |
var files = listFiles(dir); | |
files.forEach(function(file) { | |
if (file.isDirectory) { | |
load_specs(file.name); | |
} else if (file.name.match(/_spec\.js$/)) { | |
load(file.name); | |
} | |
}); | |
} | |
if (g_spec_file !== null) { | |
load(g_spec_file); | |
} else { | |
load_specs('spec'); | |
} | |
// Go go go | |
jasmineEnv.execute(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment