/ libs / typescript / jest.global-server-teardown.ts
jest.global-server-teardown.ts
 1  import { rmSync } from 'fs';
 2  import { ChildProcess } from 'child_process';
 3  
 4  module.exports = async () => {
 5    const globals = globalThis as any;
 6    const mlflowProcess = globals.mlflowProcess as ChildProcess;
 7    const tempDir = globals.tempDir as string;
 8  
 9    if (mlflowProcess) {
10      // Kill the process group to ensure worker processes spawned by uvicorn are terminated
11      process.kill(-mlflowProcess.pid!, 'SIGTERM');
12  
13      // Wait for 1 second to ensure the process is terminated
14      await new Promise((resolve) => setTimeout(resolve, 1000));
15    }
16    if (tempDir) {
17      rmSync(tempDir, { recursive: true, force: true });
18    }
19  };