diff --git a/cli.mjs b/cli.mjs index 174b2ae..db846d5 100644 --- a/cli.mjs +++ b/cli.mjs @@ -27,15 +27,20 @@ function PrintHelp() { process.exit(1) } -function showErrorAndExit(message = '', err = null, code = 1) { - console.log('') +function showErrorAndExit(message = '', err = null, code = 1, clean = false) { + if (!clean) { + console.log('') + } if (message) { console.error(`\x1b[31m${message}\x1b[0m`) } if (err) { - printError(err) + printError(err, '', clean) + if (err.inner) { + return showErrorAndExit(null, err.inner, code, true) + } } else { PrintHelp() } diff --git a/lib/cli.mjs b/lib/cli.mjs index 98cd88f..f1e63d4 100644 --- a/lib/cli.mjs +++ b/lib/cli.mjs @@ -440,9 +440,9 @@ export function getFilesFromTarget(files, match, insidePath, grabAll, insideStar }) } -export function printError(err, msg) { +export function printError(err, msg, clean = false) { let before = msg || '' - console.error('') + if (!clean) console.error('') console.error('\x1b[31m ' + before + err.toString() + '\x1b[0m\n \x1b[90m' diff --git a/lib/kill.mjs b/lib/kill.mjs index e976ffd..b91e6fe 100644 --- a/lib/kill.mjs +++ b/lib/kill.mjs @@ -35,7 +35,7 @@ export default function kill(pid, signal) { } function buildTree(allPids, spawnGetChildren, parentPid) { - allPids.set(parentPid) + allPids.add(parentPid) let ps = spawnGetChildren(parentPid) let data = '' diff --git a/package.json b/package.json index 6f3985a..3e097fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eltro", - "version": "1.4.3", + "version": "1.4.4", "description": "Eltro is a tiny no-dependancy test framework for node", "main": "index.mjs", "scripts": { diff --git a/test/kill/kill.test.mjs b/test/kill/kill.test.mjs new file mode 100644 index 0000000..9a967f0 --- /dev/null +++ b/test/kill/kill.test.mjs @@ -0,0 +1,25 @@ +import { fork } from 'child_process' +import t from '../../lib/eltro.mjs' +import assert from '../../lib/assert.mjs' +import kill from '../../lib/kill.mjs' + +t.describe('kill', function() { + let worker + + t.afterEach(function() { + if (worker?.pid && !worker.killed) { + worker.kill() + } + }) + + t.test('should kill process correctly', function(done) { + worker = fork('./test/') + assert.ok(worker.pid) + + worker.on('exit', done.finish(function(code, signal) { + assert.ok(code || signal) + })) + + kill(worker.pid) + }) +}) diff --git a/test/kill/runner.mjs b/test/kill/runner.mjs new file mode 100644 index 0000000..2d16889 --- /dev/null +++ b/test/kill/runner.mjs @@ -0,0 +1 @@ +setInterval(function() {}, 1000) \ No newline at end of file diff --git a/test/watch.test.mjs b/test/watch.test.mjs index 7ec0070..649ca88 100644 --- a/test/watch.test.mjs +++ b/test/watch.test.mjs @@ -28,7 +28,7 @@ t.afterEach(function(done) { t.after(function() { if (builder) { - builder.cleanup() + return builder.cleanup() } }) diff --git a/test/watch/builder.mjs b/test/watch/builder.mjs index 2495acd..27475a1 100644 --- a/test/watch/builder.mjs +++ b/test/watch/builder.mjs @@ -173,7 +173,7 @@ Builder.prototype.newRandomFiles = function(fpath, count) { } Builder.prototype.cleanup = function() { - return fs.rmdir(this.root) + return fs.rm(this.root, { recursive: true, force: true }) } Builder.prototype.getAllDirectories = function() {