简体   繁体   English

如何结束 node js 应用程序并杀死终端

[英]How to end the node js app and kill the terminal

I am using the below script in my package.json to start the node js app and perform the test simultaneously.我在 package.json 中使用以下脚本来启动 node js 应用程序并同时执行测试。 To achieve this I used the concept of npm concurrently为了实现这一点,我同时使用了npm concurrently的概念

"scripts": {
    "start": "node server.js",
    "dev": "set NODE_ENV=dev && node server.js",
    "local": "set NODE_ENV=local && node server.js",
    "test": "set NODE_ENV=test && mocha --timeout 10000 --exit --reporter mocha-junit-reporter",
    "mochatest": "concurrently \"set NODE_ENV=local && node server.js\" \"set NODE_ENV=test && mocha --timeout 10000 --exit --reporter mocha-junit-reporter\""

So whenever I want to perform the test I will run the command npm run mochatest which will start my app and perform the test but to terminate the batch job I am using Ctrl + C .因此,每当我想执行测试时,我都会运行命令npm run mochatest ,它将启动我的应用程序并执行测试,但要终止我正在使用的批处理作业Ctrl + C Is there a way to include a command to stop the job after a particular timeout.有没有办法包含在特定超时后停止作业的命令。

My output window:我的输出窗口:

在此处输入图片说明

According to docs you can use --exit to "Force Mocha to quit after tests complete"根据文档,您可以使用--exit来“在测试完成后强制 Mocha 退出”

So mocha --timeout 10000 --reporter mocha-junit-reporter --exit should works.所以mocha --timeout 10000 --reporter mocha-junit-reporter --exit应该可以工作。

I have this line:我有这条线:
cross-env NODE_ENV=testing mocha tests --timeout 4000 --reporter mochawesome --exit
and works fine.并且工作正常。

Edit:编辑:

I've seen you run server and tests.我见过你运行服务器和测试。 Your terminal will not ends because server process is still running.您的终端不会结束,因为服务器进程仍在运行。 You don't need to start your server manually, mocha will start if you use something like:您不需要手动启动服务器,如果您使用以下内容, mocha将启动:

var app = require('...');


it('...', function(done) {
    request(app)
        .get('...')
        .expect(...).then(response => {
            assert.(...)
            done()
        })
})

如果您尝试结束该过程,请使用 CTRL + C。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM