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'
|
|
|
|
|
|
|
|
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')
|
2022-03-02 14:25:56 +00:00
|
|
|
console.log(' -t, --timeout - Specify the timeout for tests in ms.')
|
|
|
|
console.log(' Default value is 2000ms')
|
2023-09-28 09:33:43 +00:00
|
|
|
console.log(' -w, --watch - specify which group of files to watch from package.json')
|
|
|
|
console.log(' ')
|
2022-03-02 14:25:56 +00:00
|
|
|
console.log(' --ignore-only - Specify to ignore any .only() tests found')
|
2020-03-31 17:27:36 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-09-28 09:33:43 +00:00
|
|
|
function showErrorAndExit(message = '', err = null, code = 1) {
|
|
|
|
console.log('')
|
|
|
|
|
|
|
|
if (message) {
|
|
|
|
console.error(`\x1b[31m${message}\x1b[0m`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
printError(err)
|
|
|
|
} else {
|
2020-03-31 17:27:36 +00:00
|
|
|
PrintHelp()
|
|
|
|
}
|
2023-09-28 09:33:43 +00:00
|
|
|
process.exit(code)
|
|
|
|
}
|
2020-03-31 17:27:36 +00:00
|
|
|
|
2023-09-28 09:33:43 +00:00
|
|
|
const cli = new CLI(e)
|
|
|
|
cli.parseOptions(args)
|
|
|
|
.catch(function(err) { showErrorAndExit(err.message) })
|
|
|
|
.then(function() {
|
|
|
|
return cli.startWatcher()
|
|
|
|
})
|
|
|
|
.catch(function(err) { showErrorAndExit('Unknown error while starting watcher', err) })
|
|
|
|
.then(function() {
|
|
|
|
return cli.getFiles()
|
|
|
|
})
|
|
|
|
.catch(function(err) { showErrorAndExit('Unknown error while processing arguments', err) })
|
|
|
|
.then(function() {
|
|
|
|
if (!cli.files.length) {
|
|
|
|
showErrorAndExit('No files were found with pattern', cli.targets.join(','))
|
|
|
|
}
|
|
|
|
|
|
|
|
return cli.loadFiles()
|
|
|
|
})
|
|
|
|
.catch(function(err) { showErrorAndExit('', err) })
|
|
|
|
.then(function() {
|
|
|
|
return cli.beginRun()
|
2020-03-31 17:27:36 +00:00
|
|
|
})
|
2023-09-28 09:33:43 +00:00
|
|
|
.catch(function(err) { showErrorAndExit('Unknown error occured while running the tests', err) })
|
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)
|
|
|
|
})
|