0

我正在尝试做这样的事情,但 testcafe 不会等到测试运行。一旦它点击 t.navigate(url),异步 runtest() 函数就会返回 undefined,并且“eachMessage”代码继续以未定义的值。如何确保 runtest 在返回之前成功完成。显然 await 不起作用,我没有从 testcafe 或 nodejs 收到任何错误消息

先感谢您


const {
  Kafka
} = require('kafkajs')
const kafka = new Kafka({
  clientId: 'my-producer',
  brokers: ['localhost:9092'],
})
const consumer = kafka.consumer({
  groupId: 'consumer-group'
})

const run = async() => {
  await consumer.connect()
  await consumer.subscribe({
    topic: 'topic',
    fromBeginning: true
  })
  await consumer.run({
    eachMessage: async({
      topic,
      partition,
      message
    }) => {
      var data = message.value.toString();
      console.log({
        topic: topic,
        partition: partition,
        value: score,
      })
      var value = await runtest(data)
      console.log(value)
        .
        .
    },
  })
}

run().catch(console.error)


const runtest = async function(data) {
  console.log("Entered runtest"); // logs on console
  await t.navigateTo(data) // t is testcafe object defined globally
  console.log("Navigated"); // does not get logged and nothing after is executed...
  .
  .
}
4

0 回答 0