Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgo committed Oct 28, 2020
1 parent 561a90c commit bebebee
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/test.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import { strict as assert } from "assert";
import childProcess from "child_process";
import { test } from "mocha";
import psTree from "ps-tree";
import util from "util";
import { strict as assert } from "assert"
import childProcess from "child_process"
import { test } from "mocha"
import psTree from "ps-tree"
import util from "util"

import { endChildProcesses } from "./index";
const psTreeA = util.promisify(psTree);
import { endChildProcesses } from "./index"
const psTreeA = util.promisify(psTree)

test("end-child-processes", async function () {
// start some child processes
childProcess.exec(blockingCommand());
let count = await runningProcessCount();
assert.equal(count, 2, "should have 2 child processes");
childProcess.exec(blockingCommand())
let count = await runningProcessCount()
assert.equal(count, 2, "should have 2 child processes")

// stop the child processes
await endChildProcesses();
count = await runningProcessCount();
assert.equal(count, 0, "should have 0 child processes now");
});
await endChildProcesses()
count = await runningProcessCount()
assert.equal(count, 0, "should have 0 child processes now")
})

/**
* Returns a command that runs on the current platform and blocks
*/
function blockingCommand() {
if (process.platform === "win32") {
return "cmd /c pause";
return "cmd /c pause"
} else {
return "(read foo)";
return "(read foo)"
}
}

async function runningProcessCount() {
const children = await psTreeA(process.pid);
return children.length - 1;
const children = await psTreeA(process.pid)
return children.length - 1
}

0 comments on commit bebebee

Please sign in to comment.