-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bin.js
executable file
·71 lines (61 loc) · 1.43 KB
/
bin.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
#!/usr/bin/env node
'use strict'
const mri = require('mri')
const sink = require('stream-sink')
const {version} = require('./package.json')
const run = require('.')
const argv = mri(process.argv.slice(2), {
boolean: [
'help', 'h',
'version', 'v'
]
})
if (argv.help || argv.h) {
process.stdout.write(`
Usage:
chutney [--timeout <seconds>]
Options:
--timeout -t Set the timeout in seconds. Default: 20
Examples:
browserify test.js | chutney | tap-spec
\n`)
process.exit(0)
}
if (argv.version || argv.v) {
process.stdout.write(version + '\n')
process.exit(0)
}
const showError = (err) => {
console.error(err.data || err)
process.exit(1)
}
if ('string' !== typeof process.env.SAUCE_USER) {
showError('You must export $SAUCE_USER.')
}
if ('string' !== typeof process.env.SAUCE_KEY) {
showError('You must export $SAUCE_KEY.')
}
if ('string' !== typeof process.env.PLATFORM) {
showError('You must export $PLATFORM.')
}
if ('string' !== typeof process.env.BROWSER) {
showError('You must export $BROWSER.')
}
let timeout
if (argv.timeout || argv.t) {
timeout = parseInt(argv.timeout || argv.t)
if (Number.isNaN(timeout)) showError('Timeout must be a number.')
}
process.stdin
.pipe(sink())
.then((tests) => {
run({
user: process.env.SAUCE_USER, key: process.env.SAUCE_KEY,
platform: process.env.PLATFORM, browser: process.env.BROWSER,
timeout,
tests
})
.once('error', showError)
.pipe(process.stdout)
})
.catch(showError)