如何在没有 Web 浏览器交互的情况下在 nightwatch.js 中等待任意时间

How to wait an arbitrary amount of time in nightwatch.js without web browser interaction

我正在将我的测试从 Intern.js 迁移到 Nightwatch.js,我确定这不是 推荐的 编写测试的方式,但我的测试异步进行 browser 命令调用(我的测试使用具有自己的命令队列的 class)。根据正在执行的内容,Nightwatch 命令队列有时可能为空,但最终会被填充。我需要一种方法来手动告诉 Nightwatch 何时完成,然后等到那时,否则浏览器会关闭得太早。

我可以这样做:

finished() {
  let done = false;
  //will run at the end of my class's internal command queue
  this.command
    .then(() => {
      done = true;
    });
    
  //will cause nightwatch to wait until my command queue is done
  this.browser.perform(doneFn => {
    const check = () => {
      if (done) {
        return doneFn();
      }
      setTimeout(check, 10);
    }
    check();
  });
}

但那样的话perform()会在等待10秒后超时,而且我似乎无法配置它。否则我可以 运行 一系列 ~9 秒 perform() 调用,但这听起来太老套了。我可以重写以依赖于守夜人命令队列,但重写所有内容也需要更多工作。

最后,改用 nightwatch 的命令队列更容易。任何只是 .then() 和 Intern.js 的东西都变成了各种形式的 .perform()