运行国家防范机制的测试在调试终端在VSCode

0

的问题

我试图建立一个配置在我的启动。json这将运行 npm test 在文件夹 .js 文件驻留。 运行 npm test 手动终端的正常工作,把有关的命令 scripts 部分的我 package.json:

"scripts": {
    "start": "node --experimental-json-modules nodeserver.js",
    "test": "export MY_VAR=abc && node --experimental-json-modules nodeserver.js"
},

特别是,当在运行 npm test 直接在一个终端,env var指定的 test 脚本行生效和 --experimental-json-modules 标志是传递给 node.

这是我的启动。json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "command": "npm test",
            "name": "Run npm test",
            "request": "launch",
            "type": "node-terminal"
        }
    ]
}

这是很多-是从一个预选项中所建议的编辑,并且是非常相似, 这个.

但是,当我运行这种结构上的 nodeserver.js 文件中,我获得:

enter image description here

这似乎是运行 node 没有标志我的指定配置? 我是什么误解关于如何 launch.json 方案工作的?

编辑更我打过周围,更加看来,如果该结构只是被完全被忽略,所以,它使用的是默认的node.js 配置...我选择配置从拉下来按播放的图标:

enter image description here

应该这项工作?

除了运行 npm start 在一个终端,只有"自动"的方式得到这个工作是通过打开的 package.json 并且点击小调试按钮,会出现的 scripts 标签:

enter image description here

但是我想弄清楚如何使用 launch.json 正确因此,我可以通过环境变量等通过,代替。

debugging node.js npm visual-studio-code
2021-11-23 19:08:15
2
0

你可以尝试创建国家防范机制的测试脚本直接在你的发射。json如上:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Run npm test",
        "request": "launch",
        "type": "node",
        "args": ["--experimental-json-modules", "${workspaceFolder}/nodeserver"],
        "env": {
           "MY_VAR": "abc"
        }

    }
]
}
2021-11-29 11:39:31

完全相同的情况与这个 launch.json 太...它好像如果该结构只是被完全被忽略,所以,它使用的是默认的node.js 启动配置。
drmrbrewer
0

启动。json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}\\index.js"
        },
        {
            "type": "pwa-node",
            "request": "launch",
            "name": "Run Test",
            "skipFiles": 
            [
                "<node_internals>/**"
            ],

            // You can specify enviorment variables per config here
            // using key value pairs
            "env": 
            {
                "test_variable": "test value"
            },

            // You can also specify a .env file that contains them
            "envFile": "${workspaceFolder}/.env",

            // Here you specify the file you want launched
            "program": "${workspaceFolder}\\test.js",

            // add args to nodejs here
            "runtimeArgs": 
            [
                "--experimental-json-modules"
            ],
        }
    ]
}

供参考: https://code.visualstudio.com/docs/nodejs/nodejs-debugging

2021-12-02 10:34:50

完全相同的情况与这个 launch.json 太...它好像如果配置(包括 --experimental-json-modules arg)只是被完全被忽略,所以,它使用的是默认的node.js 启动结构,没有任何args. 也许我只是启动这个错误...你是怎么做? 我这样做是在原岗位。
drmrbrewer

@drmrbrewer我选择的个人资料,然后按F5。 我只是给了那个开关一个试验和它的工作。 i.imgur.com/CiRXX6X.png
John

是的. F5是相当于我在做什么...按下"玩"按钮旁边的配置文件的名字...我仍然得到同样的错误和运行参数规定都是完全被忽视...不知道怎么回事。
drmrbrewer

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................