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

Ability to customize the "assetPrefix" for HTML report. #6357

Closed
4 tasks done
Zizzamia opened this issue Aug 17, 2024 · 5 comments
Closed
4 tasks done

Ability to customize the "assetPrefix" for HTML report. #6357

Zizzamia opened this issue Aug 17, 2024 · 5 comments

Comments

@Zizzamia
Copy link

Zizzamia commented Aug 17, 2024

Clear and concise description of the problem

We are using Vite for https://onchainkit-coverage.vercel.app/, which loads really well when used at the top-level domain.

But as soon as we run the report in its own subfolder, https://onchainkit.xyz/coverage, the HTML report struggles to handle static files and page links.

Suggested solution

I think one feature that could make this super easy is the ability to set assetPrefix. This would be similar to what Next.js has at https://nextjs.org/docs/app/api-reference/next-config-js/assetPrefix.

Ideally, that can be added to the report config

reporter: [
        [
          'html',
          {
            assetPrefix: 'https://onchainkit.xyz/coverage/',
          },
        ],
      ],

Thank you again for building Vitest. We really love writing test with it.

Alternative

No response

Additional context

No response

Validations

@hi-ogawa
Copy link
Contributor

It looks like all assets inside html are relative, so accessing https://onchainkit.xyz/coverage/index.html seems to work already. I think if you tweak a vercel config, then https://onchainkit.xyz/coverage/ would also work too (currently 404).

If you want trailing slash stripped /coverage, then it might need a different approach though.

@Zizzamia
Copy link
Author

@hi-ogawa thank you for the quick reply. So we use the vercel.json rules to organize the coverage page.
Here file: https://github.com/coinbase/onchainkit/blob/main/vercel/vercel.json

Also, knowing https://onchainkit.xyz/coverage/index.html works and sublinks too https://onchainkit.xyz/coverage/src/identity/hooks/index.html, that's very good news. 🗞️

Now I wonder, if I should experiment with vercel.json rules a bit more.

@hi-ogawa
Copy link
Contributor

Btw, Vitest's coverage reporter generation is delegated to istanbuljs (like html reporter here https://github.com/istanbuljs/istanbuljs/blob/main/packages/istanbul-reports/lib/html/index.js), so the feature request needs to go there if this requires fundamental change.

I just found they support custom linkMapper, but playing with it, it looks tricky to achieve what you need (assuming what you want is to serve it without trailing slash https://onchainkit.xyz/coverage). Note that <a href> link is also relative, so implementing "assetPrefix" alone won't solve your issue.

One quick hack I'm thinking is to inject <base> https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base into your root index.html. Something like <base href="/coverage/" /> would allow relative links to resolved correctly even when served in /coverage.

@Zizzamia
Copy link
Author

Zizzamia commented Sep 9, 2024

Feel free to close this issue, I end up using https://onchainkit.xyz/coverage/ with / and do some re-routing magic to have https://onchainkit.xyz/coverage reroute to https://onchainkit.xyz/coverage/

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Sep 9, 2024

Yeah, your setup looks good to me 👍 Okay closing.

@hi-ogawa hi-ogawa closed this as completed Sep 9, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants