eltro/cli.mjs
Jonatan Nilsson be700ab012
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed
cli: Add ability to override default timeout as well as ignore only tests
2022-03-02 14:25:56 +00:00

76 lines
2 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(' -t, --timeout - Specify the timeout for tests in ms.')
console.log(' Default value is 2000ms')
console.log(' --ignore-only - Specify to ignore any .only() tests found')
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
e.ignoreOnly = cli.ignoreOnly
e.__timeout = cli.timeout
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(stats) {
if (stats.failed > 0) {
process.exit(10)
}
process.exit(0)
}, function(err) {
console.error('\x1b[31mInternal error occured:\x1b[0m', err)
process.exit(2)
})