diff --git a/package-lock.json b/package-lock.json index 4cd2e88..a316c3e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "@types/jest": "^29.5.5", "jest": "^29.7.0", "prettier": "^3.0.3", + "tree-kill": "^1.2.2", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", "typescript": "^5.2.2" @@ -3566,6 +3567,15 @@ "node": ">=8.0" } }, + "node_modules/tree-kill": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", + "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==", + "dev": true, + "bin": { + "tree-kill": "cli.js" + } + }, "node_modules/ts-jest": { "version": "29.1.1", "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.1.tgz", diff --git a/package.json b/package.json index 10efaae..5bd17c6 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "@types/jest": "^29.5.5", "jest": "^29.7.0", "prettier": "^3.0.3", + "tree-kill": "^1.2.2", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", "typescript": "^5.2.2" @@ -14,5 +15,6 @@ "scripts": { "build": "tsc", "test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --verbose" - } + }, + "prettier": {} } diff --git a/test/integration.test.ts b/test/integration.test.ts index 451f9ef..4d1e959 100644 --- a/test/integration.test.ts +++ b/test/integration.test.ts @@ -35,10 +35,5 @@ describe("integration tests", () => { } finally { expect(gateway.stop()).toBeTruthy(); } - - // @ts-ignore - console.log(process._getActiveHandles()); - // @ts-ignore - console.log(process._getActiveRequests()); }); }); diff --git a/test/utils.ts b/test/utils.ts index cc040d8..66d10e7 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -17,6 +17,8 @@ import { relative } from "path"; import { execFile, ChildProcess } from "child_process"; +import treeKill from "tree-kill"; + import { CONFIG_PATH, readConfig } from "./config"; export async function execute( @@ -41,10 +43,11 @@ export async function fluence(...args: string[]): Promise<[string, string]> { export class Gateway { constructor( private readonly gateway: ChildProcess, - private readonly port: number + private readonly port: number, ) {} - public stop(): boolean { + public async stop(): Promise { + console.log(this.gateway.pid); if (this.gateway.stdin) { this.gateway.stdin.end(); } @@ -55,7 +58,16 @@ export class Gateway { this.gateway.stderr.destroy(); } if (this.gateway.pid) { - process.kill(this.gateway.pid); + const pid = this.gateway.pid; + await new Promise((resolve, reject) => + treeKill(pid, (err) => { + if (err) { + reject(err); + } else { + resolve(); + } + }), + ); } return this.gateway.kill(); }