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.
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.