Fix bug in kill and add basic test. Improve error handling on import errors.
continuous-integration/appveyor/branch AppVeyor build succeeded Details

master v1.4.4
TheThing 2023-10-31 13:25:08 +00:00
parent a70d64e624
commit 8fad1b45b1
8 changed files with 40 additions and 9 deletions

11
cli.mjs
View File

@ -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()
}

View File

@ -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'

View File

@ -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 = ''

View File

@ -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": {

25
test/kill/kill.test.mjs Normal file
View File

@ -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)
})
})

1
test/kill/runner.mjs Normal file
View File

@ -0,0 +1 @@
setInterval(function() {}, 1000)

View File

@ -28,7 +28,7 @@ t.afterEach(function(done) {
t.after(function() {
if (builder) {
builder.cleanup()
return builder.cleanup()
}
})

View File

@ -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() {