     buffer.setText(buffer.getText().replace(/[ ]{2}/g, "\t"))
 
   beforeEach ->
-    editor = atom.project.openSync('sample.js', autoIndent: false)
-    buffer = editor.buffer
-    lineLengths = buffer.getLines().map (line) -> line.length
+    waitsForPromise ->
+      atom.project.open('sample.js', autoIndent: false).then (o) -> editor = o
+
+    runs ->
+      buffer = editor.buffer
+      lineLengths = buffer.getLines().map (line) -> line.length
 
     waitsForPromise ->
       atom.packages.activatePackage('language-javascript')


      it "does not explode if the current language mode has no comment regex", ->
        editor.destroy()
        editor = atom.project.openSync(null, autoIndent: false)
        editor.setSelectedBufferRange([[4, 5], [4, 5]])
        editor.toggleLineCommentsInSelection()
        expect(buffer.lineForRow(4)).toBe "    while(items.length > 0) {"

      it "uncomments when the line lacks the trailing whitespace in the comment regex", ->
        editor.setCursorBufferPosition([10, 0])

        expect(selection1.isReversed()).toBeTruthy()

      it "merges selections when they intersect when moving left", ->
        editor.setSelectedBufferRanges([[[0,9], [0,13]], [[0,14], [1,20]]], reversed: true)
        [selection1, selection2] = editor.getSelections()

        editor.selectLeft()
