Skip to content

Commit 574271c

Browse files
test(client): Move to assert and add shims
1 parent 8627d67 commit 574271c

4 files changed

Lines changed: 66 additions & 66 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@
303303
"grunt-mocha-test": "^0.12.7",
304304
"grunt-npm": "0.0.2",
305305
"jasmine-core": "^2.3.4",
306+
"json3": "^3.3.2",
306307
"karma-browserify": "^5.0.1",
307308
"karma-browserstack-launcher": "^0.1.10",
308309
"karma-chrome-launcher": "*",

test/client/karma.spec.js

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// shim all the things
2+
require('core-js/es5')
3+
global.JSON = require('json3')
14
var sinon = require('sinon')
2-
var chai = require('chai')
3-
chai.use(require('sinon-chai'))
4-
var expect = chai.expect
5+
var assert = require('assert')
56

67
var Karma = require('../../client/karma')
78
var MockSocket = require('./mocks').Socket
@@ -31,10 +32,10 @@ describe('Karma', function () {
3132
}
3233

3334
socket.emit('execute', config)
34-
expect(startSpy).to.not.have.been.called
35+
assert(!startSpy.called)
3536

3637
k.loaded()
37-
expect(startSpy).to.have.been.calledWith(config)
38+
assert(startSpy.calledWith(config))
3839
})
3940

4041
it('should open a new window when useIFrame is false', function () {
@@ -43,24 +44,24 @@ describe('Karma', function () {
4344
}
4445

4546
socket.emit('execute', config)
46-
expect(k.start).to.not.have.been.called
47+
assert(!k.start.called)
4748

4849
k.loaded()
49-
expect(startSpy).to.have.been.calledWith(config)
50-
expect(windowStub).to.have.been.calledWith('about:blank')
50+
assert(startSpy.calledWith(config))
51+
assert(windowStub.calledWith('about:blank'))
5152
})
5253

5354
it('should stop execution', function () {
5455
sinon.spy(k, 'complete')
5556
socket.emit('stop')
56-
expect(k.complete).to.have.been.called
57+
assert(k.complete.called)
5758
})
5859

5960
it('should not start execution if any error during loading files', function () {
6061
k.error('syntax error', '/some/file.js', 11)
6162
k.loaded()
6263
sinon.spy(k, 'start')
63-
expect(startSpy).to.not.have.been.called
64+
assert(!startSpy.called)
6465
})
6566

6667
it('should remove reference to start even after syntax error', function () {
@@ -69,11 +70,11 @@ describe('Karma', function () {
6970
k.start = ADAPTER_START_FN
7071
k.error('syntax error', '/some/file.js', 11)
7172
k.loaded()
72-
expect(k.start).to.not.be.eql(ADAPTER_START_FN)
73+
assert.notEqual(k.start, ADAPTER_START_FN)
7374

7475
k.start = ADAPTER_START_FN
7576
k.loaded()
76-
expect(k.start).to.not.be.eql(ADAPTER_START_FN)
77+
assert.notEqual(k.start, ADAPTER_START_FN)
7778
})
7879

7980
it('should not set up context if there was an error', function () {
@@ -88,9 +89,9 @@ describe('Karma', function () {
8889
k.error('page reload')
8990
k.setupContext(mockWindow)
9091

91-
expect(mockWindow.__karma__).to.not.exist
92-
expect(mockWindow.onbeforeunload).to.not.exist
93-
expect(mockWindow.onerror).to.not.exist
92+
assert(mockWindow.__karma__ == null)
93+
assert(mockWindow.onbeforeunloadK == null)
94+
assert(mockWindow.onerror == null)
9495
})
9596

9697
it('should setup context if there was error but clearContext config is false', function () {
@@ -105,22 +106,22 @@ describe('Karma', function () {
105106
k.error('page reload')
106107
k.setupContext(mockWindow)
107108

108-
expect(mockWindow.__karma__).to.exist
109-
expect(mockWindow.onbeforeunload).to.exist
110-
expect(mockWindow.onerror).to.exist
109+
assert(mockWindow.__karma__ != null)
110+
assert(mockWindow.onbeforeunload != null)
111+
assert(mockWindow.onerror != null)
111112
})
112113

113114
it('should report navigator name', function () {
114115
var spyInfo = sinon.spy(function (info) {
115-
expect(info.name).to.be.eql('Fake browser name')
116+
assert(info.name === 'Fake browser name')
116117
})
117118

118119
windowNavigator.userAgent = 'Fake browser name'
119120
windowLocation.search = ''
120121
socket.on('register', spyInfo)
121122
socket.emit('connect')
122123

123-
expect(spyInfo).to.have.been.called
124+
assert(spyInfo.called)
124125
})
125126

126127
it('should report browser id', function () {
@@ -129,13 +130,13 @@ describe('Karma', function () {
129130
k = new Karma(socket, {}, windowStub, windowNavigator, windowLocation)
130131

131132
var spyInfo = sinon.spy(function (info) {
132-
expect(info.id).to.be.eql('567')
133+
assert(info.id === '567')
133134
})
134135

135136
socket.on('register', spyInfo)
136137
socket.emit('connect')
137138

138-
expect(spyInfo).to.have.been.called
139+
assert(spyInfo.called)
139140
})
140141

141142
describe('result', function () {
@@ -150,11 +151,11 @@ describe('Karma', function () {
150151
k.result({id: i})
151152
}
152153

153-
expect(spyResult).to.not.have.been.called
154+
assert(!spyResult.called)
154155

155156
k.result('result', {id: 50})
156-
expect(spyResult).to.have.been.called
157-
expect(spyResult.args[0][0].length).to.be.eql(50)
157+
assert(spyResult.called)
158+
assert(spyResult.args[0][0].length === 50)
158159
})
159160

160161
it('should buffer results when polling', function () {
@@ -169,8 +170,8 @@ describe('Karma', function () {
169170
}
170171

171172
k.complete()
172-
expect(spyResult).to.have.been.called
173-
expect(spyResult.args[0][0].length).to.be.eql(40)
173+
assert(spyResult.called)
174+
assert(spyResult.args[0][0].length === 40)
174175
})
175176

176177
it('should emit "start" with total specs count first', function () {
@@ -188,7 +189,7 @@ describe('Karma', function () {
188189

189190
// adapter didn't call info({total: x})
190191
k.result()
191-
expect(log).to.be.eql(['start', 'result'])
192+
assert.deepEqual(log, ['start', 'result'])
192193
})
193194

194195
it('should not emit "start" if already done by the adapter', function () {
@@ -209,8 +210,8 @@ describe('Karma', function () {
209210

210211
k.info({total: 321})
211212
k.result()
212-
expect(log).to.be.eql(['start', 'result'])
213-
expect(spyStart).to.have.been.calledWith({total: 321})
213+
assert.deepEqual(log, ['start', 'result'])
214+
assert(spyStart.calledWith({total: 321}))
214215
})
215216
})
216217

@@ -226,7 +227,7 @@ describe('Karma', function () {
226227

227228
k.setupContext(mockWindow)
228229
mockWindow.alert('What?')
229-
expect(k.log).to.have.been.calledWith('alert', ['What?'])
230+
assert(k.log.calledWith('alert', ['What?']))
230231
})
231232
})
232233

@@ -235,16 +236,16 @@ describe('Karma', function () {
235236
k.store('a', 10)
236237
k.store('b', [1, 2, 3])
237238

238-
expect(k.store('a')).to.be.eql(10)
239-
expect(k.store('b')).to.be.eql([1, 2, 3])
239+
assert.equal(k.store('a'), 10)
240+
assert.deepEqual(k.store('b'), [1, 2, 3])
240241
})
241242

242243
it('should clone arrays to avoid memory leaks', function () {
243244
var array = [1, 2, 3, 4, 5]
244245

245246
k.store('one.array', array)
246-
expect(k.store('one.array')).to.be.eql(array)
247-
expect(k.store('one.array')).to.be.eql(array)
247+
assert.deepEqual(k.store('one.array'), array)
248+
assert.deepEqual(k.store('one.array'), array)
248249
})
249250
})
250251

@@ -270,10 +271,10 @@ describe('Karma', function () {
270271
k.result({id: i})
271272
}
272273

273-
expect(spyResult).to.not.have.been.called
274+
assert(!spyResult.called)
274275

275276
k.complete()
276-
expect(spyResult).to.have.been.called
277+
assert(spyResult.called)
277278
})
278279

279280
it('should navigate the client to return_url if specified', function (done) {
@@ -291,7 +292,7 @@ describe('Karma', function () {
291292

292293
clock.tick(500)
293294
setTimeout(function () {
294-
expect(windowLocation.href).to.be.eql('http://return.com')
295+
assert(windowLocation.href === 'http://return.com')
295296
done()
296297
}, 5)
297298
clock.tick(10)
@@ -309,8 +310,8 @@ describe('Karma', function () {
309310

310311
k.setupContext(mockWindow)
311312
mockWindow.console.log('What?')
312-
expect(k.log).to.have.been.calledWith('log')
313-
expect(k.log.args[0][1][0]).to.be.eql('What?')
313+
assert(k.log.calledWith('log'))
314+
assert(k.log.args[0][1][0] === 'What?')
314315
})
315316

316317
it('should not patch the console if captureConsole is false', function () {
@@ -325,7 +326,7 @@ describe('Karma', function () {
325326

326327
k.setupContext(mockWindow)
327328
mockWindow.console.log('hello')
328-
expect(k.log).to.not.have.been.called
329+
assert(!k.log.called)
329330
})
330331

331332
it('should clear context window upon complete when clearContext config is true', function () {
@@ -338,9 +339,9 @@ describe('Karma', function () {
338339

339340
k.complete()
340341

341-
clock.tick(1)
342+
clock.tick(20)
342343

343-
expect(iframe.src).to.not.be.eql(CURRENT_URL)
344+
assert.notEqual(iframe.src, CURRENT_URL)
344345
})
345346

346347
it('should not clear context window upon complete when clearContext config is false', function () {
@@ -355,7 +356,7 @@ describe('Karma', function () {
355356

356357
clock.tick(1)
357358

358-
expect(iframe.src).to.be.eql(CURRENT_URL)
359+
assert.equal(iframe.src, CURRENT_URL)
359360
})
360361
})
361362
})

test/client/stringify.spec.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
/* global __karma__ */
2-
var chai = require('chai')
3-
var expect = chai.expect
2+
var assert = require('assert')
43

54
var stringify = require('../../client/stringify')
65

76
describe('stringify', function () {
87
it('should serialize string', function () {
9-
expect(stringify('aaa')).to.be.eql("'aaa'")
8+
assert.deepEqual(stringify('aaa'), "'aaa'")
109
})
1110

1211
it('should serialize booleans', function () {
13-
expect(stringify(true)).to.be.eql('true')
14-
expect(stringify(false)).to.be.eql('false')
12+
assert.deepEqual(stringify(true), 'true')
13+
assert.deepEqual(stringify(false), 'false')
1514
})
1615

1716
it('should serialize null and undefined', function () {
18-
expect(stringify(null)).to.be.eql('null')
19-
expect(stringify()).to.be.eql('undefined')
17+
assert.deepEqual(stringify(null), 'null')
18+
assert.deepEqual(stringify(), 'undefined')
2019
})
2120

2221
it('should serialize functions', function () {
@@ -28,59 +27,59 @@ describe('stringify', function () {
2827
var partsDef = ['function', '(d, e, f)', '{ ... }']
2928

3029
partsAbc.forEach(function (part) {
31-
expect(abcString).to.contain(part)
30+
assert(abcString.indexOf(part) > -1)
3231
})
3332

3433
var defString = stringify(def)
3534
partsDef.forEach(function (part) {
36-
expect(defString).to.contain(part)
35+
assert(defString.indexOf(part) > -1)
3736
})
3837
})
3938

4039
it('should serialize arrays', function () {
41-
expect(stringify(['a', 'b', null, true, false])).to.be.eql("['a', 'b', null, true, false]")
40+
assert.deepEqual(stringify(['a', 'b', null, true, false]), "['a', 'b', null, true, false]")
4241
})
4342

4443
it('should serialize objects', function () {
4544
var obj
4645

4746
obj = {a: 'a', b: 'b', c: null, d: true, e: false}
48-
expect(stringify(obj)).to.contain("{a: 'a', b: 'b', c: null, d: true, e: false}")
47+
assert(stringify(obj).indexOf("{a: 'a', b: 'b', c: null, d: true, e: false}") > -1)
4948

5049
function MyObj () {
5150
this.a = 'a'
5251
}
5352

5453
obj = new MyObj()
55-
expect(stringify(obj)).to.contain("{a: 'a'}")
54+
assert(stringify(obj).indexOf("{a: 'a'}") > -1)
5655

5756
obj = {constructor: null}
58-
expect(stringify(obj)).to.contain('{constructor: null}')
57+
assert(stringify(obj).indexOf('{constructor: null}') > -1)
5958

6059
obj = Object.create(null)
6160
obj.a = 'a'
62-
expect(stringify(obj)).to.contain("{a: 'a'}")
61+
assert(stringify(obj).indexOf("{a: 'a'}") > -1)
6362
})
6463

6564
it('should serialize html', function () {
6665
var div = document.createElement('div')
6766

68-
expect(stringify(div)).to.be.eql('<div></div>')
67+
assert.deepEqual(stringify(div), '<div></div>')
6968

7069
div.innerHTML = 'some <span>text</span>'
71-
expect(stringify(div)).to.be.eql('<div>some <span>text</span></div>')
70+
assert.deepEqual(stringify(div), '<div>some <span>text</span></div>')
7271
})
7372

7473
it('should serialize DOMParser objects', function () {
7574
var parser = new DOMParser()
7675
var doc = parser.parseFromString('<test></test>', 'application/xml')
77-
expect(stringify(doc)).to.be.eql('<test></test>')
76+
assert.deepEqual(stringify(doc), '<test></test>')
7877
})
7978

8079
it('should serialize across iframes', function () {
8180
var div = document.createElement('div')
82-
expect(__karma__.stringify(div)).to.be.eql('<div></div>')
81+
assert.deepEqual(__karma__.stringify(div), '<div></div>')
8382

84-
expect(__karma__.stringify([1, 2])).to.be.eql('[1, 2]')
83+
assert.deepEqual(__karma__.stringify([1, 2]), '[1, 2]')
8584
})
8685
})

test/client/util.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
var chai = require('chai')
2-
var expect = chai.expect
1+
var assert = require('assert')
32

43
var util = require('../../client/util')
54

65
describe('util', function () {
76
it('parseQueryParams', function () {
87
var params = util.parseQueryParams('?id=123&return_url=http://whatever.com')
98

10-
expect(params).to.be.eql({id: '123', return_url: 'http://whatever.com'})
9+
assert.deepEqual(params, {id: '123', return_url: 'http://whatever.com'})
1110
})
1211
})

0 commit comments

Comments
 (0)