/
testmybot.js
90 lines (83 loc) · 2.21 KB
/
testmybot.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env node
const yargsCmd = require('yargs')
const Mocha = require('mocha')
const debug = require('debug')
const path = require('path')
const outputTypes = [
'tap',
'json',
'xunit',
'spec',
'list',
'html'
]
yargsCmd.usage('TestMyBot CLI\n\nUsage: $0 [options]') // eslint-disable-line
.help('help').alias('help', 'h')
.version('version', require('../package.json').version).alias('version', 'V')
.command('run [output]', 'Run TestMyBot convo files and output test report', (yargs) => {
yargs.positional('output', {
describe: 'Output report type, supported: ' + outputTypes.join(),
default: 'spec'
})
}, (argv) => {
handleOptions(argv)
if (outputTypes.findIndex((o) => o === argv.output) < 0) {
yargsCmd.showHelp()
} else {
runTestsuite(argv)
}
})
.command('emulator [type]', 'Launch TestMyBot emulator', (yargs) => {
yargs.positional('type', {
describe: 'Emulator type, supported: "console", "browser"',
default: 'console'
})
}, (argv) => {
handleOptions(argv)
if (argv.type !== 'console' && argv.type !== 'browser') {
yargsCmd.showHelp()
} else if (argv.type === 'console') {
require('../emulator-console')
} else if (argv.type === 'browser') {
require('../emulator-browser')
}
})
.option('verbose', {
alias: 'v',
describe: 'Enable verbose output',
default: false
})
.option('convos', {
alias: 'C',
describe: 'Path to the directory holding your convo files',
default: './spec/convo'
})
.option('config', {
alias: 'c',
describe: 'Path to the TestMyBot configuration file (testmybot.json)',
default: './testmybot.json'
})
.demandCommand()
.argv
function handleOptions (argv) {
if (argv.verbose) {
debug.enable('testmybot*,botium*')
}
if (argv.convos) {
require('../src/convo').setConvoDir(argv.convos)
}
if (argv.config) {
require('../src/readconfig').setConfigFile(argv.config)
}
}
function runTestsuite (argv) {
const mocha = new Mocha({
reporter: argv.output
})
mocha.addFile(path.resolve(__dirname, 'testmybot.spec.js'))
mocha.run((failures) => {
process.on('exit', () => {
process.exit(failures)
})
})
}