From c719dc8aa2f63fda790bc52cfa6acb272cbae3ae Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Fri, 19 Apr 2019 17:37:23 -0400 Subject: [PATCH] Test empty command-line cases --- spec/main-process/atom-application.test.js | 30 ++++++++++++++++++++++ src/main-process/atom-application.js | 8 ++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/spec/main-process/atom-application.test.js b/spec/main-process/atom-application.test.js index 0e9a42b6b..c2685fdc1 100644 --- a/spec/main-process/atom-application.test.js +++ b/spec/main-process/atom-application.test.js @@ -56,6 +56,12 @@ describe('AtomApplication', function () { describe('command-line interface behavior', function () { describe('with no open windows', function () { + // This is also the case when a user selects the application from the OS shell + it('opens an empty window', async function () { + await scenario.launch(parseCommandLine([])) + await scenario.assert('[_ _]') + }) + // This is also the case when a user clicks on a file in their file manager it('opens a file', async function () { await scenario.open(parseCommandLine(['a/1.md'])) @@ -182,6 +188,12 @@ describe('AtomApplication', function () { await scenario.preconditions('[_ _]') }) + // This is also the case when a user selects the application from the OS shell + it('opens a new, empty window', async function () { + await scenario.open(parseCommandLine([])) + await scenario.assert('[_ _] [_ _]') + }) + // This is also the case when a user clicks on a file in their file manager it('opens a file', async function () { await scenario.open(parseCommandLine(['a/1.md'])) @@ -220,6 +232,12 @@ describe('AtomApplication', function () { await scenario.preconditions('[a _]') }) + // This is also the case when a user selects the application from the OS shell + it('opens a new, empty window', async function () { + await scenario.open(parseCommandLine([])) + await scenario.assert('[a _] [_ _]') + }) + // This is also the case when a user clicks on a file within the project root in their file manager it('opens a file within the project root', async function () { await scenario.open(parseCommandLine(['a/1.md'])) @@ -290,6 +308,12 @@ describe('AtomApplication', function () { await scenario.preconditions('[a _] [_ _]') }) + // This is also the case when a user selects the application from the OS shell + it('opens a new, empty window', async function () { + await scenario.open(parseCommandLine([])) + await scenario.assert('[a _] [_ _] [_ _]') + }) + // This is also the case when a user clicks on a file within the project root in their file manager it('opens a file within the project root', async function () { await scenario.open(parseCommandLine(['a/1.md'])) @@ -360,6 +384,12 @@ describe('AtomApplication', function () { await scenario.preconditions('[_ _] [a _]') }) + // This is also the case when a user selects the application from the OS shell + it('opens a new, empty window', async function () { + await scenario.open(parseCommandLine([])) + await scenario.assert('[_ _] [a _] [_ _]') + }) + // This is also the case when a user clicks on a file within the project root in their file manager it('opens a file within the project root', async function () { await scenario.open(parseCommandLine(['a/1.md'])) diff --git a/src/main-process/atom-application.js b/src/main-process/atom-application.js index e622816f5..020e450fb 100644 --- a/src/main-process/atom-application.js +++ b/src/main-process/atom-application.js @@ -349,6 +349,7 @@ class AtomApplication extends EventEmitter { } else { // Always open an editor window if this is the first instance of Atom. return this.openPath({ + pathToOpen: null, pidToKillWhenClosed, newWindow, devMode, @@ -991,15 +992,18 @@ class AtomApplication extends EventEmitter { return } + const hasNonEmptyPath = locationsToOpen.some(location => location.pathToOpen) + const createNewWindow = newWindow || !hasNonEmptyPath + let existingWindow - if (!newWindow) { + if (!createNewWindow) { // An explicitly provided AtomWindow has precedence. existingWindow = window // If no window is specified and at least one path is provided, locate an existing window that contains all // provided paths. - if (!existingWindow && locationsToOpen.some(location => location.pathToOpen)) { + if (!existingWindow && hasNonEmptyPath) { existingWindow = this.windowForLocations(locationsToOpen, devMode, safeMode) }