Skip to content

Commit

Permalink
Add support for Jasmine 3.0 (#192)
Browse files Browse the repository at this point in the history
* feat: Add support for Jasmine 3.0

Also check for `excluded` in addition to `disabled`, since Jasmine 3.0
only uses `excluded`. Add `failFast` support to `stopOnSpecFailure`, but
only set it if the Jasmine supports it. Use Jasmine 3.0 in tests, so
update to use `spyOn` for cleanup now that random is the default order.

* chore: lock to old conventional changelog for older node support
  • Loading branch information
Gregg Van Hove authored and johnjbarton committed Mar 29, 2018
1 parent 022ee04 commit fce80bf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -79,7 +79,8 @@ module.exports = function(config) {
jasmine: {
random: true,
seed: '4321',
stopOnFailure: true
stopOnFailure: true,
failFast: true
}
}
})
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -18,6 +18,8 @@
"author": "Vojta Jina <vojta.jina@gmail.com>",
"dependencies": {},
"devDependencies": {
"conventional-changelog": "1.1.7",
"conventional-changelog-core": "1.9.3",
"eslint-config-standard": "^5.1.0",
"eslint-plugin-promise": "^1.1.0",
"eslint-plugin-standard": "^1.3.2",
Expand All @@ -28,8 +30,8 @@
"grunt-eslint": "^18.0.0",
"grunt-karma": "2.x",
"grunt-npm": "0.0.2",
"jasmine-core": "~2.4.1",
"karma": "2.x || ",
"jasmine-core": "~3.0.0",
"karma-chrome-launcher": "1.x || ~0.2.2",
"karma-firefox-launcher": "1.x || ~0.1.7",
"load-grunt-tasks": "^3.4.1"
Expand Down
7 changes: 4 additions & 3 deletions src/adapter.js
Expand Up @@ -239,14 +239,14 @@ function KarmaReporter (tc, jasmineEnv) {
}

this.specDone = function (specResult) {
var skipped = specResult.status === 'disabled' || specResult.status === 'pending'
var skipped = specResult.status === 'disabled' || specResult.status === 'pending' || specResult.status === 'excluded'

var result = {
description: specResult.description,
id: specResult.id,
log: [],
skipped: skipped,
disabled: specResult.status === 'disabled',
disabled: specResult.status === 'disabled' || specResult.status === 'excluded',
pending: specResult.status === 'pending',
success: specResult.failedExpectations.length === 0,
suite: [],
Expand Down Expand Up @@ -348,6 +348,7 @@ 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)

Expand All @@ -356,7 +357,7 @@ function createStartFn (karma, jasmineEnv) {
}

function setOption (option, set) {
if (option != null) {
if (option != null && typeof set === 'function') {
set(option)
}
}
Expand Down
36 changes: 33 additions & 3 deletions test/adapter.spec.js
Expand Up @@ -110,6 +110,18 @@ describe('jasmine adapter', function () {
expect(karma.result).toHaveBeenCalled()
})

it('should report excluded status', function () {
spec.result.status = 'excluded'

karma.result.and.callFake(function (result) {
expect(result.skipped).toBe(true)
expect(result.disabled).toBe(true)
})

reporter.specDone(spec.result)
expect(karma.result).toHaveBeenCalled()
})

it('should report pending status', function () {
spec.result.status = 'pending'

Expand Down Expand Up @@ -399,6 +411,15 @@ describe('jasmine adapter', function () {
expect(jasmineEnv.throwOnExpectationFailure).toHaveBeenCalledWith(true)
})

it('should set failFast', function () {
jasmineConfig.failFast = true
spyOn(jasmineEnv, 'stopOnSpecFailure')

createStartFn(tc, jasmineEnv)()

expect(jasmineEnv.stopOnSpecFailure).toHaveBeenCalledWith(true)
})

it('should not set random order if client does not pass it', function () {
spyOn(jasmineEnv, 'randomizeTests')

Expand All @@ -407,6 +428,15 @@ describe('jasmine adapter', function () {
expect(jasmineEnv.randomizeTests).not.toHaveBeenCalled()
})

it('should not fail with failFast if the jasmineEnv does not support it', function () {
jasmineConfig.failFast = true
jasmineEnv.stopOnSpecFailure = null

expect(function () {
createStartFn(tc, jasmineEnv)()
}).not.toThrowError()
})

it('should not fail if client does not set config', function () {
tc.config = null

Expand Down Expand Up @@ -446,17 +476,17 @@ describe('jasmine adapter', function () {
})

it('should split by newline and return all values for which isExternalStackEntry returns true', function () {
isExternalStackEntry = jasmine.createSpy('isExternalStackEntry').and.returnValue(true)
spyOn(window, 'isExternalStackEntry').and.returnValue(true)
expect(getRelevantStackFrom('a\nb\nc')).toEqual(['a', 'b', 'c'])
})

it('should return the all stack entries if every entry is irrelevant', function () {
isExternalStackEntry = jasmine.createSpy('isExternalStackEntry').and.returnValue(false)
spyOn(window, 'isExternalStackEntry').and.returnValue(true)
expect(getRelevantStackFrom('a\nb\nc')).toEqual(['a', 'b', 'c'])
})

it('should return only the relevant stack entries if the stack contains relevant entries', function () {
isExternalStackEntry = jasmine.createSpy('isExternalStackEntry').and.callFake(function (entry) {
spyOn(window, 'isExternalStackEntry').and.callFake(function (entry) {
return entry !== 'b'
})
expect(getRelevantStackFrom('a\nb\nc')).toEqual(['a', 'c'])
Expand Down

0 comments on commit fce80bf

Please sign in to comment.