From b696bec9e373ecafe526c12f25d1d7012d7ecab3 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 31 Jul 2021 07:37:55 -0700 Subject: [PATCH 1/2] Renamed failFast and oneFailurePerSpec config props to stopOnSpecFailure and stopSpecOnExpectationFailure The new names are more self-explanatory and consistent with jasmine-npm. The old names are deprecated but still work. [#178682783] --- lib/jasmine-core/jasmine-html.js | 11 ++-- lib/jasmine-core/jasmine.js | 66 ++++++++++++++++++++++-- spec/core/EnvSpec.js | 62 ++++++++++++++++++++++ spec/core/integration/SpecRunningSpec.js | 53 +++++++++---------- spec/html/HtmlReporterSpec.js | 8 +-- src/core/Env.js | 66 ++++++++++++++++++++++-- src/html/HtmlReporter.js | 11 ++-- 7 files changed, 225 insertions(+), 52 deletions(-) diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index 79e0f451..8399eda4 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -558,17 +558,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 282b9fe4..ee4b2bfe 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1075,8 +1075,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 @@ -1093,8 +1102,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. @@ -1182,9 +1200,7 @@ getJasmineRequireObj().Env = function(j$) { this.configure = function(configuration) { var booleanProps = [ 'random', - 'failFast', 'failSpecWithNoExpectations', - 'oneFailurePerSpec', 'hideDisabled' ]; @@ -1194,6 +1210,46 @@ getJasmineRequireObj().Env = function(j$) { } }); + if (typeof configuration.failFast !== 'undefined') { + 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') { + 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; } @@ -1525,7 +1581,7 @@ getJasmineRequireObj().Env = function(j$) { this.deprecated( 'Setting stopOnSpecFailure directly is deprecated and will be removed in a future version of Jasmine, please use the failFast option in `configure`' ); - this.configure({ failFast: !!value }); + this.configure({ stopOnSpecFailure: !!value }); }; this.stoppingOnSpecFailure = function() { @@ -1619,9 +1675,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 a87c1328..d8a3d699 100644 --- a/spec/core/EnvSpec.js +++ b/spec/core/EnvSpec.js @@ -67,6 +67,8 @@ describe('Env', function() { failFast: true, failSpecWithNoExpectations: true, oneFailurePerSpec: true, + stopSpecOnExpectationFailure: true, + stopOnSpecFailure: true, hideDisabled: true }; env.configure(initialConfig); @@ -77,6 +79,8 @@ describe('Env', function() { failFast: undefined, failSpecWithNoExpectations: undefined, oneFailurePerSpec: undefined, + stopSpecOnExpectationFailure: undefined, + stopOnSpecFailure: undefined, hideDisabled: undefined }); @@ -85,6 +89,64 @@ describe('Env', function() { ); }); + it('sets stopOnSpecFailure when failFast is set, and vice versa', function() { + 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() { + 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('sets stopSpecOnExpectationFailure when oneFailurePerSpec is set, and vice versa', function() { + 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() { + 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.' + ); + }); + 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 d6e26104..d6dececd 100644 --- a/spec/core/integration/SpecRunningSpec.js +++ b/spec/core/integration/SpecRunningSpec.js @@ -980,35 +980,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 = []; - - env.describe('wrapper', function() { - env.it('fails', function() { - actions.push('fails'); - env.expect(1).toBe(2); - }); - }); - - env.describe('holder', function() { - env.it('does not run', function() { - actions.push('does not run'); - }); - }); - - env.configure({ random: false, failFast: true }); - - env.execute(null, function() { - expect(actions).toEqual(['fails']); - done(); - }); - }); - - it('does not run further specs when one fails when configured with deprecated option', function(done) { - var actions = []; - - spyOn(env, 'deprecated'); + var actions = [], + config; env.describe('wrapper', function() { env.it('fails', function() { @@ -1024,13 +999,31 @@ describe('spec running', function() { }); env.configure({ random: false }); - env.stopOnSpecFailure(true); + configureFn(env); env.execute(null, function() { expect(actions).toEqual(['fails']); - expect(env.deprecated).toHaveBeenCalled(); done(); }); }); + } + + describe('when failFast is on', function() { + behavesLikeStopOnSpecFailureIsOn(function(env) { + env.configure({ failFast: true }); + }); + }); + + describe('when stopOnSpecFailure is on', function() { + behavesLikeStopOnSpecFailureIsOn(function(env) { + env.configure({ stopOnSpecFailure: true }); + }); + }); + + describe('when stopOnSpecFailure is enabled via the deprecated method', function() { + behavesLikeStopOnSpecFailureIsOn(function(env) { + spyOn(env, 'deprecated'); + env.stopOnSpecFailure(true); + }); }); }); diff --git a/spec/html/HtmlReporterSpec.js b/spec/html/HtmlReporterSpec.js index 0e8e8e3d..5fef9a21 100644 --- a/spec/html/HtmlReporterSpec.js +++ b/spec/html/HtmlReporterSpec.js @@ -663,7 +663,7 @@ describe('HtmlReporter', function() { } }); - env.configure({ failFast: true }); + env.configure({ stopOnSpecFailure: true }); reporter.initialize(); reporter.jasmineDone({}); @@ -717,7 +717,7 @@ describe('HtmlReporter', function() { } }); - env.configure({ failFast: true }); + env.configure({ stopOnSpecFailure: true }); reporter.initialize(); reporter.jasmineDone({}); @@ -769,7 +769,7 @@ describe('HtmlReporter', function() { } }); - env.configure({ oneFailurePerSpec: true }); + env.configure({ stopSpecOnExpectationFailure: true }); reporter.initialize(); reporter.jasmineDone({}); @@ -823,7 +823,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 f4a36083..65c062bc 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. @@ -172,9 +190,7 @@ getJasmineRequireObj().Env = function(j$) { this.configure = function(configuration) { var booleanProps = [ 'random', - 'failFast', 'failSpecWithNoExpectations', - 'oneFailurePerSpec', 'hideDisabled' ]; @@ -184,6 +200,46 @@ getJasmineRequireObj().Env = function(j$) { } }); + if (typeof configuration.failFast !== 'undefined') { + 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') { + 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; } @@ -515,7 +571,7 @@ getJasmineRequireObj().Env = function(j$) { this.deprecated( 'Setting stopOnSpecFailure directly is deprecated and will be removed in a future version of Jasmine, please use the failFast option in `configure`' ); - this.configure({ failFast: !!value }); + this.configure({ stopOnSpecFailure: !!value }); }; this.stoppingOnSpecFailure = function() { @@ -609,9 +665,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 77e345cb..dc91c4dc 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -527,17 +527,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( From dcaac62a6c94181d89bc406bfd1040b22d920dbf Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 31 Jul 2021 08:02:39 -0700 Subject: [PATCH 2/2] Updated deprecaton messages for Env#throwOnExpectationFailure() and Env#stopOnSpecFailure() --- lib/jasmine-core/jasmine.js | 20 ++++++++++++++------ src/core/Env.js | 20 ++++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index ee4b2bfe..bed18d89 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1553,18 +1553,22 @@ getJasmineRequireObj().Env = function(j$) { * @since 2.3.0 * @function * @param {Boolean} value Whether to throw when a expectation fails - * @deprecated Use the `oneFailurePerSpec` option with {@link Env#configure} + * @deprecated Use the `stopSpecOnExpectationFailure` option with {@link Env#configure} */ this.throwOnExpectationFailure = function(value) { this.deprecated( - 'Setting throwOnExpectationFailure directly on Env is deprecated and will be removed in a future version of Jasmine, please use the oneFailurePerSpec option in `configure`' + 'Setting throwOnExpectationFailure directly on Env is deprecated and ' + + 'will be removed in a future version of Jasmine. Please use the ' + + 'stopSpecOnExpectationFailure option in `configure`.' ); this.configure({ oneFailurePerSpec: !!value }); }; this.throwingExpectationFailures = function() { this.deprecated( - 'Getting throwingExpectationFailures directly from Env is deprecated and will be removed in a future version of Jasmine, please check the oneFailurePerSpec option from `configuration`' + 'Getting throwingExpectationFailures directly from Env is deprecated ' + + 'and will be removed in a future version of Jasmine. Please check ' + + 'the stopSpecOnExpectationFailure option from `configuration`.' ); return config.oneFailurePerSpec; }; @@ -1575,18 +1579,22 @@ getJasmineRequireObj().Env = function(j$) { * @since 2.7.0 * @function * @param {Boolean} value Whether to stop suite execution when a spec fails - * @deprecated Use the `failFast` option with {@link Env#configure} + * @deprecated Use the `stopOnSpecFailure` option with {@link Env#configure} */ this.stopOnSpecFailure = function(value) { this.deprecated( - 'Setting stopOnSpecFailure directly is deprecated and will be removed in a future version of Jasmine, please use the failFast option in `configure`' + 'Setting stopOnSpecFailure directly is deprecated and will be ' + + 'removed in a future version of Jasmine. Please use the ' + + 'stopOnSpecFailure option in `configure`.' ); this.configure({ stopOnSpecFailure: !!value }); }; this.stoppingOnSpecFailure = function() { this.deprecated( - 'Getting stoppingOnSpecFailure directly from Env is deprecated and will be removed in a future version of Jasmine, please check the failFast option from `configuration`' + 'Getting stoppingOnSpecFailure directly from Env is deprecated and ' + + 'will be removed in a future version of Jasmine. Please check the ' + + 'stopOnSpecFailure option from `configuration`.' ); return config.failFast; }; diff --git a/src/core/Env.js b/src/core/Env.js index 65c062bc..18d1157d 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -543,18 +543,22 @@ getJasmineRequireObj().Env = function(j$) { * @since 2.3.0 * @function * @param {Boolean} value Whether to throw when a expectation fails - * @deprecated Use the `oneFailurePerSpec` option with {@link Env#configure} + * @deprecated Use the `stopSpecOnExpectationFailure` option with {@link Env#configure} */ this.throwOnExpectationFailure = function(value) { this.deprecated( - 'Setting throwOnExpectationFailure directly on Env is deprecated and will be removed in a future version of Jasmine, please use the oneFailurePerSpec option in `configure`' + 'Setting throwOnExpectationFailure directly on Env is deprecated and ' + + 'will be removed in a future version of Jasmine. Please use the ' + + 'stopSpecOnExpectationFailure option in `configure`.' ); this.configure({ oneFailurePerSpec: !!value }); }; this.throwingExpectationFailures = function() { this.deprecated( - 'Getting throwingExpectationFailures directly from Env is deprecated and will be removed in a future version of Jasmine, please check the oneFailurePerSpec option from `configuration`' + 'Getting throwingExpectationFailures directly from Env is deprecated ' + + 'and will be removed in a future version of Jasmine. Please check ' + + 'the stopSpecOnExpectationFailure option from `configuration`.' ); return config.oneFailurePerSpec; }; @@ -565,18 +569,22 @@ getJasmineRequireObj().Env = function(j$) { * @since 2.7.0 * @function * @param {Boolean} value Whether to stop suite execution when a spec fails - * @deprecated Use the `failFast` option with {@link Env#configure} + * @deprecated Use the `stopOnSpecFailure` option with {@link Env#configure} */ this.stopOnSpecFailure = function(value) { this.deprecated( - 'Setting stopOnSpecFailure directly is deprecated and will be removed in a future version of Jasmine, please use the failFast option in `configure`' + 'Setting stopOnSpecFailure directly is deprecated and will be ' + + 'removed in a future version of Jasmine. Please use the ' + + 'stopOnSpecFailure option in `configure`.' ); this.configure({ stopOnSpecFailure: !!value }); }; this.stoppingOnSpecFailure = function() { this.deprecated( - 'Getting stoppingOnSpecFailure directly from Env is deprecated and will be removed in a future version of Jasmine, please check the failFast option from `configuration`' + 'Getting stoppingOnSpecFailure directly from Env is deprecated and ' + + 'will be removed in a future version of Jasmine. Please check the ' + + 'stopOnSpecFailure option from `configuration`.' ); return config.failFast; };