From 20b914c55406cf7ca6d91bcc2d6a8cb334668f84 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 31 Jul 2021 08:42:01 -0700 Subject: [PATCH] Deprecated the failFast and oneFailurePerSpec config properties --- lib/jasmine-core/jasmine.js | 24 +++++++++++++++++++ spec/core/EnvSpec.js | 30 ++++++++++++++++++++++-- spec/core/integration/SpecRunningSpec.js | 9 +++---- src/core/Env.js | 24 +++++++++++++++++++ 4 files changed, 81 insertions(+), 6 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index cd065645..67d2f066 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1251,6 +1251,18 @@ getJasmineRequireObj().Env = function(j$) { }); if (typeof configuration.failFast !== 'undefined') { + // We can't unconditionally issue a warning here because then users who + // get the configuration from Jasmine, modify it, and pass it back would + // see the warning. + if (configuration.failFast !== config.failFast) { + this.deprecated( + 'The `failFast` config property is deprecated and will be removed ' + + 'in a future version of Jasmine. Please use `stopOnSpecFailure` ' + + 'instead.', + { ignoreRunnable: true } + ); + } + if (typeof configuration.stopOnSpecFailure !== 'undefined') { if (configuration.stopOnSpecFailure !== configuration.failFast) { throw new Error( @@ -1268,6 +1280,18 @@ getJasmineRequireObj().Env = function(j$) { } if (typeof configuration.oneFailurePerSpec !== 'undefined') { + // We can't unconditionally issue a warning here because then users who + // get the configuration from Jasmine, modify it, and pass it back would + // see the warning. + if (configuration.oneFailurePerSpec !== config.oneFailurePerSpec) { + this.deprecated( + 'The `oneFailurePerSpec` config property is deprecated and will be ' + + 'removed in a future version of Jasmine. Please use ' + + '`stopSpecOnExpectationFailure` instead.', + { ignoreRunnable: true } + ); + } + if (typeof configuration.stopSpecOnExpectationFailure !== 'undefined') { if ( configuration.stopSpecOnExpectationFailure !== diff --git a/spec/core/EnvSpec.js b/spec/core/EnvSpec.js index 97b73575..9ebbda0d 100644 --- a/spec/core/EnvSpec.js +++ b/spec/core/EnvSpec.js @@ -256,7 +256,7 @@ describe('Env', function() { }); it('can configure specs to throw errors on expectation failures', function() { - env.configure({ oneFailurePerSpec: true }); + env.configure({ stopSpecOnExpectationFailure: true }); spyOn(jasmineUnderTest, 'Spec'); env.it('foo', function() {}); @@ -268,7 +268,7 @@ describe('Env', function() { }); it('can configure suites to throw errors on expectation failures', function() { - env.configure({ oneFailurePerSpec: true }); + env.configure({ stopSpecOnExpectationFailure: true }); spyOn(jasmineUnderTest, 'Suite'); env.describe('foo', function() {}); @@ -280,6 +280,7 @@ describe('Env', function() { }); it('ignores configuration properties that are present but undefined', function() { + spyOn(env, 'deprecated'); var initialConfig = { random: true, seed: '123', @@ -309,6 +310,7 @@ describe('Env', function() { }); it('sets stopOnSpecFailure when failFast is set, and vice versa', function() { + spyOn(env, 'deprecated'); env.configure({ failFast: true }); expect(env.configuration()).toEqual( jasmine.objectContaining({ @@ -327,6 +329,7 @@ describe('Env', function() { }); it('rejects a single call that sets stopOnSpecFailure and failFast to different values', function() { + spyOn(env, 'deprecated'); expect(function() { env.configure({ failFast: true, stopOnSpecFailure: false }); }).toThrowError( @@ -335,7 +338,18 @@ describe('Env', function() { ); }); + it('deprecates the failFast config property', function() { + spyOn(env, 'deprecated'); + env.configure({ failFast: true }); + expect(env.deprecated).toHaveBeenCalledWith( + 'The `failFast` config property is deprecated and will be removed in a ' + + 'future version of Jasmine. Please use `stopOnSpecFailure` instead.', + { ignoreRunnable: true } + ); + }); + it('sets stopSpecOnExpectationFailure when oneFailurePerSpec is set, and vice versa', function() { + spyOn(env, 'deprecated'); env.configure({ oneFailurePerSpec: true }); expect(env.configuration()).toEqual( jasmine.objectContaining({ @@ -354,6 +368,7 @@ describe('Env', function() { }); it('rejects a single call that sets stopSpecOnExpectationFailure and oneFailurePerSpec to different values', function() { + spyOn(env, 'deprecated'); expect(function() { env.configure({ oneFailurePerSpec: true, @@ -366,6 +381,17 @@ describe('Env', function() { ); }); + it('deprecates the oneFailurePerSpec config property', function() { + spyOn(env, 'deprecated'); + env.configure({ oneFailurePerSpec: true }); + expect(env.deprecated).toHaveBeenCalledWith( + 'The `oneFailurePerSpec` config property is deprecated and will be ' + + 'removed in a future version of Jasmine. Please use ' + + '`stopSpecOnExpectationFailure` instead.', + { ignoreRunnable: true } + ); + }); + describe('promise library', function() { it('can be configured without a custom library', function() { env.configure({}); diff --git a/spec/core/integration/SpecRunningSpec.js b/spec/core/integration/SpecRunningSpec.js index bb2604a0..c981df99 100644 --- a/spec/core/integration/SpecRunningSpec.js +++ b/spec/core/integration/SpecRunningSpec.js @@ -792,7 +792,7 @@ describe('spec running', function() { }); }); - describe('When throwOnExpectationFailure is set', function() { + describe('When stopSpecOnExpectationFailure is set', function() { it('skips to cleanup functions after an error', function(done) { var actions = []; @@ -821,7 +821,7 @@ describe('spec running', function() { }); }); - env.configure({ oneFailurePerSpec: true }); + env.configure({ stopSpecOnExpectationFailure: true }); env.execute(null, function() { expect(actions).toEqual([ @@ -852,7 +852,7 @@ describe('spec running', function() { }); }); - env.configure({ oneFailurePerSpec: true }); + env.configure({ stopSpecOnExpectationFailure: true }); env.execute(null, function() { expect(actions).toEqual(['beforeEach', 'afterEach']); @@ -877,7 +877,7 @@ describe('spec running', function() { }); }); - env.configure({ oneFailurePerSpec: true }); + env.configure({ stopSpecOnExpectationFailure: true }); env.execute(null, function() { expect(actions).toEqual(['beforeEach', 'afterEach']); @@ -1017,6 +1017,7 @@ describe('spec running', function() { describe('when failFast is on', function() { behavesLikeStopOnSpecFailureIsOn(function(env) { + spyOn(env, 'deprecated'); env.configure({ failFast: true }); }); }); diff --git a/src/core/Env.js b/src/core/Env.js index 77e888c3..38471f96 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -213,6 +213,18 @@ getJasmineRequireObj().Env = function(j$) { }); if (typeof configuration.failFast !== 'undefined') { + // We can't unconditionally issue a warning here because then users who + // get the configuration from Jasmine, modify it, and pass it back would + // see the warning. + if (configuration.failFast !== config.failFast) { + this.deprecated( + 'The `failFast` config property is deprecated and will be removed ' + + 'in a future version of Jasmine. Please use `stopOnSpecFailure` ' + + 'instead.', + { ignoreRunnable: true } + ); + } + if (typeof configuration.stopOnSpecFailure !== 'undefined') { if (configuration.stopOnSpecFailure !== configuration.failFast) { throw new Error( @@ -230,6 +242,18 @@ getJasmineRequireObj().Env = function(j$) { } if (typeof configuration.oneFailurePerSpec !== 'undefined') { + // We can't unconditionally issue a warning here because then users who + // get the configuration from Jasmine, modify it, and pass it back would + // see the warning. + if (configuration.oneFailurePerSpec !== config.oneFailurePerSpec) { + this.deprecated( + 'The `oneFailurePerSpec` config property is deprecated and will be ' + + 'removed in a future version of Jasmine. Please use ' + + '`stopSpecOnExpectationFailure` instead.', + { ignoreRunnable: true } + ); + } + if (typeof configuration.stopSpecOnExpectationFailure !== 'undefined') { if ( configuration.stopSpecOnExpectationFailure !==