CLion 2018.2 Help

Capturing Unused JavaScript Code (Coverage)

CLion lets you find unused JavaScript (or TypeScript) code in your client-side applications. When you run an application in the special Code Coverage mode, CLion creates a report showing how much code in every file and folder was used. Thanks to source maps, this report shows coverage for your source files but not for the compiled code that was actually run in the browser.

To run an application in the Code Coverage mode

  1. Create a debug configuration of the type JavaScript Debug:
    Choose Run | Edit Configuration on the main menu, click icons general add on the toolbar and select JavaScript Debug from the pop-up list. In the Run/Debug Configuration: JavaScript Debug dialog that opens, specify the URL address at which the application is running. This URL can be copied from the address bar of your browser as described in Step 2 above.
    JavaScript Debug configuration
    Click OK to save the configuration settings.
  2. Choose the newly created configuration in the Select run/debug configuration drop-down list on the toolbar and click icons general runWithCoverage svg next to the list.
    ws javascript coverage run with coverage
    The URL address specified in the run configuration opens in the browser.
  3. Stop the configuration in CLion by clicking artwork studio icons shell toolbar stop.
    • Wait till the page is loaded if you want to know what code was executed during the page load, and then click artwork studio icons shell toolbar stop.
    • To see the coverage report for some specific features of your app, use these features in the browser and only then stop the configuration.
  4. View the report in the Coverage tool window. The Project tool window shows information about the coverage of files and folders. In the editor, the left gutter shows green markers next to the lines that were executed and red markers next to those that were not.
    ws javescript coverage report with editor
    In the example above, the togglePast method is marked with red because the link that shows the past events was not clicked.
Last modified: 27 June 2018