   [tokenizedBuffer, buffer, changeHandler] = []
 
   beforeEach ->
-    atom.packages.activatePackage('language-javascript', sync: true)
     # enable async tokenization
     TokenizedBuffer.prototype.chunkSize = 5
     jasmine.unspy(TokenizedBuffer.prototype, 'tokenizeInBackground')
+
+    waitsForPromise ->
+      atom.packages.activatePackage('language-javascript')
 
   startTokenizing = (tokenizedBuffer) ->
     tokenizedBuffer.setVisible(true)


  describe "when the buffer contains hard-tabs", ->
    beforeEach ->
      atom.packages.activatePackage('language-coffee-script', sync: true)
      buffer = atom.project.bufferForPathSync('sample-with-tabs.coffee')
      tokenizedBuffer = new TokenizedBuffer({buffer})
      startTokenizing(tokenizedBuffer)

    afterEach ->
      tokenizedBuffer.destroy()


  describe "when the buffer contains surrogate pairs", ->
    beforeEach ->
      waitsForPromise ->
        atom.packages.activatePackage('language-javascript')

      runs ->
        buffer = atom.project.bufferForPathSync 'sample-with-pairs.js'
        buffer.setText """
          'abc\uD835\uDF97def'
          //\uD835\uDF97xyz
        """
        tokenizedBuffer = new TokenizedBuffer({buffer})
        fullyTokenize(tokenizedBuffer)

    afterEach ->
      tokenizedBuffer.destroy()
