From abee4c1db410834aa790e99e8e4f3c84e85171b3 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sat, 17 Oct 2015 10:39:26 -0600 Subject: [PATCH 1/3] Default devMode to true ASAP if running Atom in test mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, we ran the window in devMode, but didn’t set devMode to true early enough to compute the correct resource path. This caused errors when attempting to load the bundled keymaps when running atom —test without the —dev flag. --- src/browser/atom-application.coffee | 5 ++--- src/browser/main.coffee | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index b8e3e7bc2..ab7a45db9 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -91,7 +91,7 @@ class AtomApplication openWithOptions: ({pathsToOpen, executedFrom, urlsToOpen, test, pidToKillWhenClosed, devMode, safeMode, newWindow, logFile, profileStartup, timeout}) -> if test - @runTests({headless: true, @resourcePath, executedFrom, pathsToOpen, logFile, timeout}) + @runTests({headless: true, devMode, @resourcePath, executedFrom, pathsToOpen, logFile, timeout}) else if pathsToOpen.length > 0 @openPaths({pathsToOpen, executedFrom, pidToKillWhenClosed, newWindow, devMode, safeMode, profileStartup}) else if urlsToOpen.length > 0 @@ -494,7 +494,7 @@ class AtomApplication # :specPath - The directory to load specs from. # :safeMode - A Boolean that, if true, won't run specs from ~/.atom/packages # and ~/.atom/dev/packages, defaults to false. - runTests: ({headless, resourcePath, executedFrom, pathsToOpen, logFile, safeMode, timeout}) -> + runTests: ({headless, devMode, resourcePath, executedFrom, pathsToOpen, logFile, safeMode, timeout}) -> if resourcePath isnt @resourcePath and not fs.existsSync(resourcePath) resourcePath = @resourcePath @@ -522,7 +522,6 @@ class AtomApplication legacyTestRunnerPath = @resolveLegacyTestRunnerPath() testRunnerPath = @resolveTestRunnerPath(testPaths[0]) isSpec = true - devMode = true safeMode ?= false new AtomWindow({windowInitializationScript, resourcePath, headless, isSpec, devMode, testRunnerPath, legacyTestRunnerPath, testPaths, logFile, safeMode}) diff --git a/src/browser/main.coffee b/src/browser/main.coffee index 6a141cf1a..990002671 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -133,6 +133,8 @@ parseCommandLine = -> if args['resource-path'] devMode = true resourcePath = args['resource-path'] + + devMode = true if test resourcePath ?= devResourcePath if devMode unless fs.statSyncNoException(resourcePath) From c35411cd29a047db92a9974bc3d972cd3d654fbb Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sat, 17 Oct 2015 10:52:39 -0600 Subject: [PATCH 2/3] :art: --- src/initialize-test-window.coffee | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/initialize-test-window.coffee b/src/initialize-test-window.coffee index ad15429ff..ecacddd4e 100644 --- a/src/initialize-test-window.coffee +++ b/src/initialize-test-window.coffee @@ -13,9 +13,11 @@ try AtomEnvironment = require '../src/atom-environment' ApplicationDelegate = require '../src/application-delegate' + {testRunnerPath, legacyTestRunnerPath, headless, logFile, testPaths} = getWindowLoadSettings() + # Show window synchronously so a focusout doesn't fire on input elements # that are focused in the very first spec run. - remote.getCurrentWindow().show() unless getWindowLoadSettings().headless + remote.getCurrentWindow().show() unless headless handleKeydown = (event) -> # Reload: cmd-r / ctrl-r @@ -39,15 +41,13 @@ try document.title = "Spec Suite" - legacyTestRunner = require(getWindowLoadSettings().legacyTestRunnerPath) - testRunner = require(getWindowLoadSettings().testRunnerPath) + testRunner = require(testRunnerPath) + legacyTestRunner = require(legacyTestRunnerPath) + buildAtomEnvironment = (params) -> new AtomEnvironment(params) + buildDefaultApplicationDelegate = (params) -> new ApplicationDelegate() + promise = testRunner({ - logFile: getWindowLoadSettings().logFile - headless: getWindowLoadSettings().headless - testPaths: getWindowLoadSettings().testPaths - buildAtomEnvironment: (params) -> new AtomEnvironment(params) - buildDefaultApplicationDelegate: (params) -> new ApplicationDelegate() - legacyTestRunner: legacyTestRunner + logFile, headless, testPaths, buildAtomEnvironment, buildDefaultApplicationDelegate, legacyTestRunner }) promise.then(exitWithStatusCode) if getWindowLoadSettings().headless From 979b08f5fe18ce0a764c4037f5633ea552d94854 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sat, 17 Oct 2015 10:55:23 -0600 Subject: [PATCH 3/3] Override console.log/error/warn in headless mode to log to stdout/stderr --- src/initialize-test-window.coffee | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/initialize-test-window.coffee b/src/initialize-test-window.coffee index ecacddd4e..27ef46acc 100644 --- a/src/initialize-test-window.coffee +++ b/src/initialize-test-window.coffee @@ -15,9 +15,19 @@ try {testRunnerPath, legacyTestRunnerPath, headless, logFile, testPaths} = getWindowLoadSettings() - # Show window synchronously so a focusout doesn't fire on input elements - # that are focused in the very first spec run. - remote.getCurrentWindow().show() unless headless + if headless + # Override logging in headless mode so it goes to the console, regardless + # of the --enable-logging flag to Electron. + console.log = (args...) -> + ipc.send 'write-to-stdout', args.join(' ') + '\n' + console.warn = (args...) -> + ipc.send 'write-to-stderr', args.join(' ') + '\n' + console.error = (args...) -> + ipc.send 'write-to-stderr', args.join(' ') + '\n' + else + # Show window synchronously so a focusout doesn't fire on input elements + # that are focused in the very first spec run. + remote.getCurrentWindow().show() handleKeydown = (event) -> # Reload: cmd-r / ctrl-r