This repository has been archived by the owner on Oct 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.coffee
58 lines (50 loc) · 1.76 KB
/
cli.coffee
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
chai = require 'chai'
child_process = require 'child_process'
path = require 'path'
debug = require('debug')('jsjob:test')
jsJobRun = (url, input, callback) ->
prog = "./bin/jsjob-run"
args = [
url
]
childOptions = {}
cmd = prog + ' ' + args.join ' '
debug 'running:', cmd
child = child_process.execFile prog, args, childOptions, callback
input = JSON.stringify input
debug 'writing stdin', input
child.stdin.end input, 'utf8'
return child
module.exports.jsJobRun = jsJobRun
testserver = 'http://localhost:8001'
fixture = (name) ->
return path.join testserver, 'spec/fixtures/jsjobs', name
cliTimeout = 4000
describe 'jsjob-run', ->
stdout = null
stderr = null
describe "with job that errors", ->
it 'should exit with non-zero code', (done) ->
@timeout cliTimeout
jsJobRun fixture('return-error.js'), { 'input': 'data' }, (err, o, e) ->
[stdout, stderr] = [o, e]
chai.expect(err).to.exist
chai.expect(err.code).to.not.equal 0
chai.expect(err.message).to.contain 'Command failed'
done()
it 'should write error message to stderr', () ->
chai.expect(stderr).to.include 'Error'
chai.expect(stderr).to.include 'this is my error message'
it 'should write error stack to stderr'
describe "with job that passes", ->
it 'should exit with 0 code', (done) ->
@timeout cliTimeout
jsJobRun fixture('return-input.js'), { 'original': 'input' }, (err, o, e) ->
[stdout, stderr] = [o, e]
chai.expect(err).to.not.exist
done()
it 'should write results to stdout', () ->
chai.expect(stdout).to.include 'original'
parsed = JSON.parse stdout
chai.expect(parsed).to.have.keys ['original']
chai.expect(parsed.original).to.equal 'input'