英文:
How can I get new reporter hook working in v2.6.0?
问题
I am trying to add test duration and noticed onBeforeWrite was released in v2.6.0. I am using this version but when I try the code written in the docs, I don't see duration being printed. Am I missing something?
Url for the release with the code
https://testcafe.io/404399/release-notes/framework/2023-5-11-testcafe-v2-6-0-released
//.testcaferc.js or .testcaferc.cjs
function onBeforeWriteHook(writeInfo) { // This function will fire every time the reporter calls the "write" method.
if (writeInfo.initiator === 'reportTestDone') { // The "initiator" property contains the name of the reporter event that triggered the hook.
const {
name,
testRunInfo,
meta
} = writeInfo.data || {}; // If you attached this hook to a compatible reporter (such as "spec" or "list"), the hook can process data related to the event.
const testDuration = testRunInfo.durationMs; // Save the duration of the test.
writeInfo.formattedText = writeInfo.formattedText + ' (' + testDuration + 'ms)'; // Add test duration to the reporter output.
};
}
module.exports = { // Attach the hook
hooks: {
reporter: {
onBeforeWrite: {
'spec': onBeforeWriteHook, // This hook will fire when you use the default "spec" reporter.
},
},
},
};
I am expecting to see the description of the test being printed with duration.
英文:
I am trying to add test duration and noticed onBeforeWrite was released in v2.6.0. I am using this version but when I try the code written in the docs, I don't see duration being printed. Am I missing something?
Url for the release with the code
https://testcafe.io/404399/release-notes/framework/2023-5-11-testcafe-v2-6-0-released
//.testcaferc.js or .testcaferc.cjs
function onBeforeWriteHook(writeInfo) { // This function will fire every time the reporter calls the "write" method.
if (writeInfo.initiator === 'reportTestDone') { // The "initiator" property contains the name of the reporter event that triggered the hook.
const {
name,
testRunInfo,
meta
} = writeInfo.data || {}; // If you attached this hook to a compatible reporter (such as "spec" or "list"), the hook can process data related to the event.
const testDuration = testRunInfo.durationMs; // Save the duration of the test.
writeInfo.formattedText = writeInfo.formattedText + ' (' + testDuration + 'ms)'; // Add test duration to the reporter output.
};
}
module.exports = { // Attach the hook
hooks: {
reporter: {
onBeforeWrite: {
'spec': onBeforeWriteHook, // This hook will fire when you use the default "spec" reporter.
},
},
},
};
I am expecting to see the description of the test being printed with duration.
答案1
得分: 1
没有足够的信息来找出问题的原因。您将配置文件放在项目的哪个位置?默认情况下,TestCafe 尝试从项目根目录读取它。如果不是这样,请使用 --config-file
来设置配置文件的直接路径。
英文:
There is not enough information to find out the reason for the issue. Where did you put the config file in your project? By default, TestCafe tries to read it from the project root. If not, use --config-file
to set a direct path to the config.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论