From 2792cb1b0a6a104b0f0c1e4c77e9b46ae2ef9b10 Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 24 Jan 2024 14:55:41 +0800 Subject: [PATCH] fix: e2e test did not exit successfully (#3427) * fix: e2e test did not exit successfully * fix: tree kill --------- Co-authored-by: dream2023 <1098626505@qq.com> --- package.json | 1 + packages/core/cli/src/commands/e2e.js | 16 ++++++++++++++++ yarn.lock | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 546b0c1f8..5d571da2b 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "pretty-quick": "^3.1.0", "react": "^18.0.0", "react-dom": "^18.0.0", + "tree-kill": "^1.2.2", "typescript": "5.1.3" }, "volta": { diff --git a/packages/core/cli/src/commands/e2e.js b/packages/core/cli/src/commands/e2e.js index ee702a446..06127a317 100644 --- a/packages/core/cli/src/commands/e2e.js +++ b/packages/core/cli/src/commands/e2e.js @@ -4,6 +4,7 @@ const { execSync } = require('node:child_process'); const axios = require('axios'); const { pTest } = require('./p-test'); const os = require('os'); +const treeKill = require('tree-kill'); /** * 检查服务是否启动成功 @@ -91,6 +92,17 @@ async function runApp(options = {}) { run('nocobase', [process.env.APP_ENV === 'production' ? 'start' : 'dev'], options); } +process.on('SIGINT', async () => { + treeKill(process.pid, (error) => { + if (error) { + console.error(error); + } else { + console.log('所有子进程已被杀掉,应用程序即将退出'); + } + process.exit(); + }); +}); + const commonConfig = { stdio: 'inherit', }; @@ -150,6 +162,10 @@ module.exports = (cli) => { console.log('APP_BASE_URL:', process.env.APP_BASE_URL); } }); + process.on('SIGINT', () => { + console.log('SIGINT......'); + }); + e2e .command('test') .allowUnknownOption() diff --git a/yarn.lock b/yarn.lock index f6ac61e71..01a558f2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -24424,7 +24424,7 @@ transformation-matrix@^2.11.1: tree-kill@^1.2.2: version "1.2.2" - resolved "https://registry.npmmirror.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc" + resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc" integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A== trim-lines@^3.0.0: