Skip to content

Commit 6663e47

Browse files
Lalem001johnjbarton
authored andcommitted
feat (adapter): Use jasmine's new configure method (#224)
Pass `client.jasmine` object directly to `jasmine.configure` method. See: https://jasmine.github.io/api/3.3/Env.html Closes: #221 BREAKING CHANGE: `stopOnFailure`, which was previously documented in karma-jasmine's README, is not configuration option for jasmine. Use `oneFailurePerSpec` instead. Requires peerDependency Jasmine@^3.3.0
1 parent e604132 commit 6663e47

File tree

5 files changed

+40
-80
lines changed

5 files changed

+40
-80
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module.exports = function(config) {
7979
jasmine: {
8080
random: true,
8181
seed: '4321',
82-
stopOnFailure: true,
82+
oneFailurePerSpec: true,
8383
failFast: true,
8484
timeoutInterval: 1000
8585
}

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
"grunt-karma": "2.x",
3232
"grunt-npm": "0.0.2",
3333
"karma": "2.x || ",
34-
"jasmine-core": "~3.0.0",
34+
"jasmine-core": "^3.3.0",
3535
"karma-chrome-launcher": "1.x || ~0.2.2",
3636
"karma-firefox-launcher": "1.x || ~0.1.7",
3737
"load-grunt-tasks": "^3.4.1"
3838
},
3939
"peerDependencies": {
40-
"jasmine-core": "*",
40+
"jasmine-core": "^3.3.0",
4141
"karma": "*"
4242
},
4343
"engines": {

src/adapter.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -322,19 +322,26 @@ var KarmaSpecFilter = function (options) {
322322
}
323323

324324
/**
325+
* Configure jasmine specFilter
326+
*
327+
* This function is invoked from the wrapper.
328+
* @see adapter.wrapper
329+
*
325330
* @param {Object} config The karma config
326331
* @param {Object} jasmineEnv jasmine environment object
327332
*/
328333
var createSpecFilter = function (config, jasmineEnv) {
329-
var specFilter = new KarmaSpecFilter({
334+
var karmaSpecFilter = new KarmaSpecFilter({
330335
filterString: function () {
331336
return getGrepOption(config.args)
332337
}
333338
})
334339

335-
jasmineEnv.specFilter = function (spec) {
336-
return specFilter.matches(spec.getFullName())
340+
var specFilter = function (spec) {
341+
return karmaSpecFilter.matches(spec.getFullName())
337342
}
343+
344+
jasmineEnv.configure({ specFilter: specFilter })
338345
}
339346

340347
/**
@@ -355,23 +362,14 @@ function createStartFn (karma, jasmineEnv) {
355362

356363
jasmineEnv = jasmineEnv || window.jasmine.getEnv()
357364

358-
setOption(jasmineConfig.stopOnFailure, jasmineEnv.throwOnExpectationFailure)
359-
setOption(jasmineConfig.failFast, jasmineEnv.stopOnSpecFailure)
360-
setOption(jasmineConfig.seed, jasmineEnv.seed)
361-
setOption(jasmineConfig.random, jasmineEnv.randomizeTests)
365+
jasmineEnv.configure(jasmineConfig)
362366

363367
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = jasmineConfig.timeoutInterval ||
364368
window.jasmine.DEFAULT_TIMEOUT_INTERVAL
365369

366370
jasmineEnv.addReporter(new KarmaReporter(karma, jasmineEnv))
367371
jasmineEnv.execute()
368372
}
369-
370-
function setOption (option, set) {
371-
if (option != null && typeof set === 'function') {
372-
set(option)
373-
}
374-
}
375373
}
376374

377375
function indexOf (collection, find, i /* opt*/) {

test/adapter.spec.js

+23-61
Original file line numberDiff line numberDiff line change
@@ -366,42 +366,14 @@ describe('jasmine adapter', function () {
366366
jasmineEnv = new jasmine.Env()
367367
})
368368

369-
it('should set random order', function () {
370-
jasmineConfig.random = true
371-
spyOn(jasmineEnv, 'randomizeTests')
369+
it('should pass jasmineConfig directly to jasmine.configure', function () {
370+
var configure = spyOn(jasmineEnv, 'configure')
372371

373-
createStartFn(tc, jasmineEnv)()
374-
375-
expect(jasmineEnv.randomizeTests).toHaveBeenCalledWith(true)
376-
})
377-
378-
it('should set order seed', function () {
379-
var seed = '4321'
380-
381-
jasmineConfig.seed = seed
382-
spyOn(jasmineEnv, 'seed')
372+
jasmineConfig.foo = 42
383373

384374
createStartFn(tc, jasmineEnv)()
385375

386-
expect(jasmineEnv.seed).toHaveBeenCalledWith(seed)
387-
})
388-
389-
it('should set stopOnFailure', function () {
390-
jasmineConfig.stopOnFailure = true
391-
spyOn(jasmineEnv, 'throwOnExpectationFailure')
392-
393-
createStartFn(tc, jasmineEnv)()
394-
395-
expect(jasmineEnv.throwOnExpectationFailure).toHaveBeenCalledWith(true)
396-
})
397-
398-
it('should set failFast', function () {
399-
jasmineConfig.failFast = true
400-
spyOn(jasmineEnv, 'stopOnSpecFailure')
401-
402-
createStartFn(tc, jasmineEnv)()
403-
404-
expect(jasmineEnv.stopOnSpecFailure).toHaveBeenCalledWith(true)
376+
expect(configure).toHaveBeenCalledWith(jasmineConfig)
405377
})
406378

407379
it('should change timeoutInterval', function () {
@@ -416,29 +388,6 @@ describe('jasmine adapter', function () {
416388
jasmine.DEFAULT_TIMEOUT_INTERVAL = previousTimeoutInterval
417389
})
418390

419-
it('should not set random order if client does not pass it', function () {
420-
spyOn(jasmineEnv, 'randomizeTests')
421-
422-
createStartFn(tc, jasmineEnv)()
423-
424-
expect(jasmineEnv.randomizeTests).not.toHaveBeenCalled()
425-
})
426-
427-
it('should not fail with failFast if the jasmineEnv does not support it', function () {
428-
jasmineConfig.failFast = true
429-
jasmineEnv.stopOnSpecFailure = null
430-
431-
expect(function () {
432-
createStartFn(tc, jasmineEnv)()
433-
}).not.toThrowError()
434-
})
435-
436-
it('should not change timeoutInterval if client does not pass it', function () {
437-
createStartFn(tc, jasmineEnv)()
438-
439-
expect(jasmine.DEFAULT_TIMEOUT_INTERVAL).toBe(jasmine.DEFAULT_TIMEOUT_INTERVAL)
440-
})
441-
442391
it('should not fail if client does not set config', function () {
443392
tc.config = null
444393

@@ -601,18 +550,31 @@ describe('jasmine adapter', function () {
601550
})
602551

603552
describe('createSpecFilter', function () {
553+
var jasmineEnv
554+
555+
beforeEach(function () {
556+
jasmineEnv = new jasmine.Env()
557+
})
558+
604559
it('should create spec filter in jasmine', function () {
605-
var jasmineEnvMock = {}
606560
var karmaConfMock = {
607561
args: ['--grep', 'test']
608562
}
609-
var specMock = {
610-
getFullName: jasmine.createSpy('getFullName').and.returnValue('test')
611-
}
612563

613-
createSpecFilter(karmaConfMock, jasmineEnvMock)
564+
createSpecFilter(karmaConfMock, jasmineEnv)
565+
566+
var specFilter = jasmineEnv.configuration().specFilter
567+
568+
// Jasmine's default specFilter **always** returns true
569+
// so test multiple possibilities
570+
571+
expect(specFilter({
572+
getFullName: jasmine.createSpy('getFullName').and.returnValue('test')
573+
})).toEqual(true)
614574

615-
expect(jasmineEnvMock.specFilter(specMock)).toEqual(true)
575+
expect(specFilter({
576+
getFullName: jasmine.createSpy('getFullName2').and.returnValue('foo')
577+
})).toEqual(false)
616578
})
617579
})
618580
})

0 commit comments

Comments
 (0)