cenfun / monocart-coverage-reports

A code coverage tool to generate native V8 reports or Istanbul reports.
MIT License
31 stars 5 forks source link

[Question] How to get accurate playwright coverage for a remix app #73

Open spencersteers opened 5 days ago

spencersteers commented 5 days ago

I could use some help getting accurate coverage for a remix app. I'm collecting playwright coverage with a fixture similar to this.

The issue I am having is with functions being marked as having coverage but shouldn't. For example, here is the original source:

// app/routes/test.tsx
import { json } from '@remix-run/node';

export function action() {
  return json({ hello: 'world' });
}

export default function Test() {
  return (
    <div>
      <h1>Test</h1>
    </div>
  );
}

In remix, the action export is server side only and is removed from the client build:

// build/client/assets/test-DMIq5N6p.js
import { j as jsxRuntimeExports } from "./jsx-runtime-B9re1YI9.js";
function Test() {
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", {
    children: /* @__PURE__ */ jsxRuntimeExports.jsx("h1", {
      children: "Test"
    })
  });
}
export {
  Test as default
};
//# sourceMappingURL=test-DMIq5N6p.js.map

The final coverage output includes action even though it is not included in the client build.

image image

I've spent awhile messing with this and would appreciate any help. Server side coverage is working great, just having issues with the client side.

Let me know if there is anything else I can provide — happy to setup a sample app too.

Thanks for all your hard work on monocart ❤️

cenfun commented 5 days ago

It should similar to Next.js. The client side coverage should be collected by playwright. Could you please provide a minimal reproduction repo for your remix issue? so i can reproduce it and debug the issue. Thanks

spencersteers commented 4 days ago

https://github.com/spencersteers/remix-monocart-coverage-example

Thank you so much!

cenfun commented 3 days ago

It seems that Remix will remove all server side code from client bundles see https://remix.run/docs/en/main/guides/gotchas#server-code-in-client-bundles

So there is no coverage info for server side code from client side. The lines are marked as covered by default if no coverage data. For action():

After merged: The action() is marked as covered

I don't know how to fix it, any idea? Or asking help from the official Remix team, if they are willing to support code coverage.

cenfun commented 2 days ago

Please try monocart-coverage-reports@2.10.5 and see if this issue has been fixed.

I also create a example repo for Remix, see https://github.com/cenfun/remix-with-playwright

spencersteers commented 15 hours ago

It's working great! Thank you so much!