pulsar/spec/jasmine-helper.coffee

60 lines
1.7 KiB
CoffeeScript
Raw Normal View History

fs = require 'fs'
module.exports.runSpecSuite = (specSuite, logFile, logErrors=true) ->
{$, $$} = require '../src/space-pen-extensions'
2013-09-17 22:47:00 +04:00
window[key] = value for key, value of require '../vendor/jasmine'
{TerminalReporter} = require 'jasmine-tagged'
disableFocusMethods() if process.env.JANKY_SHA1
2013-09-18 01:54:33 +04:00
TimeReporter = require './time-reporter'
timeReporter = new TimeReporter()
2013-12-19 05:12:12 +04:00
logStream = fs.openSync(logFile, 'w') if logFile?
2013-12-19 06:35:20 +04:00
log = (str) ->
2013-12-19 05:12:12 +04:00
if logStream?
2013-12-19 06:35:20 +04:00
fs.writeSync(logStream, str)
2013-12-19 05:12:12 +04:00
else
2013-12-19 06:35:20 +04:00
process.stderr.write(str)
if atom.getLoadSettings().exitWhenDone
reporter = new TerminalReporter
2013-12-19 06:35:20 +04:00
print: (str) ->
log(str)
onComplete: (runner) ->
2013-12-19 06:35:20 +04:00
fs.closeSync(logStream) if logStream?
2014-12-13 02:37:43 +03:00
if process.env.JANKY_SHA1
grim = require 'grim'
2015-03-25 20:47:06 +03:00
if grim.getDeprecationsLength() > 0
grim.logDeprecations()
return atom.exit(1) if runner.results().failedCount is 0
if runner.results().failedCount > 0
atom.exit(1)
else
atom.exit(0)
else
2013-09-18 01:54:33 +04:00
AtomReporter = require './atom-reporter'
reporter = new AtomReporter()
2013-02-12 06:00:42 +04:00
require specSuite
jasmineEnv = jasmine.getEnv()
jasmineEnv.addReporter(reporter)
jasmineEnv.addReporter(timeReporter)
jasmineEnv.setIncludedTags([process.platform])
2013-02-02 02:13:09 +04:00
$('body').append $$ -> @div id: 'jasmine-content'
2013-02-02 02:13:09 +04:00
jasmineEnv.execute()
disableFocusMethods = ->
['fdescribe', 'ffdescribe', 'fffdescribe', 'fit', 'ffit', 'fffit'].forEach (methodName) ->
focusMethod = window[methodName]
window[methodName] = (description) ->
error = new Error('Focused spec is running on CI')
focusMethod description, -> throw error