Create an untitled window from `apm test`?


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/
    at AtomApplication.<anonymous> (/Users/mbolin/src/atom/src/browser/
    at emitNone (events.js:67:13)
    at AtomApplication.emit (events.js:163:7)
    at EventEmitter.<anonymous> (/Users/mbolin/src/atom/src/browser/
    at emitTwo (events.js:87:13)
    at EventEmitter.emit (events.js:169:7)
    at EventEmitter.<anonymous> (/Applications/
    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.


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

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.


Thanks for the deep dive @abe! I filed an issue for this: