Fix bug in kill and add basic test. Improve error handling on import errors.
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
This commit is contained in:
parent
a70d64e624
commit
8fad1b45b1
8 changed files with 40 additions and 9 deletions
11
cli.mjs
11
cli.mjs
|
@ -27,15 +27,20 @@ function PrintHelp() {
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
function showErrorAndExit(message = '', err = null, code = 1) {
|
function showErrorAndExit(message = '', err = null, code = 1, clean = false) {
|
||||||
console.log('')
|
if (!clean) {
|
||||||
|
console.log('')
|
||||||
|
}
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
console.error(`\x1b[31m${message}\x1b[0m`)
|
console.error(`\x1b[31m${message}\x1b[0m`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
printError(err)
|
printError(err, '', clean)
|
||||||
|
if (err.inner) {
|
||||||
|
return showErrorAndExit(null, err.inner, code, true)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
PrintHelp()
|
PrintHelp()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 || ''
|
let before = msg || ''
|
||||||
console.error('')
|
if (!clean) console.error('')
|
||||||
console.error('\x1b[31m '
|
console.error('\x1b[31m '
|
||||||
+ before + err.toString()
|
+ before + err.toString()
|
||||||
+ '\x1b[0m\n \x1b[90m'
|
+ '\x1b[0m\n \x1b[90m'
|
||||||
|
|
|
@ -35,7 +35,7 @@ export default function kill(pid, signal) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildTree(allPids, spawnGetChildren, parentPid) {
|
function buildTree(allPids, spawnGetChildren, parentPid) {
|
||||||
allPids.set(parentPid)
|
allPids.add(parentPid)
|
||||||
|
|
||||||
let ps = spawnGetChildren(parentPid)
|
let ps = spawnGetChildren(parentPid)
|
||||||
let data = ''
|
let data = ''
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "eltro",
|
"name": "eltro",
|
||||||
"version": "1.4.3",
|
"version": "1.4.4",
|
||||||
"description": "Eltro is a tiny no-dependancy test framework for node",
|
"description": "Eltro is a tiny no-dependancy test framework for node",
|
||||||
"main": "index.mjs",
|
"main": "index.mjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
25
test/kill/kill.test.mjs
Normal file
25
test/kill/kill.test.mjs
Normal 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
1
test/kill/runner.mjs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
setInterval(function() {}, 1000)
|
|
@ -28,7 +28,7 @@ t.afterEach(function(done) {
|
||||||
|
|
||||||
t.after(function() {
|
t.after(function() {
|
||||||
if (builder) {
|
if (builder) {
|
||||||
builder.cleanup()
|
return builder.cleanup()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ Builder.prototype.newRandomFiles = function(fpath, count) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Builder.prototype.cleanup = function() {
|
Builder.prototype.cleanup = function() {
|
||||||
return fs.rmdir(this.root)
|
return fs.rm(this.root, { recursive: true, force: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
Builder.prototype.getAllDirectories = function() {
|
Builder.prototype.getAllDirectories = function() {
|
||||||
|
|
Loading…
Reference in a new issue