This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
/
test-spec.coffee
73 lines (59 loc) · 2.21 KB
/
test-spec.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
child_process = require 'child_process'
path = require 'path'
temp = require 'temp'
apm = require '../lib/apm-cli'
describe "apm test", ->
[specPath] = []
beforeEach ->
silenceOutput()
spyOnToken()
currentDir = temp.mkdirSync('apm-init-')
spyOn(process, 'cwd').andReturn(currentDir)
specPath = path.join(currentDir, 'spec')
it "calls atom to test", ->
atomSpawn = spyOn(child_process, 'spawn').andReturn
stdout:
on: ->
stderr:
on: ->
on: ->
apm.run(['test'])
waitsFor 'waiting for test to complete', ->
atomSpawn.callCount is 1
runs ->
# On Windows, there's a suffix (atom.cmd), so we only check that atom is _included_ in the path
expect(atomSpawn.mostRecentCall.args[0].indexOf('atom')).not.toBe -1
expect(atomSpawn.mostRecentCall.args[1][0]).toEqual '--dev'
expect(atomSpawn.mostRecentCall.args[1][1]).toEqual '--test'
expect(atomSpawn.mostRecentCall.args[1][2]).toEqual specPath
if process.platform isnt 'win32'
expect(atomSpawn.mostRecentCall.args[2].streaming).toBeTruthy()
describe 'returning', ->
[callback] = []
returnWithCode = (type, code) ->
callback = jasmine.createSpy('callback')
atomReturnFn = (e, fn) -> fn(code) if e is type
spyOn(child_process, 'spawn').andReturn
stdout:
on: ->
stderr:
on: ->
on: atomReturnFn
removeListener: -> # no op
apm.run(['test'], callback)
describe 'successfully', ->
beforeEach -> returnWithCode('close', 0)
it "prints success", ->
expect(callback).toHaveBeenCalled()
expect(callback.mostRecentCall.args[0]).toBeUndefined()
expect(process.stdout.write.mostRecentCall.args[0]).toEqual 'Tests passed\n'.green
describe 'with a failure', ->
beforeEach -> returnWithCode('close', 1)
it "prints failure", ->
expect(callback).toHaveBeenCalled()
expect(callback.mostRecentCall.args[0]).toEqual 'Tests failed'
describe 'with an error', ->
beforeEach -> returnWithCode('error')
it "prints failure", ->
expect(callback).toHaveBeenCalled()
expect(callback.mostRecentCall.args[0]).toEqual 'Tests failed'