gpt4 book ai didi

node.js - 一个文件中的多个运行者只产生第一个的结果

转载 作者:搜寻专家 更新时间:2023-11-01 00:49:49 25 4
gpt4 key购买 nike

我正在尝试使用 TestCafe 来自动化我项目的初始设置。在安装过程中,必须先发出一个耗时很长的 POST 请求,然后才能继续安装。这是我的 runner.js,它在 Node 10 中运行:

const longRunningPostRequest = require('./setup/seed-database');
const createTestCafe = require('testcafe');

const RUN_OPTIONS = {pageLoadTimeout: 120000, selectorTimeout: 15000};

const setupLicense = async () => {
const testcafe = await createTestCafe('localhost', 1337, 1338, undefined, true);
const runner = testcafe.createRunner();
const failedCount = await runner
.src(['fixtures/setup-license.js'])
.browsers(['chrome -incognito'])
.run(RUN_OPTIONS);
await testcafe.close();
};

const setupData = async () => {
const testcafe = await createTestCafe('localhost', 1337, 1338, undefined, true)
const runner = testcafe.createRunner();
await runner
.src(['fixtures/setup-wizard.js'])
.browsers(['chrome -incognito'])
.run(RUN_OPTIONS);
await testcafe.close();
};

// running them all in sequence
setupLicense()
.then(() => longRunningPostRequest()) // long-running POST request. Typically takes around 100 seconds to complete
.then(() => setupData())
.catch(err => console.log('Error occured:', err));

当我运行应用程序 node runner.js 时,它们正在运行。但是,仅显示 setup-license.js 中的 fixture 结果,而来自第二个运行器 fixtures/setup-wizard.js 的 fixture 不显示任何输出(但它们正在运行并且正在工作),但是使用起来非常烦人,因为如果失败,错误消息也会被吞没。我所做的解决方法是注释掉 setupLicense fixture 的内容,以便显示 setupData 的输出。

我该如何解决这个问题?

最佳答案

尝试使用最新的 testcafe@0.23.3 版本。该团队最近修复了一个可能导致此类问题的错误 - TestCafe 在未指定明确报告程序时关闭了 stdout 输出流。这可以防止在从一个脚本文件开始的第二个和连续的测试 session 中显示任何测试结果。

作为解决方法,您可以启用 spec reporter显式地添加 .reporter('spec') call到您的设置代码,如本例所示:

gist.github.com/AndreyBelym/c9afd908d4b2891a62a4ba87623ec064

关于node.js - 一个文件中的多个运行者只产生第一个的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53665738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com