mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-28 21:24:26 +08:00
No changes in the changelog (https://github.com/karma-runner/karma/blob/master/CHANGELOG.md) to concern ourselves about, but one useful change is they upgraded the log4js dependency which was spitting out console messages on each test run. This is fixed with this version of Karma. Bug: none Change-Id: Ic49618cbda7a079cacb9813f5129692a83508a92 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3745621 Commit-Queue: Jack Franklin <jacktfranklin@chromium.org> Auto-Submit: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Philip Pfaffe <pfaffe@chromium.org> Commit-Queue: Philip Pfaffe <pfaffe@chromium.org>
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
'use strict'
|
|
|
|
const EventEmitter = require('events').EventEmitter
|
|
const helper = require('./helper')
|
|
|
|
function bufferEvents (emitter, eventsToBuffer) {
|
|
const listeners = []
|
|
const eventsToReply = []
|
|
|
|
function genericListener () {
|
|
eventsToReply.push(Array.from(arguments))
|
|
}
|
|
|
|
eventsToBuffer.forEach((eventName) => {
|
|
const listener = genericListener.bind(null, eventName)
|
|
listeners.push(listener)
|
|
emitter.on(eventName, listener)
|
|
})
|
|
|
|
return function () {
|
|
listeners.forEach((listener, i) => {
|
|
emitter.removeListener(eventsToBuffer[i], listener)
|
|
})
|
|
|
|
eventsToReply.forEach((args) => {
|
|
EventEmitter.prototype.emit.apply(emitter, args)
|
|
})
|
|
|
|
listeners.length = 0
|
|
eventsToReply.length = 0
|
|
}
|
|
}
|
|
|
|
class KarmaEventEmitter extends EventEmitter {
|
|
bind (object) {
|
|
for (const method in object) {
|
|
if (method.startsWith('on') && helper.isFunction(object[method])) {
|
|
this.on(helper.camelToSnake(method.slice(2)), function () {
|
|
// We do not use an arrow function here, to supply the caller as this.
|
|
object[method].apply(object, Array.from(arguments).concat(this))
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
emitAsync (name) {
|
|
// TODO(vojta): allow passing args
|
|
// TODO(vojta): ignore/throw if listener call done() multiple times
|
|
let pending = this.listeners(name).length
|
|
const deferred = helper.defer()
|
|
|
|
this.emit(name, () => {
|
|
if (!--pending) {
|
|
deferred.resolve()
|
|
}
|
|
})
|
|
|
|
if (!pending) {
|
|
deferred.resolve()
|
|
}
|
|
|
|
return deferred.promise
|
|
}
|
|
}
|
|
|
|
exports.EventEmitter = KarmaEventEmitter
|
|
exports.bufferEvents = bufferEvents
|