-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(ui): add dark theme to istanbul html reporter #6281
base: main
Are you sure you want to change the base?
feat(ui): add dark theme to istanbul html reporter #6281
Conversation
✅ Deploy Preview for vitest-dev ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Coverage including html folder when running standalone report ( Added The html reporter not being resolved from local (added the reporter subpackage to root tsconfig base with no luck). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making this UI specific, could we jus create a custom coverage reporter that extends Istanbul's html
reporter with theme toggle? And when ever user defines html
reporter, we use that custom built-in one instead?
Html reporter is the custom reporter you are asking for. Vitest will check for html reporter in the configuration to include the reporter from the ui package: check coverage docs (for example, will not work with html-spa reporter). This reporter is only used with Vitest UI or Browser Mode and will work only with the istambul html reporter (both istambul and v8 using this reporter). IIRC Vlad asked in discord about changing the reporter name to web. |
Sorry I'm not sure I'm following here. Istanbul's Why does this need to be Vitest UI specific only?
Sure, we can do that. For the public API we would require users to specify |
Vitest UI will show the coverage link in the UI only when html reporter added to the configuration and This PR is about integrating Istanbul html reporter in Vitest UI: it is out of scope how can we integrate dark theme outside Vitest UI. For example, some users may want to use system theme, others may want dark or light only (with a custom color palette like https://userstyles.world/style/14631/istanbul-lcov-material-theme-darker). Vitest UI using vueuse to switch between dark and light themes, this PR adds the corresponding script to all html pages to access and watch the corresponding local storage theme key and updates the css files to match Vitest UI color palette. Check linked Istanbul issue, there is a PR to add system theme to the html reporter. NOTE: the Vitest UI html reporter also generating standalone output when enabling it via |
@@ -1097,6 +1097,9 @@ export class Vitest { | |||
if (reporter instanceof WebSocketReporter) { | |||
reporter.onFinishedReportCoverage() | |||
} | |||
else if ('onFinishedReportCoverage' in reporter && typeof reporter.onFinishedReportCoverage === 'function') { | |||
await reporter.onFinishedReportCoverage() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we find a better way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to check reporter instanceof HTMLReporter
just like WebSocketReporter
above?
In #5242 (comment), we discussed and we didn't go with onFinishedReportCoverage
at interface Reporter
level for now (though it might change in reporter API rework #6147).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTMLReporter
is defined in @vitest/ui
, not in vitest
, so I don't think we can do that. Maybe we can add a special property 🤷🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding a new type like BuildReporter?
async onFinishedReportCoverage() { | ||
await prepareReportCoverageFolder(this.ctx) | ||
} | ||
|
||
async onFinished() { | ||
const result: HTMLReportData = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic should be moved to onFinishedReportCoverage
since the coverage still not generated:
- running the standalone html reporter script will include ui client in the coverage report
- we should remove the html folder on every run using standalone html reporter, otherwise the ui client from previous run will be included in the coverage report (when included the coverage inside the build)
Running this script from examples/basic
folder:
pnpm vitest --ui --open --coverage.enabled=true --coverage.reporter=html --reporter=html --coverage.reportsDirectory=./html/coverage/
Description
This PR adds custom dark theme css for istambul html reporter modified from this https://userstyles.world/style/14631/istanbul-lcov-material-theme-darker
Check also istanbuljs/istanbuljs#553 (comment)
I need to override the css files when using standalone, rn only works when running Vitest UI (shouldn't work when running
npx serve coverage
)index with dark theme
index with light theme
detail with dark theme
detail with light theme
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.