eltro/cli.mjs
Jonatan Nilsson 3bd8d4ba51 Make eltro slightly more robust
Make the printError slightly more robust as well as well as make it print better when obscure errors occur when programmers fiddle with the internal mechanics of node, for example the Error.prepareStack among other things.
2021-06-02 21:28:51 +00:00

68 lines
1.7 KiB
JavaScript

#!/usr/bin/env node
// Get arguments
const [,, ...args] = process.argv
import e from './lib/eltro.mjs'
import { CLI, printError } from './lib/cli.mjs'
e.begin()
const cli = new CLI(e)
cli.parseOptions(args)
if (cli.errored) {
PrintHelp()
}
function PrintHelp() {
console.log('')
console.log('Usage: eltro <options> <files>')
console.log('')
console.log('where <files> can either be a single file or a simple glob pattern.')
console.log('where <options> can be any of the following:')
console.log(' -r, --reporter - Specify the reporter to use.')
console.log(' Supported reporters: list, dot')
console.log('')
console.log('eltro test/mytest.mjs')
console.log('eltro dot test/*.mjs')
console.log('eltro -r dot test/**/*.test.mjs')
console.log('')
process.exit(1)
}
cli.processTargets().then(function() {
if (!cli.files.length) {
console.log('')
console.log('No files were found with pattern', cli.targets.join(','))
PrintHelp()
}
return cli.loadFiles()
.then(function() {
e.reporter = cli.reporter
return e.run()
.catch(function(err) {
console.log('')
console.error('\x1b[31mUnknown error occured while running the tests\x1b[0m')
printError(err)
process.exit(1)
})
}, function(err) {
console.log('')
console.error('\x1b[31m' + err.message + '\x1b[0m')
printError(err.inner)
process.exit(1)
})
}, function(err) {
console.log('')
console.error('\x1b[31mUnknown error while processing arguments\x1b[0m')
printError(err)
process.exit(1)
})
.then(function() {
process.exit(0)
}, function(err) {
console.error('\x1b[31mInternal error occured:\x1b[0m', err)
process.exit(2)
})