Debugging javascript running in Chrome using VSCode

Installation steps:

  • Install mocha NPM module
  •         npm install
            npm install mocha chai --save-dev
            sudo npm install -g mocha
          
  • Install Debugger for Chrome plugin in VSCode
  • Copy the node_modules/mocha folder to your public (or public/lib) folder
  • Copy the node_modules/chai folder to your public (or public/lib) folder
  • Include mocha in the page you want to debug
  •         <html>
              <head>
                <link rel="stylesheet" href="lib/mocha/mocha.css">
              </head>
              <body>
                <script src="lib/mocha/mocha.js"></script>
                <script src="lib/chai/chai.js"></script>
                <script>mocha.setup('bdd')</script>
                <div id="mocha">
                </div>
                <script>
                  mocha.run();
                </script>
              </body>
            </html>
          

You can use chai to run unit tests in NodeJS application by including chai and using mocha to run tests

    # Include this in the script you need to debug
    var chai = require('chai')
  

References: