diff --git a/lib/jasmine-core/boot/boot1.js b/lib/jasmine-core/boot/boot1.js index 60663cde..f0a085e0 100644 --- a/lib/jasmine-core/boot/boot1.js +++ b/lib/jasmine-core/boot/boot1.js @@ -27,8 +27,8 @@ var filterSpecs = !!queryString.getParam("spec"); var config = { - failFast: queryString.getParam("failFast"), - oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"), + stopOnSpecFailure: queryString.getParam("failFast"), + stopSpecOnExpectationFailure: queryString.getParam("oneFailurePerSpec"), hideDisabled: queryString.getParam("hideDisabled") }; diff --git a/lib/jasmine-core/boot1.js b/lib/jasmine-core/boot1.js index 5a6a5647..940bb087 100644 --- a/lib/jasmine-core/boot1.js +++ b/lib/jasmine-core/boot1.js @@ -49,8 +49,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. var filterSpecs = !!queryString.getParam("spec"); var config = { - failFast: queryString.getParam("failFast"), - oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"), + stopOnSpecFailure: queryString.getParam("failFast"), + stopSpecOnExpectationFailure: queryString.getParam("oneFailurePerSpec"), hideDisabled: queryString.getParam("hideDisabled") }; diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index 43edd002..2eb408cf 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -569,17 +569,20 @@ jasmineRequire.HtmlReporter = function(j$) { ); var failFastCheckbox = optionsMenuDom.querySelector('#jasmine-fail-fast'); - failFastCheckbox.checked = config.failFast; + failFastCheckbox.checked = config.stopOnSpecFailure; failFastCheckbox.onclick = function() { - navigateWithNewParam('failFast', !config.failFast); + navigateWithNewParam('failFast', !config.stopOnSpecFailure); }; var throwCheckbox = optionsMenuDom.querySelector( '#jasmine-throw-failures' ); - throwCheckbox.checked = config.oneFailurePerSpec; + throwCheckbox.checked = config.stopSpecOnExpectationFailure; throwCheckbox.onclick = function() { - navigateWithNewParam('oneFailurePerSpec', !config.oneFailurePerSpec); + navigateWithNewParam( + 'oneFailurePerSpec', + !config.stopSpecOnExpectationFailure + ); }; var randomCheckbox = optionsMenuDom.querySelector( diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index fef0a9e6..b0fff9fb 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1042,8 +1042,17 @@ getJasmineRequireObj().Env = function(j$) { * @since 3.3.0 * @type Boolean * @default false + * @deprecated Use the `stopOnSpecFailure` config property instead. */ failFast: false, + /** + * Whether to stop execution of the suite after the first spec failure + * @name Configuration#stopOnSpecFailure + * @since 3.9.0 + * @type Boolean + * @default false + */ + stopOnSpecFailure: false, /** * Whether to fail the spec if it ran no expectations. By default * a spec that ran no expectations is reported as passed. Setting this @@ -1060,8 +1069,17 @@ getJasmineRequireObj().Env = function(j$) { * @since 3.3.0 * @type Boolean * @default false + * @deprecated Use the `stopSpecOnExpectationFailure` config property instead. */ oneFailurePerSpec: false, + /** + * Whether to cause specs to only have one expectation failure. + * @name Configuration#stopSpecOnExpectationFailure + * @since 3.3.0 + * @type Boolean + * @default false + */ + stopSpecOnExpectationFailure: false, /** * A function that takes a spec and returns true if it should be executed * or false if it should be skipped. @@ -1161,9 +1179,7 @@ getJasmineRequireObj().Env = function(j$) { this.configure = function(configuration) { var booleanProps = [ 'random', - 'failFast', 'failSpecWithNoExpectations', - 'oneFailurePerSpec', 'hideDisabled' ]; @@ -1173,6 +1189,70 @@ 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( + 'stopOnSpecFailure and failFast are aliases for ' + + "each other. Don't set failFast if you also set stopOnSpecFailure." + ); + } + } + + config.failFast = configuration.failFast; + config.stopOnSpecFailure = configuration.failFast; + } else if (typeof configuration.stopOnSpecFailure !== 'undefined') { + config.failFast = configuration.stopOnSpecFailure; + config.stopOnSpecFailure = configuration.stopOnSpecFailure; + } + + 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 !== + configuration.oneFailurePerSpec + ) { + throw new Error( + 'stopSpecOnExpectationFailure and oneFailurePerSpec are aliases for ' + + "each other. Don't set oneFailurePerSpec if you also set stopSpecOnExpectationFailure." + ); + } + } + + config.oneFailurePerSpec = configuration.oneFailurePerSpec; + config.stopSpecOnExpectationFailure = configuration.oneFailurePerSpec; + } else if ( + typeof configuration.stopSpecOnExpectationFailure !== 'undefined' + ) { + config.oneFailurePerSpec = configuration.stopSpecOnExpectationFailure; + config.stopSpecOnExpectationFailure = + configuration.stopSpecOnExpectationFailure; + } + if (configuration.specFilter) { config.specFilter = configuration.specFilter; } @@ -1484,9 +1564,9 @@ getJasmineRequireObj().Env = function(j$) { var queueRunnerFactory = function(options, args) { var failFast = false; if (options.isLeaf) { - failFast = config.oneFailurePerSpec; + failFast = config.stopSpecOnExpectationFailure; } else if (!options.isReporter) { - failFast = config.failFast; + failFast = config.stopOnSpecFailure; } options.clearStack = options.clearStack || clearStack; options.timeout = { diff --git a/spec/core/EnvSpec.js b/spec/core/EnvSpec.js index ae790a9c..514192fe 100644 --- a/spec/core/EnvSpec.js +++ b/spec/core/EnvSpec.js @@ -88,7 +88,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').and.callThrough(); env.it('foo', function() {}); @@ -100,7 +100,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() {}); @@ -112,12 +112,15 @@ describe('Env', function() { }); it('ignores configuration properties that are present but undefined', function() { + spyOn(env, 'deprecated'); var initialConfig = { random: true, seed: '123', failFast: true, failSpecWithNoExpectations: true, oneFailurePerSpec: true, + stopSpecOnExpectationFailure: true, + stopOnSpecFailure: true, hideDisabled: true }; env.configure(initialConfig); @@ -128,6 +131,8 @@ describe('Env', function() { failFast: undefined, failSpecWithNoExpectations: undefined, oneFailurePerSpec: undefined, + stopSpecOnExpectationFailure: undefined, + stopOnSpecFailure: undefined, hideDisabled: undefined }); @@ -136,6 +141,89 @@ 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({ + failFast: true, + stopOnSpecFailure: true + }) + ); + + env.configure({ stopOnSpecFailure: false }); + expect(env.configuration()).toEqual( + jasmine.objectContaining({ + failFast: false, + stopOnSpecFailure: false + }) + ); + }); + + 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( + 'stopOnSpecFailure and failFast are aliases for each ' + + "other. Don't set failFast if you also set stopOnSpecFailure." + ); + }); + + 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({ + oneFailurePerSpec: true, + stopSpecOnExpectationFailure: true + }) + ); + + env.configure({ stopSpecOnExpectationFailure: false }); + expect(env.configuration()).toEqual( + jasmine.objectContaining({ + oneFailurePerSpec: false, + stopSpecOnExpectationFailure: false + }) + ); + }); + + it('rejects a single call that sets stopSpecOnExpectationFailure and oneFailurePerSpec to different values', function() { + spyOn(env, 'deprecated'); + expect(function() { + env.configure({ + oneFailurePerSpec: true, + stopSpecOnExpectationFailure: false + }); + }).toThrowError( + 'stopSpecOnExpectationFailure and oneFailurePerSpec are ' + + "aliases for each other. Don't set oneFailurePerSpec if you also set " + + 'stopSpecOnExpectationFailure.' + ); + }); + + 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 96c80bb2..e2a91b76 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']); @@ -886,9 +886,10 @@ describe('spec running', function() { }); }); - describe('when stopOnSpecFailure is on', function() { + function behavesLikeStopOnSpecFailureIsOn(configureFn) { it('does not run further specs when one fails', function(done) { - var actions = []; + var actions = [], + config; env.describe('wrapper', function() { env.it('fails', function() { @@ -903,12 +904,26 @@ describe('spec running', function() { }); }); - env.configure({ random: false, failFast: true }); + env.configure({ random: false }); + configureFn(env); env.execute(null, function() { expect(actions).toEqual(['fails']); done(); }); }); + } + + describe('when failFast is on', function() { + behavesLikeStopOnSpecFailureIsOn(function(env) { + spyOn(env, 'deprecated'); + env.configure({ failFast: true }); + }); + }); + + describe('when stopOnSpecFailure is on', function() { + behavesLikeStopOnSpecFailureIsOn(function(env) { + env.configure({ stopOnSpecFailure: true }); + }); }); }); diff --git a/spec/html/HtmlReporterSpec.js b/spec/html/HtmlReporterSpec.js index a245e82d..d098fbc1 100644 --- a/spec/html/HtmlReporterSpec.js +++ b/spec/html/HtmlReporterSpec.js @@ -785,7 +785,7 @@ describe('HtmlReporter', function() { } }); - env.configure({ failFast: true }); + env.configure({ stopOnSpecFailure: true }); reporter.initialize(); reporter.jasmineDone({}); @@ -839,7 +839,7 @@ describe('HtmlReporter', function() { } }); - env.configure({ failFast: true }); + env.configure({ stopOnSpecFailure: true }); reporter.initialize(); reporter.jasmineDone({}); @@ -891,7 +891,7 @@ describe('HtmlReporter', function() { } }); - env.configure({ oneFailurePerSpec: true }); + env.configure({ stopSpecOnExpectationFailure: true }); reporter.initialize(); reporter.jasmineDone({}); @@ -945,7 +945,7 @@ describe('HtmlReporter', function() { } }); - env.configure({ oneFailurePerSpec: true }); + env.configure({ stopSpecOnExpectationFailure: true }); reporter.initialize(); reporter.jasmineDone({}); diff --git a/src/core/Env.js b/src/core/Env.js index d019fc4b..189f5abb 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -65,8 +65,17 @@ getJasmineRequireObj().Env = function(j$) { * @since 3.3.0 * @type Boolean * @default false + * @deprecated Use the `stopOnSpecFailure` config property instead. */ failFast: false, + /** + * Whether to stop execution of the suite after the first spec failure + * @name Configuration#stopOnSpecFailure + * @since 3.9.0 + * @type Boolean + * @default false + */ + stopOnSpecFailure: false, /** * Whether to fail the spec if it ran no expectations. By default * a spec that ran no expectations is reported as passed. Setting this @@ -83,8 +92,17 @@ getJasmineRequireObj().Env = function(j$) { * @since 3.3.0 * @type Boolean * @default false + * @deprecated Use the `stopSpecOnExpectationFailure` config property instead. */ oneFailurePerSpec: false, + /** + * Whether to cause specs to only have one expectation failure. + * @name Configuration#stopSpecOnExpectationFailure + * @since 3.3.0 + * @type Boolean + * @default false + */ + stopSpecOnExpectationFailure: false, /** * A function that takes a spec and returns true if it should be executed * or false if it should be skipped. @@ -184,9 +202,7 @@ getJasmineRequireObj().Env = function(j$) { this.configure = function(configuration) { var booleanProps = [ 'random', - 'failFast', 'failSpecWithNoExpectations', - 'oneFailurePerSpec', 'hideDisabled' ]; @@ -196,6 +212,70 @@ 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( + 'stopOnSpecFailure and failFast are aliases for ' + + "each other. Don't set failFast if you also set stopOnSpecFailure." + ); + } + } + + config.failFast = configuration.failFast; + config.stopOnSpecFailure = configuration.failFast; + } else if (typeof configuration.stopOnSpecFailure !== 'undefined') { + config.failFast = configuration.stopOnSpecFailure; + config.stopOnSpecFailure = configuration.stopOnSpecFailure; + } + + 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 !== + configuration.oneFailurePerSpec + ) { + throw new Error( + 'stopSpecOnExpectationFailure and oneFailurePerSpec are aliases for ' + + "each other. Don't set oneFailurePerSpec if you also set stopSpecOnExpectationFailure." + ); + } + } + + config.oneFailurePerSpec = configuration.oneFailurePerSpec; + config.stopSpecOnExpectationFailure = configuration.oneFailurePerSpec; + } else if ( + typeof configuration.stopSpecOnExpectationFailure !== 'undefined' + ) { + config.oneFailurePerSpec = configuration.stopSpecOnExpectationFailure; + config.stopSpecOnExpectationFailure = + configuration.stopSpecOnExpectationFailure; + } + if (configuration.specFilter) { config.specFilter = configuration.specFilter; } @@ -507,9 +587,9 @@ getJasmineRequireObj().Env = function(j$) { var queueRunnerFactory = function(options, args) { var failFast = false; if (options.isLeaf) { - failFast = config.oneFailurePerSpec; + failFast = config.stopSpecOnExpectationFailure; } else if (!options.isReporter) { - failFast = config.failFast; + failFast = config.stopOnSpecFailure; } options.clearStack = options.clearStack || clearStack; options.timeout = { diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js index 86061385..ac5a4213 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -538,17 +538,20 @@ jasmineRequire.HtmlReporter = function(j$) { ); var failFastCheckbox = optionsMenuDom.querySelector('#jasmine-fail-fast'); - failFastCheckbox.checked = config.failFast; + failFastCheckbox.checked = config.stopOnSpecFailure; failFastCheckbox.onclick = function() { - navigateWithNewParam('failFast', !config.failFast); + navigateWithNewParam('failFast', !config.stopOnSpecFailure); }; var throwCheckbox = optionsMenuDom.querySelector( '#jasmine-throw-failures' ); - throwCheckbox.checked = config.oneFailurePerSpec; + throwCheckbox.checked = config.stopSpecOnExpectationFailure; throwCheckbox.onclick = function() { - navigateWithNewParam('oneFailurePerSpec', !config.oneFailurePerSpec); + navigateWithNewParam( + 'oneFailurePerSpec', + !config.stopSpecOnExpectationFailure + ); }; var randomCheckbox = optionsMenuDom.querySelector(