【问题标题】:Let Puppeteer wait for globalSetup to finish让 Puppeteer 等待 globalSetup 完成
【发布时间】:2019-12-13 17:15:39
【问题描述】:

我使用 Jest-Puppeteer 对 web 应用程序进行端到端测试。所有测试都与异步函数并行运行。现在我发现第一个测试在 globalSetup 完成并且数据准备完成之前已经运行(初始化客户端设置等)

我尝试在请求后超时,但这不起作用,因为现在所有请求都有超时。

import puppeteer from "puppeteer";

import { getUrlByPath, post } from "../helper";

module.exports = async function globalSetup(globalConfig) {
  await setupPuppeteer(globalConfig);

  puppeteer.launch({args: ["--no-sandbox", "--disable-setuid-sandbox"]}).then(async browser => {
    const page = await browser.newPage();

    await post(
      page,
      getUrlByPath("somePath"),
      "prepare_data_for_testing",
    );

    await browser.close();
  });
};

上面的代码运行一个 globalConfig,之后它开始为测试环境准备数据。

有没有办法让测试套件在此脚本返回带有http 200: ok 的帖子之后运行?

【问题讨论】:

    标签: testing jestjs puppeteer jest-puppeteer


    【解决方案1】:

    我必须在puppeteer.launch 之前放置await 并在顶部添加require("expect-puppeteer");

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-29
      • 2022-07-27
      • 2022-07-27
      • 2021-09-14
      • 2019-03-17
      • 2015-11-11
      • 2020-11-22
      • 2020-07-09
      相关资源
      最近更新 更多