2016-04-14 12:24:01 +03:00
|
|
|
Grim = require 'grim'
|
2015-09-26 00:15:11 +03:00
|
|
|
_ = require 'underscore-plus'
|
|
|
|
fs = require 'fs-plus'
|
|
|
|
path = require 'path'
|
2015-12-11 05:03:20 +03:00
|
|
|
{ipcRenderer} = require 'electron'
|
2015-09-26 00:15:11 +03:00
|
|
|
|
2015-10-06 00:21:46 +03:00
|
|
|
module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) ->
|
2015-09-26 00:15:11 +03:00
|
|
|
window[key] = value for key, value of require '../vendor/jasmine'
|
|
|
|
require 'jasmine-tagged'
|
|
|
|
|
2015-10-13 00:19:55 +03:00
|
|
|
# Allow document.title to be assigned in specs without screwing up spec window title
|
|
|
|
documentTitle = null
|
|
|
|
Object.defineProperty document, 'title',
|
|
|
|
get: -> documentTitle
|
|
|
|
set: (title) -> documentTitle = title
|
|
|
|
|
2015-10-14 00:42:57 +03:00
|
|
|
ApplicationDelegate = require '../src/application-delegate'
|
|
|
|
applicationDelegate = new ApplicationDelegate()
|
2015-10-14 03:54:48 +03:00
|
|
|
applicationDelegate.setRepresentedFilename = ->
|
2015-10-14 00:42:57 +03:00
|
|
|
applicationDelegate.setWindowDocumentEdited = ->
|
2015-10-15 05:05:06 +03:00
|
|
|
window.atom = buildAtomEnvironment({
|
|
|
|
applicationDelegate, window, document,
|
|
|
|
configDirPath: process.env.ATOM_HOME
|
|
|
|
enablePersistence: false
|
|
|
|
})
|
2015-10-13 00:19:55 +03:00
|
|
|
|
2015-09-26 00:15:11 +03:00
|
|
|
require './spec-helper'
|
|
|
|
disableFocusMethods() if process.env.JANKY_SHA1 or process.env.CI
|
|
|
|
requireSpecs(testPath) for testPath in testPaths
|
|
|
|
|
|
|
|
setSpecType('user')
|
|
|
|
|
2015-10-13 10:02:37 +03:00
|
|
|
resolveWithExitCode = null
|
|
|
|
promise = new Promise (resolve, reject) -> resolveWithExitCode = resolve
|
2015-09-26 00:15:11 +03:00
|
|
|
jasmineEnv = jasmine.getEnv()
|
2015-10-13 10:02:37 +03:00
|
|
|
jasmineEnv.addReporter(buildReporter({logFile, headless, resolveWithExitCode}))
|
2015-09-26 00:15:11 +03:00
|
|
|
TimeReporter = require './time-reporter'
|
|
|
|
jasmineEnv.addReporter(new TimeReporter())
|
|
|
|
jasmineEnv.setIncludedTags([process.platform])
|
|
|
|
|
|
|
|
jasmineContent = document.createElement('div')
|
|
|
|
jasmineContent.setAttribute('id', 'jasmine-content')
|
2015-10-06 15:17:47 +03:00
|
|
|
|
2015-09-26 00:15:11 +03:00
|
|
|
document.body.appendChild(jasmineContent)
|
|
|
|
|
|
|
|
jasmineEnv.execute()
|
2015-10-13 10:02:37 +03:00
|
|
|
promise
|
2015-09-26 00:15:11 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-09-28 19:50:59 +03:00
|
|
|
requireSpecs = (testPath, specType) ->
|
|
|
|
if fs.isDirectorySync(testPath)
|
|
|
|
for testFilePath in fs.listTreeSync(testPath) when /-spec\.(coffee|js)$/.test testFilePath
|
|
|
|
require(testFilePath)
|
|
|
|
# Set spec directory on spec for setting up the project in spec-helper
|
|
|
|
setSpecDirectory(testPath)
|
|
|
|
else
|
|
|
|
require(testPath)
|
|
|
|
setSpecDirectory(path.dirname(testPath))
|
2015-09-26 00:15:11 +03:00
|
|
|
|
|
|
|
setSpecField = (name, value) ->
|
|
|
|
specs = jasmine.getEnv().currentRunner().specs()
|
|
|
|
return if specs.length is 0
|
|
|
|
for index in [specs.length-1..0]
|
|
|
|
break if specs[index][name]?
|
|
|
|
specs[index][name] = value
|
|
|
|
|
|
|
|
setSpecType = (specType) ->
|
|
|
|
setSpecField('specType', specType)
|
|
|
|
|
|
|
|
setSpecDirectory = (specDirectory) ->
|
|
|
|
setSpecField('specDirectory', specDirectory)
|
|
|
|
|
2015-10-13 10:02:37 +03:00
|
|
|
buildReporter = ({logFile, headless, resolveWithExitCode}) ->
|
2015-09-26 00:49:57 +03:00
|
|
|
if headless
|
2015-10-13 10:02:37 +03:00
|
|
|
buildTerminalReporter(logFile, resolveWithExitCode)
|
2015-09-26 00:15:11 +03:00
|
|
|
else
|
|
|
|
AtomReporter = require './atom-reporter'
|
|
|
|
reporter = new AtomReporter()
|
|
|
|
|
2015-10-13 10:02:37 +03:00
|
|
|
buildTerminalReporter = (logFile, resolveWithExitCode) ->
|
2015-09-26 00:15:11 +03:00
|
|
|
logStream = fs.openSync(logFile, 'w') if logFile?
|
|
|
|
log = (str) ->
|
|
|
|
if logStream?
|
|
|
|
fs.writeSync(logStream, str)
|
|
|
|
else
|
2015-12-11 05:03:20 +03:00
|
|
|
ipcRenderer.send 'write-to-stderr', str
|
2015-09-26 00:15:11 +03:00
|
|
|
|
|
|
|
{TerminalReporter} = require 'jasmine-tagged'
|
|
|
|
new TerminalReporter
|
|
|
|
print: (str) ->
|
|
|
|
log(str)
|
|
|
|
onComplete: (runner) ->
|
|
|
|
fs.closeSync(logStream) if logStream?
|
2016-04-14 12:24:01 +03:00
|
|
|
if Grim.getDeprecationsLength() > 0
|
|
|
|
Grim.logDeprecations()
|
|
|
|
resolveWithExitCode(1)
|
|
|
|
return
|
2015-09-26 00:15:11 +03:00
|
|
|
|
|
|
|
if runner.results().failedCount > 0
|
2015-10-13 10:02:37 +03:00
|
|
|
resolveWithExitCode(1)
|
2015-09-26 00:15:11 +03:00
|
|
|
else
|
2015-10-13 10:02:37 +03:00
|
|
|
resolveWithExitCode(0)
|