如何在 v2.6.0 中使新的报告钩子生效?

huangapple go评论52阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月25日 18:59:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331549.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定