Create an untitled window from `apm test`?


#1

I am trying to open an untitled window from apm test. Here is what I am trying to do from my test since it works fine from the Chrome DevTools console in Atom:

atom.commands.dispatch(atom.views.getView(atom.workspace), 'application:new-file');

Unfortunately, it does not appear to succeed when run from my test. I see the following stacktrace and atom.workspace.getTextEditors().length does not increase as I would expect:

-2015-08-03 23:34:10.031 Atom[46768:1925367] Cannot read property 'pathToOpen' of undefined
2015-08-03 23:34:10.033 Atom[46768:1925367] TypeError: Cannot read property 'pathToOpen' of undefined
    at AtomApplication.module.exports.AtomApplication.openPath (/Users/mbolin/src/atom/src/browser/atom-application.coffee:585:24)
    at AtomApplication.<anonymous> (/Users/mbolin/src/atom/src/browser/atom-application.coffee:280:70)
    at emitNone (events.js:67:13)
    at AtomApplication.emit (events.js:163:7)
    at EventEmitter.<anonymous> (/Users/mbolin/src/atom/src/browser/atom-application.coffee:460:24)
    at emitTwo (events.js:87:13)
    at EventEmitter.emit (events.js:169:7)
    at EventEmitter.<anonymous> (/Applications/Atom.app/Contents/Resources/atom.asar/browser/api/lib/web-contents.js:86:23)
    at emitTwo (events.js:87:13)
    at EventEmitter.emit (events.js:169:7)

Any idea why this doesn’t work? Presumably I need to file a bug, but I’m curious if anyone knows of a current workaround.

It’s good to test with untitled windows because most packages don’t take into account that TextEditor.getPath() could return undefined.


#2

Hmm looks like you’re right, there’s a problem with that command:

https://github.com/atom/atom/blob/master/src/browser/atom-application.coffee#L170

As I understand that line, it will either call openPath on the focused window or on the atom application instance, but the signatures of the two methods differs:

In AtomApplication the options argument is mandatory (hence the error you get) as it gets deconstructed immediately:

And in AtomWindow the openPath method doesn’t use an option argument:

I guess in your case, since you’re in a console no window get focused so you fall in the second case, where openPath is invoked on the AtomApplication.


#3

Thanks for the deep dive @abe! I filed an issue for this: https://github.com/atom/atom/issues/8239.