diff --git a/spec/jasmine-test-runner.coffee b/spec/jasmine-test-runner.coffee index a8d165562..dec7652a8 100644 --- a/spec/jasmine-test-runner.coffee +++ b/spec/jasmine-test-runner.coffee @@ -22,8 +22,10 @@ module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) -> setSpecType('user') + resolveWithExitCode = null + promise = new Promise (resolve, reject) -> resolveWithExitCode = resolve jasmineEnv = jasmine.getEnv() - jasmineEnv.addReporter(buildReporter({logFile, headless})) + jasmineEnv.addReporter(buildReporter({logFile, headless, resolveWithExitCode})) TimeReporter = require './time-reporter' jasmineEnv.addReporter(new TimeReporter()) jasmineEnv.setIncludedTags([process.platform]) @@ -37,6 +39,7 @@ module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) -> atom.commands.attach(window) jasmineEnv.execute() + promise disableFocusMethods = -> ['fdescribe', 'ffdescribe', 'fffdescribe', 'fit', 'ffit', 'fffit'].forEach (methodName) -> @@ -68,14 +71,14 @@ setSpecType = (specType) -> setSpecDirectory = (specDirectory) -> setSpecField('specDirectory', specDirectory) -buildReporter = ({logFile, headless}) -> +buildReporter = ({logFile, headless, resolveWithExitCode}) -> if headless - buildTerminalReporter(logFile) + buildTerminalReporter(logFile, resolveWithExitCode) else AtomReporter = require './atom-reporter' reporter = new AtomReporter() -buildTerminalReporter = (logFile) -> +buildTerminalReporter = (logFile, resolveWithExitCode) -> logStream = fs.openSync(logFile, 'w') if logFile? log = (str) -> if logStream? @@ -94,9 +97,10 @@ buildTerminalReporter = (logFile) -> if grim.getDeprecationsLength() > 0 grim.logDeprecations() - return atom.exit(1) + resolveWithExitCode(1) + return if runner.results().failedCount > 0 - atom.exit(1) + resolveWithExitCode(1) else - atom.exit(0) + resolveWithExitCode(0) diff --git a/src/initialize-test-window.coffee b/src/initialize-test-window.coffee index 28e22c0d6..b3d85e423 100644 --- a/src/initialize-test-window.coffee +++ b/src/initialize-test-window.coffee @@ -1,10 +1,14 @@ # Start the crash reporter before anything else. require('crash-reporter').start(productName: 'Atom', companyName: 'GitHub') +remote = require 'remote' + +exitWithStatusCode = (status) => + remote.require('app').emit('will-exit') + remote.process.exit(status) try path = require 'path' ipc = require 'ipc' - remote = require 'remote' {getWindowLoadSettings} = require './window-load-settings-helpers' AtomEnvironment = require '../src/atom-environment' @@ -38,17 +42,18 @@ try legacyTestRunner = require(getWindowLoadSettings().legacyTestRunnerPath) testRunner = require(getWindowLoadSettings().testRunnerPath) - testRunner({ + promise = testRunner({ logFile: getWindowLoadSettings().logFile headless: getWindowLoadSettings().headless testPaths: getWindowLoadSettings().testPaths buildAtomEnvironment: (params) -> new AtomEnvironment(params) legacyTestRunner: legacyTestRunner }) + + promise.then(exitWithStatusCode) if getWindowLoadSettings().headless catch error if getWindowLoadSettings().headless console.error(error.stack ? error) - remote.require('app').emit('will-exit') - remote.process.exit(status) + exitWithStatusCode(1) else throw error