cenfun / playwright-coverage

Playwright Coverage Reports
MIT License
3 stars 2 forks source link

Complete sourcepath in the SF line of lcov.info is missing #1

Closed KSchrage-SIT closed 2 months ago

KSchrage-SIT commented 2 months ago

I followed the instructions and got coverage working as described. I noticed however, that the lcov.info is missing the full sourcepath of the specifiv files. It only lists the file name.

We get the following SF:App.vue instead of SF:src/App.vue, for example. The ladder is generated from vitest/unit-tests.

Is there any configuration setting I can use here? It seems, that the information is somehow "there", since the generated html-report lists something like "http://localhost-3200/src/App.vue: App.vue".

cenfun commented 2 months ago

It is a common issue, We can resolve full path of the file with option sourcePath (issue https://github.com/cenfun/jest-monocart-coverage/issues/5)

const path = require("path")

// MCR coverage options
{

    sourcePath: (filePath, info)=> {
        if (!filePath.includes('/') && info.distFile) {
            return `${path.dirname(info.distFile)}/${filePath}`;
        }
        return filePath;
    }

}

See sourcePath

KSchrage-SIT commented 2 months ago

Jeah, that looks better now. However I now have SF:localhost-3200/src/App.vue instead of SF:/src/App.vue. Stripping out the localhost-3200 within the sourcePath-lambda, results in SF:../../../../src/App.vue. Do I have to combine this with baseDir or something like that? I double checked the result of the lambda and it returns with /src/App.vue.

cenfun commented 2 months ago

Try following

const path = require("path")

// MCR coverage options
{

    sourcePath: (filePath, info)=> {

        const str = 'localhost-3200';
        if (filePath.startsWith(str)) {
            return filePath.slice(str.length);
        }

        if (!filePath.includes('/') && info.distFile) {
            return `${path.dirname(info.distFile)}/${filePath}`;
        }
        return filePath;
    }

}
KSchrage-SIT commented 2 months ago

Unfortunately that results in SF:../../../../src/App.vue aswell.

cenfun commented 2 months ago

That's weird. But I can't help you unless you provide the reproduction steps

KSchrage-SIT commented 2 months ago

Here's the repro-case. Thanks for your help, really appreciate it. Archiv.zip

cenfun commented 2 months ago

It seems that we need to remove /

// previous
// const str = "localhost-3200";
// please change to

const str = "localhost-3200/";
TN:
SF:src\App.vue
FN:1,(anonymous_0)
KSchrage-SIT commented 2 months ago

That did the trick. Thanks!