-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.js
executable file
·36 lines (32 loc) · 1013 Bytes
/
list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env node
const { isJSFile, listFiles, listExecutedTests, runMocha } = require('./lib')
const getArgs = () => {
if ((process.argv.length <= 2) || ((process.argv[2] === '-h') || (process.argv[2] === '--help'))) {
console.log('Use: mocha-list <test-dir>\n')
console.log('Copyright(c) 2019 Mostafa Yassin <[email protected]> - MIT Licensed')
process.exit(0)
}
const testDir = process.argv[2] || 'test'
return { testDir }
}
/**
* This is a basic implementation that
* Searches for all JS files under the specified test dir
* Patch Mocha's test runner
* Run Mocha programmatically
* List the full title of all executed tests
*/
const main = async () => {
const args = getArgs()
const files = listFiles(args.testDir).filter(isJSFile)
const runner = runMocha(files, { reporter: 'base' })
return listExecutedTests(runner)
}
main()
.then(tests => {
console.log(tests.join('\n'))
})
.catch(error => {
console.error(error)
process.exit(-1)
})