From fce80bfdf66fa27100087b449ea77647d20b00f8 Mon Sep 17 00:00:00 2001 From: Gregg Van Hove Date: Thu, 29 Mar 2018 09:39:30 -0700 Subject: [PATCH] Add support for Jasmine 3.0 (#192) * 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 --- README.md | 3 ++- package.json | 4 +++- src/adapter.js | 7 ++++--- test/adapter.spec.js | 36 +++++++++++++++++++++++++++++++++--- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1235223..40369e5 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,8 @@ module.exports = function(config) { jasmine: { random: true, seed: '4321', - stopOnFailure: true + stopOnFailure: true, + failFast: true } } }) diff --git a/package.json b/package.json index b6662e6..1dc98eb 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,8 @@ "author": "Vojta Jina ", "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", @@ -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" diff --git a/src/adapter.js b/src/adapter.js index 61280ba..29c8995 100644 --- a/src/adapter.js +++ b/src/adapter.js @@ -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: [], @@ -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) @@ -356,7 +357,7 @@ function createStartFn (karma, jasmineEnv) { } function setOption (option, set) { - if (option != null) { + if (option != null && typeof set === 'function') { set(option) } } diff --git a/test/adapter.spec.js b/test/adapter.spec.js index 1920a91..52a0f6c 100644 --- a/test/adapter.spec.js +++ b/test/adapter.spec.js @@ -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' @@ -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') @@ -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 @@ -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'])