如何在VScode 中 调试 ts 文件 Unit test

最近在使用VScode 调试 mocha 写的 UT, 遇到一个问题,executor.js文件中require了某个ts写的文件代码,跑ut的时候回报错说无法找到。

解决方式是在参数中加入

"-r",
"ts-node/register"

{
            "type": "node",
            "request": "launch",
            "name": "Mocha Tests",
            "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
            "args": [
                "--compilers",
                "js:${workspaceFolder}/mocha.testCore.compiler.js",
                "-r",
                "ts-node/register",
                "--no-timeouts",
                "--colors",
                "${workspaceFolder}/core/test/procedures/executor.spec.js"
            ],
            "internalConsoleOptions": "openOnSessionStart"
        }

https://medium.com/@benlesh/d...

相关推荐