Skip to content

Commit

Permalink
Handle Jasmine 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Lalem001 committed Oct 29, 2018
1 parent e604132 commit 19b5dc7
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 18 deletions.
39 changes: 32 additions & 7 deletions src/adapter.js
Expand Up @@ -326,14 +326,20 @@ var KarmaSpecFilter = function (options) {
* @param {Object} jasmineEnv jasmine environment object
*/
var createSpecFilter = function (config, jasmineEnv) {
var specFilter = new KarmaSpecFilter({
var karmaSpecFilter = new KarmaSpecFilter({
filterString: function () {
return getGrepOption(config.args)
}
})

jasmineEnv.specFilter = function (spec) {
return specFilter.matches(spec.getFullName())
var specFilter = function (spec) {
return karmaSpecFilter.matches(spec.getFullName())
}

if (typeof jasmineEnv.configure === 'function') {
jasmineEnv.configure({ specFilter: specFilter })
} else {
jasmineEnv.specFilter = specFilter
}
}

Expand All @@ -355,10 +361,29 @@ function createStartFn (karma, jasmineEnv) {

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

setOption(jasmineConfig.stopOnFailure, jasmineEnv.throwOnExpectationFailure)
setOption(jasmineConfig.failFast, jasmineEnv.stopOnSpecFailure)
setOption(jasmineConfig.seed, jasmineEnv.seed)
setOption(jasmineConfig.random, jasmineEnv.randomizeTests)
if (typeof jasmineEnv.configure === 'function') {
// it is actually possible to pass jasmineConfig directly to `jasmine.configure`,
// but that would break karma-jasmine's documented use of `stopOnFailure`
// which is not a valid jasmine config option

if (jasmineConfig.hasOwnProperty('stopOnFailure')) {
jasmineEnv.configure({ oneFailurePerSpec: jasmineConfig.stopOnFailure })
}
if (jasmineConfig.hasOwnProperty('failFast')) {
jasmineEnv.configure({ failFast: jasmineConfig.failFast })
}
if (jasmineConfig.hasOwnProperty('seed')) {
jasmineEnv.configure({ seed: jasmineConfig.seed })
}
if (jasmineConfig.hasOwnProperty('random')) {
jasmineEnv.configure({ random: jasmineConfig.random })
}
} else {
setOption(jasmineConfig.stopOnFailure, jasmineEnv.throwOnExpectationFailure)
setOption(jasmineConfig.failFast, jasmineEnv.stopOnSpecFailure)
setOption(jasmineConfig.seed, jasmineEnv.seed)
setOption(jasmineConfig.random, jasmineEnv.randomizeTests)
}

window.jasmine.DEFAULT_TIMEOUT_INTERVAL = jasmineConfig.timeoutInterval ||
window.jasmine.DEFAULT_TIMEOUT_INTERVAL
Expand Down
57 changes: 46 additions & 11 deletions test/adapter.spec.js
Expand Up @@ -367,12 +367,17 @@ describe('jasmine adapter', function () {
})

it('should set random order', function () {
jasmineConfig.random = true
jasmineConfig.random = false
spyOn(jasmineEnv, 'randomizeTests')

createStartFn(tc, jasmineEnv)()

expect(jasmineEnv.randomizeTests).toHaveBeenCalledWith(true)
if (jasmineEnv.configuration) {
expect(jasmineEnv.configuration().random).toBe(false)
expect(jasmineEnv.randomizeTests).not.toHaveBeenCalled()
} else {
expect(jasmineEnv.randomizeTests).toHaveBeenCalledWith(false)
}
})

it('should set order seed', function () {
Expand All @@ -383,7 +388,12 @@ describe('jasmine adapter', function () {

createStartFn(tc, jasmineEnv)()

expect(jasmineEnv.seed).toHaveBeenCalledWith(seed)
if (typeof jasmineEnv.configuration === 'function') {
expect(jasmineEnv.configuration().seed).toBe(seed)
expect(jasmineEnv.seed).not.toHaveBeenCalled()
} else {
expect(jasmineEnv.seed).toHaveBeenCalledWith(seed)
}
})

it('should set stopOnFailure', function () {
Expand All @@ -392,7 +402,12 @@ describe('jasmine adapter', function () {

createStartFn(tc, jasmineEnv)()

expect(jasmineEnv.throwOnExpectationFailure).toHaveBeenCalledWith(true)
if (typeof jasmineEnv.configuration === 'function') {
expect(jasmineEnv.configuration().oneFailurePerSpec).toBe(true)
expect(jasmineEnv.throwOnExpectationFailure).not.toHaveBeenCalled()
} else {
expect(jasmineEnv.throwOnExpectationFailure).toHaveBeenCalledWith(true)
}
})

it('should set failFast', function () {
Expand All @@ -401,7 +416,12 @@ describe('jasmine adapter', function () {

createStartFn(tc, jasmineEnv)()

expect(jasmineEnv.stopOnSpecFailure).toHaveBeenCalledWith(true)
if (typeof jasmineEnv.configuration === 'function') {
expect(jasmineEnv.configuration().failFast).toBe(true)
expect(jasmineEnv.stopOnSpecFailure).not.toHaveBeenCalled()
} else {
expect(jasmineEnv.stopOnSpecFailure).toHaveBeenCalledWith(true)
}
})

it('should change timeoutInterval', function () {
Expand Down Expand Up @@ -601,18 +621,33 @@ describe('jasmine adapter', function () {
})

describe('createSpecFilter', function () {
var jasmineEnv

beforeEach(function () {
jasmineEnv = new jasmine.Env()
})

it('should create spec filter in jasmine', function () {
var jasmineEnvMock = {}
var karmaConfMock = {
args: ['--grep', 'test']
}
var specMock = {
getFullName: jasmine.createSpy('getFullName').and.returnValue('test')
}

createSpecFilter(karmaConfMock, jasmineEnvMock)
createSpecFilter(karmaConfMock, jasmineEnv)

var specFilter = typeof jasmineEnv.configuration === 'function'
? jasmineEnv.configuration().specFilter
: jasmineEnv.specFilter

// Jasmine's default specFilter **always** returns true
// so test multiple possibilities

expect(specFilter({
getFullName: jasmine.createSpy('getFullName').and.returnValue('test')
})).toEqual(true)

expect(jasmineEnvMock.specFilter(specMock)).toEqual(true)
expect(specFilter({
getFullName: jasmine.createSpy('getFullName2').and.returnValue('foo')
})).toEqual(false)
})
})
})

0 comments on commit 19b5dc7

Please sign in to comment.