在Visual Studio Code中运行用Babel编译的Mocha测试 [英] Running Mocha tests compiled with Babel in Visual Studio Code

查看:63
本文介绍了在Visual Studio Code中运行用Babel编译的Mocha测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mocha测试中使用的是Babel.要在终端中运行测试,请使用以下命令:

I am using Babel in my Mocha tests. To run the test in terminal I use following command:

mocha --debug --compilers js:babel/register

然后,我可以使用VS Code附加"调试选项将其附加到测试过程.我可以设置断点并停止,但是因为原始代码在ES6中,所以VS Code对行号等感到困惑.

Then I can use VS Code "Attach" debugging option to attach to the test process. I can set breakpoints and it stops, but because original code is in ES6 VS Code gets confused about line numbers and such.

无论如何,是否可以使VS Code在此设置下正常工作?

Is there anyway to make VS Code work with this setup?

我的附加"配置:

    {
        "name": "Attach",
        "type": "node",
        // TCP/IP address. Default is "localhost".
        "address": "localhost",
        // Port to attach to.
        "port": 5858,
        "sourceMaps": false
    }

"sourceMaps": true没有任何区别

我要运行测试的项目是开源. GitHub存储库: https://github.com/mohsen1/yawn-yaml/

The project I'm trying to run the test is open source. GitHub repo: https://github.com/mohsen1/yawn-yaml/

推荐答案

我使用以下配置在本地使用babel运行mocha:

I got mocha running with babel locally using this config:

"configurations": [
    {
        "name": "Debug Mocha",
        "type": "node",
        "program": "./node_modules/.bin/_mocha",
        "stopOnEntry": false,
        "args": ["--compilers", "js:babel-register"],
        "cwd": ".",
        "runtimeExecutable": null,
        "runtimeArgs": [
            "--nolazy"
        ],
        "env": {
            "NODE_ENV": "development"
        },
        "externalConsole": false,
        "sourceMaps": true,
        "outDir": null
    },
    {
        "name": "Attach",
        "type": "node",
        "request": "attach",
        "port": 5858
    }
]

使用 _mocha 可执行文件,因为该节点已被Code调用.另外,请确保已将 sourceMaps 设置为 true .

Which uses the _mocha executable since node is already invoked by Code. Also, make sure you have sourceMaps set to true.

这篇关于在Visual Studio Code中运行用Babel编译的Mocha测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆