diff --git a/spec/console-reporter.es6 b/spec/console-reporter.es6 new file mode 100644 index 000000000..c3ab37ab9 --- /dev/null +++ b/spec/console-reporter.es6 @@ -0,0 +1,31 @@ +const originalLog = console.log; +const originalWarn = console.warn; +const originalError = console.error; + +export default class ConsoleReporter { + reportSpecStarting(spec) { + const withContext = (log) => { + return (...args) => { + if (args[0] === '.') { + return log(...args); + } + return log(`[${spec.getFullName()}] ${args[0]}`, ...args.slice(1, -1 + 1)); + } + } + console.log = withContext(originalLog); + console.warn = withContext(originalWarn); + console.error = withContext(originalError); + } + + reportSpecResults() { + if (console.log !== originalLog) { + console.log = originalLog; + } + if (console.warn !== originalWarn) { + console.warn = originalWarn; + } + if (console.error !== originalError) { + console.error = originalError; + } + } +} diff --git a/spec/jasmine-extensions.es6 b/spec/jasmine-extensions.es6 new file mode 100644 index 000000000..e69de29bb diff --git a/spec/jasmine-helper.es6 b/spec/jasmine-helper.es6 index a597b6f58..32a6d3cfb 100644 --- a/spec/jasmine-helper.es6 +++ b/spec/jasmine-helper.es6 @@ -1,50 +1,31 @@ /* eslint global-require:0 */ -import { remote } from 'electron'; import jasmineExports from './jasmine'; -import {TerminalReporter} from 'jasmine-tagged'; import TimeReporter from './time-reporter' -import N1SpecReporter from './n1-spec-reporter'; +import N1GuiReporter from './n1-gui-reporter'; +import ConsoleReporter from './console-reporter' +import N1TerminalReporter from './terminal-reporter' export function runSpecSuite(specSuite) { - for (const key of Object.keys(jasmineExports)) { - window[key] = jasmineExports[key] - } - const timeReporter = new TimeReporter(); - - const log = (str) => { - return remote.process.stdout.write(str); - }; - - let reporter = new TerminalReporter({ - color: true, - print(str) { - return log(str); - }, - onComplete(runner) { - if (runner.results().failedCount > 0) { - return NylasEnv.exit(1); - } - return NylasEnv.exit(0); - }, - }); - - if (NylasEnv.getLoadSettings().showSpecsInWindow) { - reporter = N1SpecReporter - } - - NylasEnv.initialize(); - - require(specSuite); + const consoleReporter = new ConsoleReporter(); + const terminalReporter = new N1TerminalReporter(); const jasmineEnv = jasmineExports.jasmine.getEnv(); - jasmineEnv.addReporter(reporter); + + if (NylasEnv.getLoadSettings().showSpecsInWindow) { + jasmineEnv.addReporter(N1GuiReporter); + } else { + jasmineEnv.addReporter(terminalReporter); + } jasmineEnv.addReporter(timeReporter); + jasmineEnv.addReporter(consoleReporter); const div = document.createElement('div'); div.id = 'jasmine-content'; document.body.appendChild(div); + require(specSuite); + return jasmineEnv.execute(); } diff --git a/spec/n1-spec-reporter.cjsx b/spec/n1-gui-reporter.cjsx similarity index 99% rename from spec/n1-spec-reporter.cjsx rename to spec/n1-gui-reporter.cjsx index b0a63b52f..5c1349915 100644 --- a/spec/n1-spec-reporter.cjsx +++ b/spec/n1-gui-reporter.cjsx @@ -58,7 +58,7 @@ suiteString: (spec) -> descriptions.join("\n") -class N1SpecReporter extends React.Component +class N1GuiReporter extends React.Component constructor: (@props) -> render: -> @@ -262,7 +262,7 @@ deprecations = [] plainTextOutput = "" update = => - component = - arg = args - if (args.length is 1) - arg = args[0] - console.log(util.inspect(arg)) - -original_log = console.log -original_warn = console.warn -original_error = console.error - -class JasmineConsoleReporter - reportSpecStarting: (spec) -> - withContext = (log) -> - return -> - if arguments[0] is '.' - log(arguments...) - else - log("[#{spec.getFullName()}] #{arguments[0]}", Array(arguments)[1..-1]...) - console.log = withContext(original_log) - console.warn = withContext(original_warn) - console.error = withContext(original_error) - - reportSpecResults: (result) -> - if console.log isnt original_log - console.log = original_log - if console.warn isnt original_warn - console.warn = original_warn - if console.error isnt original_error - console.error = original_error - -jasmine.getEnv().addReporter(new JasmineConsoleReporter()) +# util = require('util') +# console.inspect = (args...) -> +# arg = args +# if (args.length is 1) +# arg = args[0] +# console.log(util.inspect(arg)) +# +# original_log = console.log +# original_warn = console.warn +# original_error = console.error +# +# class JasmineConsoleReporter +# reportSpecStarting: (spec) -> +# withContext = (log) -> +# return -> +# if arguments[0] is '.' +# log(arguments...) +# else +# log("[#{spec.getFullName()}] #{arguments[0]}", Array(arguments)[1..-1]...) +# console.log = withContext(original_log) +# console.warn = withContext(original_warn) +# console.error = withContext(original_error) +# +# reportSpecResults: (result) -> +# if console.log isnt original_log +# console.log = original_log +# if console.warn isnt original_warn +# console.warn = original_warn +# if console.error isnt original_error +# console.error = original_error +# +# jasmine.getEnv().addReporter(new JasmineConsoleReporter()) # # @@ -273,7 +273,8 @@ afterEach -> NylasEnv.themes.removeStylesheet('global-editor-styles') - delete NylasEnv.state?.packageStates + if NylasEnv.state + delete NylasEnv.state.packageStates unless window.debugContent document.getElementById('jasmine-content').innerHTML = '' diff --git a/spec/terminal-reporter.es6 b/spec/terminal-reporter.es6 new file mode 100644 index 000000000..de89cc9b9 --- /dev/null +++ b/spec/terminal-reporter.es6 @@ -0,0 +1,20 @@ +import { remote } from 'electron'; +import {TerminalReporter} from 'jasmine-tagged'; + +export default class N1TerminalReporter extends TerminalReporter { + constructor(opts = {}) { + const options = Object.assign(opts, { + color: true, + print(str) { + return remote.process.stdout.write(str); + }, + onComplete(runner) { + if (runner.results().failedCount > 0) { + return NylasEnv.exit(1); + } + return NylasEnv.exit(0); + }, + }); + super(options) + } +} diff --git a/spec/time-reporter.coffee b/spec/time-reporter.coffee index 3a55b176b..a844957de 100644 --- a/spec/time-reporter.coffee +++ b/spec/time-reporter.coffee @@ -1,5 +1,6 @@ _ = require 'underscore' _str = require 'underscore.string' +{jasmine} = require('./jasmine') module.exports = class TimeReporter extends jasmine.Reporter