Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
VSCode How do I debug with es6 mocha unit tests and jsx files

I manage to hit my breakpoint, but I have a few problems.

  • The code is in es5 and is impossible to debug
  • It only hits the breakpoint with .js. I need it to hit with .jsx files.
  • Mocha.opts doesn't seem to work at all with this. I have tried adding --compilers jsx:babel-register and renaming from .js to .jsx and the breakpoint just doesn't get hit any more.

Mocha options that seem to stop it working completely:

--require babel-register
--require test/util/dom.js
--require expect
--compilers jsx:babel-register

Launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "request": "launch",
      "name": "Debug Mocha Test",
      "type": "node",
      "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
      "args": [
        "test/**/*.spec.js", //I need to get this working with .jsx files
        "--require", "babel-register"
        ],
      "cwd": "${workspaceRoot}",
      "runtimeExecutable": null,
      "env": { }
    }
  ]
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Turns out that this is a bug with the node debugger. I fixed all of the problems by changing:

"type": "node" to "type": "node2".

Launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "request": "launch",
      "name": "Debug Mocha Test",
      "type": "node2",
      "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
      "args": [
        "test/**/*.spec.jsx",
        "--colors", "--no-timeouts"
        ],
      "cwd": "${workspaceRoot}",
      "runtimeExecutable": null,
      "env": { }
    }
  ]
}

mocha.opts:

--require babel-register
--require test/util/dom.js
--require expect
--compilers jsx:babel-register

Answer taken from weinand.

You also need a .babelrc file in your root app with the "retainLines": true. Here is my .babelrc file for example:

{
    "presets": [
        "es2015",
        "stage-2",
        "react"
    ],
    "plugins": [
        "transform-es2015-modules-umd"
    ],
        "retainLines": true
}

If you get bad option: --inspect=..., try and installing a newer version of node.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda