/** @babel */

export function beforeEach (fn) {
  global.beforeEach(function () {
    const result = fn()
    if (result instanceof Promise) {
      waitsForPromise(() => result)
    }
  })
}

export function afterEach (fn) {
  global.afterEach(function () {
    const result = fn()
    if (result instanceof Promise) {
      waitsForPromise(() => result)
    }
  })
}

['it', 'fit', 'ffit', 'fffit'].forEach(function (name) {
  module.exports[name] = function (description, fn) {
    global[name](description, function () {
      const result = fn()
      if (result instanceof Promise) {
        waitsForPromise(() => result)
      }
    })
  }
})

export async function conditionPromise (condition)  {
  const startTime = Date.now()

  while (true) {
    await timeoutPromise(100)

    if (await condition()) {
      return
    }

    if (Date.now() - startTime > 5000) {
      throw new Error("Timed out waiting on condition")
    }
  }
}

export function timeoutPromise (timeout) {
  return new Promise(function (resolve) {
    global.setTimeout(resolve, timeout)
  })
}

function waitsForPromise (fn) {
  const promise = fn()
  global.waitsFor('spec promise to resolve', function (done) {
    promise.then(done, function (error) {
      jasmine.getEnv().currentSpec.fail(error)
      done()
    })
  })
}

@@ -8,16 +8,48 @@
 bel */%0A%0A
+import until from 'test-until'%0A%0A
 export f
@@ -1329,16 +1329,253 @@
 )%0A    %7D)%0A  %7D)%0A%7D%0A
+%0Aexport function emitterEventPromise (emitter, event, timeout = 5000) %7B%0A  let called = false%0A  emitter.once(event, () =%3E %7B%0A    called = true%0A    // disposable.dispose()%0A  %7D)%0A  return until(%60$%7Bevent%7D is emitted%60, () =%3E called, timeout)%0A%7D%0A

Add emitterEventPromise helper