cenfun / monocart-reporter

A playwright test reporter (Node.js)
https://cenfun.github.io/monocart-reporter/
MIT License
214 stars 12 forks source link

[Bug] can not resolve source-map on Next.js 15 #161

Open azu opened 2 weeks ago

azu commented 2 weeks ago

Describe the bug

I've tested next-with-playwright with Next.js 15, but the coverage file refer to js file, not ts file. https://github.com/cenfun/nextjs-with-playwright

Probably, it can not resolve source-map.

To Reproduce

        "monocart-coverage-reports": "^2.11.2",
        "monocart-reporter": "^2.9.10",

Coverage refer to *.js files.

[MCR] Next.js V8 Coverage Report
┌────────────────────────────────────┬──────────┬────────────┬──────────┬───────────┬─────────┬────────────────────────────────────────────────────┐
│ Name                               │    Bytes │ Statements │ Branches │ Functions │   Lines │ Uncovered Lines                                    │
├────────────────────────────────────┼──────────┼────────────┼──────────┼───────────┼─────────┼────────────────────────────────────────────────────┤
│ .next/server/app                   │          │            │          │           │         │                                                    │
│ ├ about                            │          │            │          │           │         │                                                    │
│ │ └ page.js                        │  69.14 % │    82.86 % │          │   63.16 % │ 76.47 % │ 85-90,96-100,106-110,116-120,126-130,136-140,14... │
│ └ page.js                          │  70.29 % │    87.50 % │          │   66.67 % │ 82.11 % │ 85-89,95-99,105-109,115-119,125-129,135-139,167    │
│ localhost-3000/_next/static/chunks │          │            │          │           │         │                                                    │
│ ├ app-pages-internals.js           │  44.75 % │    55.56 % │  50.00 % │   57.89 % │ 62.50 % │ 9,36-41,47-52,58-63,69-74,80-85,91-96,102-107,1... │
│ ├ app                              │          │            │          │           │         │                                                    │
│ │ ├ about                          │          │            │          │           │         │                                                    │
│ │ │ └ page.js                      │   2.90 % │    12.50 % │  50.00 % │   16.00 % │ 27.97 % │ 9,25-30,36-41,47-52,58-63,69-74,80-85,91-96,102... │
│ │ └ page.js                        │ 100.00 % │   100.00 % │  50.00 % │  100.00 % │ 99.25 % │ 9                                                  │
│ ├ main-app.js                      │          │            │          │           │         │                                                    │
│ │ ├ v=1731284496315                │  99.70 % │    99.07 % │  50.00 % │   99.09 % │ 99.17 % │ 9,449-454,658-663                                  │
│ │ └ v=1731284496316                │  99.70 % │    99.07 % │  50.00 % │   99.09 % │ 99.17 % │ 9,449-454,658-663                                  │
│ └ webpack.js                       │          │            │          │           │         │                                                    │
│   ├ v=1731284496315                │  33.63 % │    31.35 % │  20.54 % │   37.34 % │ 32.07 % │ 21,40,66,96-98,106,116,119,125-128,162-165,171-... │
│   └ v=1731284496316                │  55.71 % │    54.15 % │  34.23 % │   67.72 % │ 52.29 % │ 21,40,66,96-98,106,116,119,125-128,162-165,200-... │
├────────────────────────────────────┼──────────┼────────────┼──────────┼───────────┼─────────┼────────────────────────────────────────────────────┤
│ Summary                            │  95.15 % │    63.33 % │  27.66 % │   77.25 % │ 67.36 % │                                                    │
└────────────────────────────────────┴──────────┴────────────┴──────────┴───────────┴─────────┴────────────────────────────────────────────────────┘

Reproduce repository:

Expected behavior

Coverage for *.tsx files

Errors or Screenshots

image

Make a minimal reproduction

Additional context

I've checked https://nextjs.org/docs/messages/improper-devtool, but the result is not changed.

const nextConfig = {
    productionBrowserSourceMaps: true,
    webpack: (config, options) => {

        if (process.env.NODE_V8_COVERAGE) {
            if (!options.dev) {
                config.devtool = options.isServer ? false : 'source-map';
            }
        }

        return config;
    }
};
export default nextConfig;
cenfun commented 2 weeks ago

It seems that the Next.js v15 does not output the source-map file anymore even sets config.devtool='source-map', it always reverting devtool to default eval-source-map, we can see it in the file begin comments

/*
 * ATTENTION: An "eval-source-map" devtool has been used.
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */

Currently, MCR does not support parsing sourcemap from the eval-source-map.

I'll look into how to get sourcemap from eval, not sure if it will work, but it shoud work if you can downgrad from Nextjs v15 to v14.