Search code examples
code-coverageintern

Is there a way to get JUnit code coverage when running in the browser?


We are currently working on getting better code coverage for one of our JS libraries. I have the The Intern up and running, and can run tests in the browser. However, our libraries create DOM elements in some of their functions, making it so we can't run JUnit from the terminal because Node.js doesn't allow for DOM construction in tests. Is there a way we can get JUnit code coverage on the html and console output we get when we run The Intern in the browser?


Solution

  • I found the answer. From this link: https://theintern.github.io/intern/#local-selenium

    Using ChromeDriver (Chrome-only)
    If you’re just looking to have a local environment for developing functional tests, a stand-alone ChromeDriver installation works great.
    
    1. Download the latest version of ChromeDriver
    2. Set tunnel to 'NullTunnel'
    3. Run chromedriver --port=4444 --url-base=wd/hub
    4. Set your environments capabilities to [ { browserName: 'chrome' } ]
    5. Run the test runner
    

    Once you have that setup and running, you can run

    node_modules/intern/bin/intern-runner.js  config=tests/intern reporters=JUnit filename=junit.xml
    

    This will allow the tests to run in a chrome instance, and then output the results to a report that can then be upload somewhere.