#!/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 ') console.log('') console.log('where can either be a single file or a simple glob pattern.') console.log('where 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(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) })