DevExpress / testcafe-reporter-xunit

This is the xUnit reporter plugin for TestCafe.
https://testcafe.io
MIT License
10 stars 30 forks source link

feat: possibility to pass basePath option #32

Closed AGrigorii closed 1 year ago

AGrigorii commented 1 year ago

Hello Because of this comment I've created this MR.

image

It already correct works for js config file. In my case, I have typescript version of. I have to type config object as Partial<TestCafeConfigurationOptions> & { hooks: any }, unfortunately it knows nothing about options possibility for reporters, but it already used

Notes: If we agreed to change only reporter's repository, then I'm not able to support cli and createRunner

AlexKamaev commented 1 year ago

Why do we need to use the options.basePath argument here? Can we just use process.cwd() instead of options.basePath?

AGrigorii commented 1 year ago

Why do we need to use the options.basePath argument here? Can we just use process.cwd() instead of options.basePath?

First of all, process.cwd() is not suitable because some one can arrange launching via child_processes. Here could be process.env.PWD or process.env.INIT_CWD. However, PWD is the first version of this MR. But I had a lot of concerns about this approach. It will be correct for most of cases, but not for all of them. PWD or INIT_CWD causes to major version be released. If we use options.basePath only feature bump is needed and it will be clear while setting up repository. (you are able to setup absolute paths or relative path and rootDir settings is under your control)

AGrigorii commented 1 year ago

@AlexKamaev just in case, do you have any doubts about option-way to achieve it?

AGrigorii commented 1 year ago

Any objections?

AlexKamaev commented 1 year ago

I discussed the PR with the team, and we decided that we are not ready to accept a PR with any additional options. The process.cwd() is more appropriate way even if does not cover 100% of use cases.

Artem-Babich commented 1 year ago

Hi, we decided not to merge this PR because it uses internal API: the "options" argument. You can accomplish your task with a new onBeforeWrite hook as follows:

//.testcaferc.js

const basePath = process.cwd();
const replacePathRegExp = new RegExp(basePath);

module.exports = {
    hooks: {
        reporter: {
            onBeforeWrite: {
                xunit: (writeInfo) => {
                    if (writeInfo.initiator !== 'reportTaskDone')
                        return;

                    writeInfo.formattedText = writeInfo.formattedText.replace(replacePathRegExp, () => '')
                }
            }
        }
    }
}