Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Mocha Test Debug HelperNew to Visual Studio Code? Get it now.
Mocha Test Debug Helper

Mocha Test Debug Helper

narukami-dev

|
11 installs
| (0) | Free
Debug mocha-style tests by toggling debug markers and auto commenting/uncommenting code on save.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Mocha Test Debug Helper

VS Code extension to debug Mocha-style tests by toggling marker lines and auto commenting/uncommenting lines on save.

Main behavior

Keyboard toggle (Ctrl+Shift+D)

Inside .ts/.js editor:

  1. first press -> insert //@debug
  2. second press on that line -> replace with //@undebug
  3. third press on that line -> delete marker line

If current line is not empty, marker is inserted above that line with matching indentation.

Save processing

On save, extension validates marker count:

  • multiple //@debug -> error popup
  • multiple //@undebug -> error popup
  • both markers in same file -> error popup

If valid:

  • //@debug -> add one // prefix to eligible lines before marker
  • //@undebug -> remove one // prefix from eligible lines before marker

Processing is limited to the nearest protected callback body around the marker. Call/header lines and closing lines are protected.

Focused file script runner (runs on save by default)

When a focused file is saved (Cmd+S on macOS / Ctrl+S on Windows/Linux), extension can run a configured script against that file. You can also run it manually with command Mocha Debug Helper: Run Script for Focused File (default Ctrl+Shift+R).

  • extension appends the focused file absolute path as the last argument
  • if the script exits with error, extension shows popup and logs details in output channel Mocha Debug Helper

Configurable settings

Use settings.json:

{
  "narukami-dev.mochaTestDebugHelper.protectedFunctions": [
    "describe",
    "before",
    "beforeEach",
    "test",
    "it",
    "after",
    "afterEach",
    "step"
  ],
  "narukami-dev.mochaTestDebugHelper.functionAllowlist": [
    "findElementByText"
  ],
  "narukami-dev.mochaTestDebugHelper.scriptRunner.command": "node ./scripts/process-file.js",
  "narukami-dev.mochaTestDebugHelper.scriptRunner.runOnSave": true,
  "narukami-dev.mochaTestDebugHelper.scriptRunner.runOnSaveExtensions": [".ts", ".js"]
}

Notes:

  • narukami-dev.mochaTestDebugHelper.scriptRunner.command
    • base script command to execute; extension appends focused file path as last argument
  • narukami-dev.mochaTestDebugHelper.scriptRunner.runOnSave
    • when true, script runner is triggered from normal file save
  • narukami-dev.mochaTestDebugHelper.scriptRunner.runOnSaveExtensions
    • optional extension filter for save-triggered script run
    • supports values like .ts, ts, .js, js; empty means all files
  • narukami-dev.mochaTestDebugHelper.protectedFunctions
    • overrides protected callback names used for scope + header/closure protection
  • narukami-dev.mochaTestDebugHelper.functionAllowlist
    • affects variable declarations with function-call initializers
    • variable declaration rules:
      • non-function-call initializers are protected
      • function-call initializers are commentable by default
      • if called function name is in allowlist, declaration stays protected
      • function names are resolved from:
        • direct call: findElementByText(...)
        • static/member call: SomeClass.findElementByText(...)
        • instance call: wowClass.findElementByText(...)

Example for function allowlist

With functionAllowlist: ["findElementByText"] and //@debug below:

const number = 0;
const element = await findElementByText("Hello");
const element2 = await SomeClass.findElementByText("Hello");

const wowClass = new SomeClass();
const element3 = await wowClass.findElementByText("Hello");
//@debug

after save:

const number = 0;
const element = await findElementByText("Hello");
const element2 = await SomeClass.findElementByText("Hello");

const wowClass = new SomeClass();
const element3 = await wowClass.findElementByText("Hello");
//@debug

Development

npm install
npm run compile
npm test
npx vsce package

Requirements

  • VS Code ^1.85.0

License

MIT

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft