Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): setup coverage (client) #62

Merged
merged 5 commits into from
Apr 24, 2022
Merged

Conversation

hi-ogawa
Copy link
Owner

@hi-ogawa hi-ogawa commented Apr 24, 2022

todo

  • try sourcemap: "inline" in client config (via patch-package)
  • refactor coverage helper

@hi-ogawa hi-ogawa mentioned this pull request Apr 24, 2022
5 tasks
@hi-ogawa
Copy link
Owner Author

hi-ogawa commented Apr 24, 2022

playwright and c8 don't work together out-of-box since chrome's coverage output json is:

example.json
    {
      "scriptId": "5",
      "url": "http://localhost:3001/build/_shared/chunk-M5F7E5FR.js",
      "functions": [
        {
          "functionName": "",
          "ranges": [
            {
              "startOffset": 0,
              "endOffset": 6229,
              "count": 1
            }
          ],
          "isBlockCoverage": true
        },
        {
          "functionName": "useModal",
          "ranges": [
            {
              "startOffset": 286,
              "endOffset": 441,
              "count": 0
            }
          ],
          "isBlockCoverage": false
        },
        {
          "functionName": "ModalProvider",
          "ranges": [
            {
              "startOffset": 462,
              "endOffset": 1867,
              "count": 3
            }
          ],
          "isBlockCoverage": true
        },
        {
          "functionName": "openModal",
          "ranges": [
            {
              "startOffset": 588,
              "endOffset": 670,
              "count": 0
            }
          ],
          "isBlockCoverage": false
        },
        {
          "functionName": "closeModal",
          "ranges": [
            {
              "startOffset": 673,
              "endOffset": 725,
              "count": 0
            }
          ],
          "isBlockCoverage": false
        },
        {
          "functionName": "closeModalFinal",
          "ranges": [
            {
              "startOffset": 728,
              "endOffset": 808,
              "count": 0
            }
          ],
          "isBlockCoverage": false
        }
      ],
      "source": "import {\n  Qe\n} from \"/build/_shared/chunk-HW665I5A.js\";\nimport {\n  __toESM,\n  init_react,\n  require_react\n} from \"/build/_shared/chunk-EKQW2SDC.js\";\n\n// app/components/modal.tsx\ninit_react();\nvar React = __toESM(require_react());\nvar DefaultModalContext = React.createContext(void 0);\nfunction useModal() {\n  const value = React.useContext(DefaultModalContext);\n  if (!value)\n    throw new Error(\"ModalContext undefined\");\n  return value;\n}\nvar ModalProvider = ({ children }) => {\n  const [content, setContent] = React.useState();\n  const [state, setState] = React.useState(\"CLOSED\");\n  function openModal(content2) {\n    setContent(content2);\n    setState(\"OPEN\");\n  }\n  function closeModal() {\n    setState(\"CLOSING\");\n  }\n  function closeModalFinal() {\n    setContent(void 0);\n    setState(\"CLOSED\");\n  }\n  return /* @__PURE__ */ React.createElement(DefaultModalContext.Provider, {\n    value: { openModal, closeModal }\n  }, children, /* @__PURE__ */ React.createElement(Qe, {\n    appear: true,\n    show: state === \"OPEN\"\n  }, /* @__PURE__ */ React.createElement(\"div\", {\n    className: \"absolute inset-0 z-50 flex justify-center items-center\"\n  }, /* @__PURE__ */ React.createElement(Qe.Child, {\n    className: \"transition duration-300 absolute inset-0 z-[-1]\",\n    enterFrom: \"opacity-0\",\n    enterTo: \"opacity-100\",\n    leaveFrom: \"opacity-100\",\n    leaveTo: \"opacity-0\"\n  }, /* @__PURE__ */ React.createElement(\"div\", {\n    className: \"absolute inset-0 bg-black/[0.3]\",\n    onClick: closeModal\n  })), /* @__PURE__ */ React.createElement(Qe.Child, {\n    className: \"w-full max-w-xl\",\n    enter: \"transition duration-300\",\n    enterFrom: \"opacity-0 scale-95\",\n    enterTo: \"opacity-100 scale-100\",\n    leave: \"transition duration-300\",\n    leaveFrom: \"opacity-100 scale-100\",\n    leaveTo: \"opacity-0 scale-95\",\n    afterLeave: closeModalFinal\n  }, content))));\n};\n\nexport {\n  useModal,\n  ModalProvider\n};\n//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vLi4vLi4vLi4vLi4vYXBwL2NvbXBvbmVudHMvbW9kYWwudHN4Il0sCiAgInNvdXJjZXNDb250ZW50IjogWyJpbXBvcnQgeyBUcmFuc2l0aW9uIH0gZnJ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O0FBQ3BDLFFBQU0sQ0FBQyxPQUFPLFlBQVksQUFBTSxlQUFxQjtBQUVyRCxxQkFBbUIsVUFBMEI7QUFDM0MsZUFBVztBQUNYLGFBQVM7QUFBQTtBQUdYLHdCQUFzQjtBQUNwQixhQUFTO0FBQUE7QUFHWCw2QkFBMkI7QUFDekIsZUFBVztBQUNYLGFBQVM7QUFBQTtBQUdYLFNBQ0Usb0NBQUMsb0JBQW9CLFVBQXJCO0FBQUEsSUFBOEIsT0FBTyxFQUFFLFdBQVc7QUFBQSxLQUMvQyxVQUNELG9DQUFDLElBQUQ7QUFBQSxJQUFZLFFBQU07QUFBQSxJQUFDLE1BQU0sVUFBVTtBQUFBLEtBQ2pDLG9DQUFDLE9BQUQ7QUFBQSxJQUFLLFdBQVU7QUFBQSxLQUNiLG9DQUFDLEdBQVcsT0FBWjtBQUFBLElBQ0UsV0FBVTtBQUFBLElBQ1YsV0FBVTtBQUFBLElBQ1YsU0FBUTtBQUFBLElBQ1IsV0FBVTtBQUFBLElBQ1YsU0FBUTtBQUFBLEtBRVIsb0NBQUMsT0FBRDtBQUFBLElBQ0UsV0FBVTtBQUFBLElBQ1YsU0FBUztBQUFBLE9BR2Isb0NBQUMsR0FBVyxPQUFaO0FBQUEsSUFDRSxXQUFVO0FBQUEsSUFDVixPQUFNO0FBQUEsSUFDTixXQUFVO0FBQUEsSUFDVixTQUFRO0FBQUEsSUFDUixPQUFNO0FBQUEsSUFDTixXQUFVO0FBQUEsSUFDVixTQUFRO0FBQUEsSUFDUixZQUFZO0FBQUEsS0FFWDtBQUFBOyIsCiAgIm5hbWVzIjogW10KfQo=\n"
    },
...

But, probably it would work fine if we preprocess this json file to replace "url" to be the local path in stead of localhost url.
For example, remix's client output is always under http://localshot:3001/build/..., so it would be easy to transform.

references

@hi-ogawa hi-ogawa marked this pull request as draft April 24, 2022 08:28
@hi-ogawa
Copy link
Owner Author

After a few hacks, this seems to work already:

E2E_COVERAGE=1 npm run test-e2e app/__e2e__/basic.test.ts
npx c8 report -r text -r html --all --src app --exclude build --exclude packages --exclude-after-remap --temp-directory coverage/tmp-client

@hi-ogawa hi-ogawa changed the title test(e2e): add "testCoverage" helper test(e2e): setup coverage (client) Apr 24, 2022
@hi-ogawa hi-ogawa marked this pull request as ready for review April 24, 2022 09:10
@hi-ogawa
Copy link
Owner Author

will work on merging all coverage information in the separate PR

@hi-ogawa hi-ogawa merged commit be44caa into master Apr 24, 2022
@hi-ogawa hi-ogawa deleted the test-setup-coverage-e2e-client branch April 24, 2022 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant