Every line of code we write today will end up as someone’s legacy code.
Everything that you write is going to disappears some day
RUM Code coverage, chose a 1h timeframe (per day) where 1% traffic run that the test
FES javascript instrimentation visualization
- Instrument JavaScript code – Roman Liutikov – Medium
- Raiders of the Fast Start: Frontend Performance Archaeology - Perform…
Create babel plugin that inject in code with visitors for functions and control flow (loops and switchs): Function
, IfStatement
, (Terminatorless
, SwitchCase
, Loop
, TryStatement
)
- Plugins · Babel
- babel-handbook/plugin-handbook.md at master · jamiebuilds/babel-handbook
- @babel/types · Babel
- babel-plugin-inject/index.js at master · ialpert/babel-plugin-inject - Example of plugin that replace function call
- @babel/helper-module-imports - replace function/property by import via Babel
Or as standalone tool:
Other:
Aka unused CSS RUM
Can't support easily CSSOM changes
Parse + generate result client side (use webworker):
- get CSSOM (for external and inlined stylesheets) from DOM (see step 4)
- download CSS + map
- parse stylesheet to CSSOM: ruleset, selectors, values, etc. (for results from step 1 and 2)
- find which rules/properties has been ignored by the browser (compare results from step 3)
- apply it to a virtual DOM
- apply document updates to the virtual DOM based on
MutationObserver
(for added or removed external and inlined style sheets too, see steps 1, 2 and 3) - apply source map
- generate LCOV report + send to server (
navigator.sendBeacon()
) with generated version (git commit hash)
Server side:
- merge reports https://github.com/mweibel/lcov-result-merger https://gist.github.com/xseignard/5420661
- apply later changes (commits diffs, in that case, the final report should used carefully)
Based on Webdev tools code (Firefox / Chrome):
- https://github.com/mozilla/gecko-dev/blob/master/devtools/client/inspector/rules/rules.js
- https://github.com/mozilla/gecko-dev/blob/master/devtools/client/inspector/rules/views/rule-editor.js
- https://github.com/mozilla/gecko-dev/tree/master/devtools/shared/css
- https://github.com/mozilla/gecko-dev/blob/master/devtools/client/inspector/computed/test/browser_computed_getNodeInfo.js
- https://docs.firefox-dev.tools/getting-started/architecture-overview.html
- https://github.com/ChromeDevTools/devtools-frontend/blob/master/front_end/elements/ComputedStyleModel.js
- https://github.com/ChromeDevTools/devtools-frontend/blob/master/front_end/elements/StylesSidebarPane.js
- 1518615 - (dt-rules) [meta] Convert the Rules view into React/Redux
- Dependency tree for Bug 1540753
An other method to detect ruleset usage is to add a rarely used property with a custom value and get style with void selector (could be enabled and disabled synchronously): voice-family: "my custom value"
(could be also font-family
, content
, quotes
but could add layout impact).
This method could be hard to implement if the stylesheet use attribute selectors (should detect which element or its parent has attribute change and list which attribute changes to "listen")
It could also use a tracker image with some properties (CSS background or content property)) to direct tracking element but generate too much traffic (each document elements and pseudo element call a beacon).
-
leeoniya/dropcss: A simple, thorough and fast unused-CSS cleaner - lib use Fast HTML Parser, CSSTree et css-select
- leeoniya/dropcss: A simple, thorough and fast unused-CSS cleaner
- Dust-Me Selectors – Add-ons for Firefox -
/chrome/content/dustmeselectors.js
:DustMeSelectors.evaluateSelectors
- purifycss/purifycss: Remove unused CSS. Also works with single-page apps.
- uncss/uncss: Remove unused styles from CSS
- Web Essentials: Remove unused CSS - Web Essentials: Remove unused CSS - YouTube - Browser Link - Web Essentials - WebEssentials2015/UnusedCss.js at master · madskristensen/WebEssentials2015
In Intellij IDEA/WebStorm/PHPStorm:
- Finding Unused Code with Coverage - Help | IntelliJ IDEA
- Is there a way to load the lcov data inside webstorm? · Issue #6 · StevenLooman/mocha-lcov-reporter
- Webstorm (intellij) coverage integration with the angular cli · Issue #3560 · angular/angular-cli
- Testing JavaScript - Help | IntelliJ IDEA
In Visual Studio Code:
- VSCode LCOV - Visual Studio Marketplace
- Code Coverage - Visual Studio Marketplace
- Coverage Gutters - Visual Studio Marketplace
- Automatic Unit Testing in .NET Core plus Code Coverage in Visual Studio Code - Scott Hanselman
In Visual Studio:
- Code coverage testing - Visual Studio | Microsoft Docs
- OpenCppCoverage/OpenCppCoverage: OpenCppCoverage is an open source code coverage tool for C++ under Windows.
- Testing a Team Services extension and tracking code coverage – ALM | DevOps Rangers
-
puppeteer/api.md at master · GoogleChrome/puppeteer - Chrome DevTools Protocol Viewer - Profiler
-
DevTools: allow exporting code coverage data. (I0360d0de) · Gerrit Code Review - Chrome devtools can export Coverage data (as JSON)
-
istanbuljs/v8-to-istanbul: convert from v8 coverage format to istanbul's format
-
717195 - Ability to export code coverage results for use by analysis tools - chromium - Monorail
-
Feature Request: LCOV or Istanbul format code coverage · Issue #1768 · GoogleChrome/puppeteer