function checkCalls()

in dev-utils/webdriver.js [263:321]


      function checkCalls() {
        var serverCalls = apmServerMock.calls
        /**
         * If there is more than one event we consider that as valid call
         */
        var validCall =
          serverCalls.sendEvents && serverCalls.sendEvents.length > 0

        if (validCall) {
          var promises = serverCalls.sendEvents.map(function (s) {
            return s.returnValue
          })
          Promise.all(promises)
            .then(function () {
              var transactions = []
              var errors = []
              var spyCalls = serverCalls.sendEvents
              for (var i = 0; i < spyCalls.length; i++) {
                var args = spyCalls[i].args
                for (var j = 0; j < args.length; j++) {
                  var arg = args[j]
                  arg.forEach(function (event) {
                    if (event['transactions']) {
                      transactions.push(event['transactions'])
                    } else if (event['errors']) {
                      errors.push(event['errors'])
                    }
                  })
                }
              }
              if (
                errors.length >= errorCount &&
                transactions.length >= transactionCount
              ) {
                var calls = {
                  sendEvents: {
                    // eslint-disable-next-line object-shorthand
                    transactions: transactions,
                    // eslint-disable-next-line object-shorthand
                    errors: errors
                  }
                }
                apmServerMock.resetMock()
                done(calls)
              }
            })
            .catch(function (reason) {
              console.log('reason', JSON.stringify(reason))
              apmServerMock.resetMock()
              try {
                done({ error: reason.message || JSON.stringify(reason) })
              } catch (e) {
                done({
                  error: 'Failed serializing rejection reason: ' + e.message
                })
              }
            })
        }
      }