2020-03-31 17:27:36 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
// Get arguments
|
|
|
|
const [,, ...args] = process.argv
|
|
|
|
|
2020-04-01 15:35:33 +00:00
|
|
|
import e from './lib/eltro.mjs'
|
2020-03-31 17:27:36 +00:00
|
|
|
import { CLI, printError } from './lib/cli.mjs'
|
|
|
|
|
2020-04-01 15:35:33 +00:00
|
|
|
e.begin()
|
2020-03-31 17:27:36 +00:00
|
|
|
|
2020-04-01 15:42:14 +00:00
|
|
|
const cli = new CLI(e)
|
2020-03-31 17:27:36 +00:00
|
|
|
cli.parseOptions(args)
|
|
|
|
|
|
|
|
if (cli.errored) {
|
|
|
|
PrintHelp()
|
|
|
|
}
|
|
|
|
|
|
|
|
function PrintHelp() {
|
|
|
|
console.log('')
|
2020-04-01 15:35:33 +00:00
|
|
|
console.log('Usage: eltro <options> <files>')
|
2020-03-31 17:27:36 +00:00
|
|
|
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('')
|
2020-04-01 15:35:33 +00:00
|
|
|
console.log('eltro test/mytest.mjs')
|
|
|
|
console.log('eltro dot test/*.mjs')
|
|
|
|
console.log('eltro -r dot test/**/*.test.mjs')
|
2020-04-01 15:46:11 +00:00
|
|
|
console.log('')
|
2020-03-31 17:27:36 +00:00
|
|
|
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() {
|
2020-04-01 15:35:33 +00:00
|
|
|
e.reporter = cli.reporter
|
2020-03-31 17:27:36 +00:00
|
|
|
|
2020-04-01 15:35:33 +00:00
|
|
|
return e.run()
|
2020-03-31 17:27:36 +00:00
|
|
|
.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('')
|
2021-06-02 15:31:09 +00:00
|
|
|
console.error('\x1b[31m' + err.message + '\x1b[0m')
|
|
|
|
printError(err.inner)
|
2020-03-31 17:27:36 +00:00
|
|
|
process.exit(1)
|
|
|
|
})
|
|
|
|
}, function(err) {
|
|
|
|
console.log('')
|
|
|
|
console.error('\x1b[31mUnknown error while processing arguments\x1b[0m')
|
|
|
|
printError(err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
2021-10-11 01:29:07 +00:00
|
|
|
.then(function(stats) {
|
|
|
|
if (stats.failed > 0) {
|
|
|
|
process.exit(10)
|
|
|
|
}
|
2020-03-31 17:27:36 +00:00
|
|
|
process.exit(0)
|
2021-06-02 21:28:51 +00:00
|
|
|
}, function(err) {
|
|
|
|
console.error('\x1b[31mInternal error occured:\x1b[0m', err)
|
|
|
|
process.exit(2)
|
2020-03-31 17:27:36 +00:00
|
|
|
})
|