无法从VS Code调试器运行摩卡测试

时间:2019-05-15 22:01:36

标签: visual-studio-code mocha vscode-debugger

我可以使用package.json中的以下脚本从cli运行mocha测试

  

“ test”:“跨环境NODE_ENV = test mocha --require @ babel / register --require mocha-snapshots”

但是当我尝试从VS Code调试器运行时,出现此错误

    PS> cd 'c:\Users\d841616\Documents\Dev\TenantGraphQLServer'; ${env:NODE_ENV}='test'; & 'C:\Program Files\nodejs\node.exe' '--inspect-brk=3767' 'node_modules\mocha\bin\mocha' '--colors' '--require @babel/register' '--require mocha-snapshots' 'C:\Users\d841616\Documents\Dev\TenantGraphQLServer/test'
Debugger listening on ws://127.0.0.1:3767/075bcce8-f56f-4af8-91ec-1ad65607378d
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
C:\Users\d841616\Documents\Dev\TenantGraphQLServer\test\api.js:252
export default api;
^^^^^^

SyntaxError: Unexpected token export
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at C:\Users\d841616\Documents\Dev\TenantGraphQLServer\node_modules\mocha\lib\mocha.js:327:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (C:\Users\d841616\Documents\Dev\TenantGraphQLServer\node_modules\mocha\lib\mocha.js:324:14)
    at Mocha.run (C:\Users\d841616\Documents\Dev\TenantGraphQLServer\node_modules\mocha\lib\mocha.js:801:10)
    at Object.exports.singleRun (C:\Users\d841616\Documents\Dev\TenantGraphQLServer\node_modules\mocha\lib\cli\run-helpers.js:207:16)
    at exports.runMocha (C:\Users\d841616\Documents\Dev\TenantGraphQLServer\node_modules\mocha\lib\cli\run-helpers.js:300:13)
    at Object.exports.handler.argv [as handler] (C:\Users\d841616\Documents\Dev\TenantGraphQLServer\node_modules\mocha\lib\cli\run.js:296:3)
    at Object.runCommand (C:\Users\d841616\Documents\Dev\TenantGraphQLServer\node_modules\yargs\lib\command.js:238:44)
    at Object.parseArgs [as _parseArgs] (C:\Users\d841616\Documents\Dev\TenantGraphQLServer\node_modules\yargs\yargs.js:1089:24)
    at Object.parse (C:\Users\d841616\Documents\Dev\TenantGraphQLServer\node_modules\yargs\yargs.js:566:25)
    at Object.exports.main (C:\Users\d841616\Documents\Dev\TenantGraphQLServer\node_modules\mocha\lib\cli\cli.js:62:6)
    at Object.<anonymous> (C:\Users\d841616\Documents\Dev\TenantGraphQLServer\node_modules\mocha\bin\_mocha:10:23)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3
Waiting for the debugger to disconnect...

这是我正在使用的调试器启动命令

    {
      "type": "node",
      "request": "launch",
      "name": "Mocha All",
      "program": "${workspaceFolder}/node_modules/mocha/bin/mocha",
      "args": ["--colors", "--require @babel/register", "--require mocha-snapshots", "${workspaceFolder}/test"],
      "console": "integratedTerminal",
      "env": {"NODE_ENV": "test"},
      "internalConsoleOptions": "neverOpen"
    },

我有一个.babelrc

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "current"
        }
      }
    ]
  ],
  "sourceMaps": "inline",
  "retainLines": true
}

0 个答案:

没有答案