Skip to content

Commit

Permalink
style(tests): make coffee lint super happy
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina committed Apr 2, 2013
1 parent d2bd3fe commit ac1e227
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 66 deletions.
36 changes: 18 additions & 18 deletions test/tasks/lib/changelog.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,45 @@ describe 'changelog', ->

it 'should parse raw commit', ->
msg = ch.parseRawCommit(
'9b1aff905b638aa274a5fc8f88662df446d374bd\n' +
'feat(scope): broadcast $destroy event on scope destruction\n' +
'perf testing shows that in chrome this change adds 5-15% overhead\n' +
'when destroying 10k nested scopes where each scope has a $destroy listener\n')
'9b1aff905b638aa274a5fc8f88662df446d374bd\n' +
'feat(scope): broadcast $destroy event on scope destruction\n' +
'perf testing shows that in chrome this change adds 5-15% overhead\n' +
'when destroying 10k nested scopes where each scope has a $destroy listener\n')

expect(msg.type).to.equal 'feat'
expect(msg.component).to.equal 'scope'
expect(msg.hash).to.equal '9b1aff905b638aa274a5fc8f88662df446d374bd'
expect(msg.subject).to.equal 'broadcast $destroy event on scope destruction'
expect(msg.body).to.equal(
'perf testing shows that in chrome this change adds 5-15% overhead\n' +
'when destroying 10k nested scopes where each scope has a $destroy listener\n')
'perf testing shows that in chrome this change adds 5-15% overhead\n' +
'when destroying 10k nested scopes where each scope has a $destroy listener\n')


it 'should parse closed issues', ->
msg = ch.parseRawCommit(
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' +
'feat(ng-list): Allow custom separator\n' +
'bla bla bla\n\n' +
'Closes #123\nCloses #25\n')
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' +
'feat(ng-list): Allow custom separator\n' +
'bla bla bla\n\n' +
'Closes #123\nCloses #25\n')

expect(msg.closes).to.deep.equal [123, 25]


it 'should parse breaking changes', ->
msg = ch.parseRawCommit(
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' +
'feat(ng-list): Allow custom separator\n' +
'bla bla bla\n\n' +
'BREAKING CHANGE: some breaking change\n')
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' +
'feat(ng-list): Allow custom separator\n' +
'bla bla bla\n\n' +
'BREAKING CHANGE: some breaking change\n')

expect(msg.breaks).to.deep.equal ['some breaking change\n']


it 'should parse a msg without scope', ->
msg = ch.parseRawCommit(
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' +
'chore: some chore bullshit\n' +
'bla bla bla\n\n' +
'BREAKING CHANGE: some breaking change\n')
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' +
'chore: some chore bullshit\n' +
'bla bla bla\n\n' +
'BREAKING CHANGE: some breaking change\n')

expect(msg.type).to.equal 'chore'
8 changes: 5 additions & 3 deletions test/tasks/lib/validate-commit-msg.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ describe 'validate-commit-msg', ->
m = require '../../../tasks/lib/validate-commit-msg'
errors = []

VALID = true;
INVALID = false;
VALID = true
INVALID = false


beforeEach ->
Expand Down Expand Up @@ -40,7 +40,9 @@ describe 'validate-commit-msg', ->
msg = 'not correct format'

expect(m.validateMessage msg).to.equal INVALID
expect(errors).to.deep.equal ['INVALID COMMIT MSG: does not match "<type>(<scope>): <subject>" !']
expect(errors).to.deep.equal [
'INVALID COMMIT MSG: does not match "<type>(<scope>): <subject>" !'
]


it 'should validate type', ->
Expand Down
10 changes: 8 additions & 2 deletions test/unit/config.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ describe 'config', ->

it 'should keep absolute url file patterns', ->
config = e.parseConfig '/conf/absolute.js', {}
expect(patternsFrom config.files).to.deep.equal ['http://some.com', 'https://more.org/file.js']
expect(patternsFrom config.files).to.deep.equal [
'http://some.com'
'https://more.org/file.js'
]


it 'should resolve all exclude patterns', ->
Expand Down Expand Up @@ -220,7 +223,10 @@ describe 'config', ->

it 'should compile coffeescript config', ->
config = e.parseConfig '/conf/coffee.coffee', {}
expect(patternsFrom config.files).to.deep.equal [resolveWinPath('/conf/one.js'), resolveWinPath('/conf/two.js')]
expect(patternsFrom config.files).to.deep.equal [
resolveWinPath('/conf/one.js')
resolveWinPath('/conf/two.js')
]


it 'should set defaults with coffeescript', ->
Expand Down
11 changes: 7 additions & 4 deletions test/unit/file-list.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ describe 'file-list', ->
# /a.* => /a.txt [MATCH in *.txt as well]
# /some/*.js => /some/a.js, /some/b.js [/some/b.js EXCLUDED]
# *.txt => /c.txt, a.txt, b.txt [UNSORTED]
list = new m.List patterns('/a.*', '/some/*.js', '*.txt'), ['**/b.js'], emitter, preprocessMock
list = new m.List patterns('/a.*', '/some/*.js', '*.txt'), ['**/b.js'], emitter,
preprocessMock

refreshListAndThen (files) ->
expect(pathsFrom files.served).to.deep.equal ['/a.txt', '/some/a.js', '/b.txt', '/c.txt']
Expand Down Expand Up @@ -251,7 +252,9 @@ describe 'file-list', ->
refreshListAndThen (files) ->
expect(pathsFrom files.served).to.deep.equal ['/some/a.js', '/some/b.js', '/a.txt']
waitForAddingFile done, '/a.js', (files) ->
expect(pathsFrom files.served).to.deep.equal ['/some/a.js', '/some/b.js', '/a.js', '/a.txt']
expect(pathsFrom files.served).to.deep.equal [
'/some/a.js', '/some/b.js', '/a.js', '/a.txt'
]


it 'should fire "file_list_modified" and pass a promise', (done) ->
Expand Down Expand Up @@ -388,7 +391,7 @@ describe 'file-list', ->
refreshListAndThen (files) ->
waitForRemovingFile '/some/a.js', (files) ->
expect(pathsFrom files.served).to.deep.equal ['/some/b.js', '/a.txt']
expect(onFileListModifiedSpy).to.have.been.called;
expect(onFileListModifiedSpy).to.have.been.called


it 'should not fire "file_list_modified" if file is not in the list', ->
Expand All @@ -397,7 +400,7 @@ describe 'file-list', ->

refreshListAndThen (files) ->
waitForRemovingFile '/a.js', ->
expect(onFileListModifiedSpy).not.to.have.been.called;
expect(onFileListModifiedSpy).not.to.have.been.called


#============================================================================
Expand Down
29 changes: 15 additions & 14 deletions test/unit/helper.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,78 +16,79 @@ describe 'helper', ->
it 'should parse iOS', ->
expecting('Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 ' +
'(KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25').
to.be.equal 'Safari 6.0 (iOS)'
to.be.equal 'Safari 6.0 (iOS)'


it 'should parse Linux', ->
expecting('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.19) Gecko/20081216 ' +
'Ubuntu/8.04 (hardy) Firefox/2.0.0.19').
to.be.equal 'Firefox 2.0 (Linux)'
to.be.equal 'Firefox 2.0 (Linux)'


it 'should degrade gracefully when OS not recognized', ->
expecting('Mozilla/5.0 (X11; U; FreeBSD; i386; en-US; rv:1.7) Gecko/20081216 Firefox/2.0.0.19').
to.be.equal 'Firefox 2.0'
expecting('Mozilla/5.0 (X11; U; FreeBSD; i386; en-US; rv:1.7) Gecko/20081216 ' +
'Firefox/2.0.0.19').
to.be.equal 'Firefox 2.0'


it 'should parse Chrome', ->
expecting('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 ' +
'(KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7').
to.be.equal 'Chrome 16.0 (Mac)'
to.be.equal 'Chrome 16.0 (Mac)'

expecting('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.15 ' +
'(KHTML, like Gecko) Chrome/18.0.985.0 Safari/535.15').
to.be.equal 'Chrome 18.0 (Mac)'
to.be.equal 'Chrome 18.0 (Mac)'


it 'should parse Firefox', ->
expecting('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 ' +
'Firefox/7.0.1').
to.be.equal 'Firefox 7.0 (Mac)'
to.be.equal 'Firefox 7.0 (Mac)'


it 'should parse Opera', ->
expecting('Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.9.168 ' +
'Version/11.52').
to.be.equal 'Opera 11.52 (Mac)'
to.be.equal 'Opera 11.52 (Mac)'


it 'should parse Safari', ->
expecting('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.52.7 ' +
'(KHTML, like Gecko) Version/5.1.2 Safari/534.52.7').
to.be.equal 'Safari 5.1 (Mac)'
to.be.equal 'Safari 5.1 (Mac)'


it 'should parse IE7', ->
expecting('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; ' +
'.NET CLR 2.0.50727; .NET4.0C; .NET4.0E)').
to.be.equal 'IE 7.0 (Windows)'
to.be.equal 'IE 7.0 (Windows)'


it 'should parse IE8', ->
expecting('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; ' +
'SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; ' +
'.NET4.0E; InfoPath.3)"').
to.be.equal 'IE 8.0 (Windows)'
to.be.equal 'IE 8.0 (Windows)'


it 'should parse IE9', ->
expecting('Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; ' +
'.NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center ' +
'PC 6.0)').
to.be.equal 'IE 9.0 (Windows)'
to.be.equal 'IE 9.0 (Windows)'


it 'should parse IE10', ->
expecting('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; ' +
'.NET4.0E; .NET4.0C)').
to.be.equal 'IE 10.0 (Windows)'
to.be.equal 'IE 10.0 (Windows)'


it 'should parse PhantomJS', ->
expecting('Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) ' +
'PhantomJS/1.6.0 Safari/534.34').
to.be.equal 'PhantomJS 1.6 (Mac)'
to.be.equal 'PhantomJS 1.6 (Mac)'


#==============================================================================
Expand Down
7 changes: 4 additions & 3 deletions test/unit/init.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ describe 'init', ->

it 'should handle config in a parent path', ->
# config /home/file.js
file = replace('../../../file.js')
expect(m.getBasePath file, replace('/home/vojta/tc/project')).to.equal replace('vojta/tc/project')
basePath = m.getBasePath replace('../../../file.js'), replace('/home/vojta/tc/project')
expect(basePath).to.equal replace('vojta/tc/project')


it 'should handle config in parent subfolder', ->
Expand All @@ -153,7 +153,8 @@ describe 'init', ->


it 'should handle absolute paths', ->
expect(m.getBasePath replace('/Users/vojta/karma/conf.js'), replace('/Users/vojta')).to.equal replace('..')
basePath = m.getBasePath replace('/Users/vojta/karma/conf.js'), replace('/Users/vojta')
expect(basePath).to.equal replace('..')


describe 'getReplacementsFromAnswers', ->
Expand Down
25 changes: 14 additions & 11 deletions test/unit/launchers/Base.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe 'launchers Base', ->
path = require 'path'

fakeTimer = null

mockSpawn = sinon.spy (cmd, args) ->
process = new events.EventEmitter
process.stderr = new events.EventEmitter
Expand All @@ -15,7 +15,7 @@ describe 'launchers Base', ->
mockSpawn._processes.push process
process


mockRimraf = sinon.spy (p, fn) ->
mockRimraf._callbacks.push fn

Expand All @@ -36,10 +36,10 @@ describe 'launchers Base', ->
TMP: '/tmp'
nextTick: process.nextTick
setTimeout: timer.setTimeout


m = loadFile __dirname + '/../../../lib/launchers/Base.js', mocks, globals


beforeEach ->
mockSpawn.reset()
Expand Down Expand Up @@ -101,7 +101,8 @@ describe 'launchers Base', ->

# start the browser
browser.start 'http://localhost/'
expect(mockSpawn).to.have.been.calledWith path.normalize('/usr/bin/browser'), ['http://localhost/?id=12345']
expect(mockSpawn).to.have.been.calledWith path.normalize('/usr/bin/browser'),
['http://localhost/?id=12345']
mockSpawn.reset()

# mark captured
Expand All @@ -128,12 +129,13 @@ describe 'launchers Base', ->
browser.start 'http://localhost/'

# expect starting the process
expect(mockSpawn).to.have.been.calledWith path.normalize('/usr/bin/browser'), ['http://localhost/?id=12345']
expect(mockSpawn).to.have.been.calledWith path.normalize('/usr/bin/browser'),
['http://localhost/?id=12345']
browserProcess = mockSpawn._processes.shift()

# timeout
expect(timer.setTimeout).to.have.been.called

# expect killing browser
expect(browserProcess.kill).to.have.been.called
browserProcess.emit 'close', 0
Expand All @@ -142,10 +144,11 @@ describe 'launchers Base', ->
mockRimraf._callbacks[0]() # cleanup

# expect re-starting
expect(mockSpawn).to.have.been.calledWith path.normalize('/usr/bin/browser'), ['http://localhost/?id=12345']
expect(mockSpawn).to.have.been.calledWith path.normalize('/usr/bin/browser'),
['http://localhost/?id=12345']
browserProcess = mockSpawn._processes.shift()

expect(failureSpy).not.to.have.been.called;
expect(failureSpy).not.to.have.been.called


it 'start -> timeout -> 3xrestart -> failure', ->
Expand Down Expand Up @@ -187,7 +190,7 @@ describe 'launchers Base', ->
mockRimraf.reset()

# after two time-outs, still no failure
expect(failureSpy).not.to.have.been.called;
expect(failureSpy).not.to.have.been.called

# expect starting
expect(mockSpawn).to.have.been.calledWith normalized, ['http://localhost/?id=12345']
Expand Down Expand Up @@ -231,4 +234,4 @@ describe 'launchers Base', ->
expect(mockSpawn).to.have.been.calledWith normalized, ['http://localhost/?id=12345']
browserProcess = mockSpawn._processes.shift()

expect(failureSpy).not.to.have.been.called;
expect(failureSpy).not.to.have.been.called
18 changes: 14 additions & 4 deletions test/unit/proxy.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ describe 'proxy', ->


it 'should support multiple proxies', ->
proxy = m.createProxyHandler mockProxy, {'/proxy': 'http://localhost:9000', '/static': 'http://gstatic.com'}
proxy = m.createProxyHandler mockProxy, {
'/proxy': 'http://localhost:9000'
'/static': 'http://gstatic.com'
}
proxy new httpMock.ServerRequest('/static/test.html'), response, nextSpy

expect(nextSpy).not.to.have.been.called
Expand All @@ -45,7 +48,10 @@ describe 'proxy', ->


it 'should handle nested proxies', ->
proxy = m.createProxyHandler mockProxy, {'/sub': 'http://localhost:9000', '/sub/some': 'http://gstatic.com/something'}
proxy = m.createProxyHandler mockProxy, {
'/sub': 'http://localhost:9000'
'/sub/some': 'http://gstatic.com/something'
}
proxy new httpMock.ServerRequest('/sub/some/Test.html'), response, nextSpy

expect(nextSpy).not.to.have.been.called
Expand All @@ -70,13 +76,17 @@ describe 'proxy', ->
it 'should parse a simple proxy config', ->
proxy = {'/base/': 'http://localhost:8000/'}
parsedProxyConfig = m.parseProxyConfig proxy
expect(parsedProxyConfig).to.deep.equal({'/base/': {host: 'localhost', port: '8000', baseProxyUrl: '/'}})
expect(parsedProxyConfig).to.deep.equal {
'/base/': {host: 'localhost', port: '8000', baseProxyUrl: '/'}
}


it 'should handle proxy configs with paths', ->
proxy = {'/base': 'http://localhost:8000/proxy'}
parsedProxyConfig = m.parseProxyConfig proxy
expect(parsedProxyConfig).to.deep.equal({'/base': {host: 'localhost', port: '8000', baseProxyUrl: '/proxy'}})
expect(parsedProxyConfig).to.deep.equal {
'/base': {host: 'localhost', port: '8000', baseProxyUrl: '/proxy'}
}


it 'should handle empty proxy config', ->
Expand Down
Loading

0 comments on commit ac1e227

Please sign in to comment.