如何在VScode 中 除錯 ts 檔案 Unit test

拔蘿蔔的兔子發表於2019-02-16

最近在使用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…

相關文章