我正在尝试使用 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
中的装置结果,而第二个运行器 fixtures/setup-wizard.js
中的装置不显示任何输出(但它们正在运行并且正在工作),但是使用起来非常烦人,因为如果失败,错误消息也会被吞没。我所做的解决方法是注释掉 setupLicense
固定装置的内容,以便显示 setupData
的输出。
我该如何解决这个问题?
最佳答案
尝试使用最新的 [email protected]版本。该团队最近修复了一个可能导致此类问题的错误 - TestCafe 在未指定显式报告器时关闭了 stdout 输出流。这可以防止在从一个脚本文件开始的第二个和连续测试 session 中显示任何测试结果。
作为解决方法,您可以启用 spec reporter明确添加 .reporter('spec') call到您的设置代码,如本例所示:
gist.github.com/AndreyBelym/c9afd908d4b2891a62a4ba87623ec064
关于node.js - 一个文件中的多个运行者仅产生第一个运行者的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53665738/