From 43073b3bc537fbb1de3a51348e4d1ff515c33aa4 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Thu, 29 Jul 2021 19:32:15 -0700 Subject: [PATCH 1/3] Added API docs for Suite#id and Spec#id These properties are the only way to obtain runnable IDs, without which you can't call the form of Env#execute that takes an array of IDs. --- lib/jasmine-core/jasmine.js | 12 ++++++++++++ src/core/Spec.js | 6 ++++++ src/core/Suite.js | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index df224cb8..282b9fe4 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -712,6 +712,12 @@ getJasmineRequireObj().Spec = function(j$) { this.expectationFactory = attrs.expectationFactory; this.asyncExpectationFactory = attrs.asyncExpectationFactory; this.resultCallback = attrs.resultCallback || function() {}; + /** + * The unique ID of this spec. + * @name Spec#id + * @readonly + * @type {string} + */ this.id = attrs.id; /** * The description passed to the {@link it} that created this spec. @@ -9242,6 +9248,12 @@ getJasmineRequireObj().Suite = function(j$) { */ function Suite(attrs) { this.env = attrs.env; + /** + * The unique ID of this suite. + * @name Suite#id + * @readonly + * @type {string} + */ this.id = attrs.id; /** * The parent of this suite, or null if this is the top suite. diff --git a/src/core/Spec.js b/src/core/Spec.js index 81d244dd..826f7157 100644 --- a/src/core/Spec.js +++ b/src/core/Spec.js @@ -7,6 +7,12 @@ getJasmineRequireObj().Spec = function(j$) { this.expectationFactory = attrs.expectationFactory; this.asyncExpectationFactory = attrs.asyncExpectationFactory; this.resultCallback = attrs.resultCallback || function() {}; + /** + * The unique ID of this spec. + * @name Spec#id + * @readonly + * @type {string} + */ this.id = attrs.id; /** * The description passed to the {@link it} that created this spec. diff --git a/src/core/Suite.js b/src/core/Suite.js index 5043017b..c3e475bd 100644 --- a/src/core/Suite.js +++ b/src/core/Suite.js @@ -5,6 +5,12 @@ getJasmineRequireObj().Suite = function(j$) { */ function Suite(attrs) { this.env = attrs.env; + /** + * The unique ID of this suite. + * @name Suite#id + * @readonly + * @type {string} + */ this.id = attrs.id; /** * The parent of this suite, or null if this is the top suite. From 2a2a671b6577bd0cb99024f70b2fe9127888c268 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Thu, 29 Jul 2021 20:15:04 -0700 Subject: [PATCH 2/3] Don't deprecate access to Suite#id and Spec#id --- lib/jasmine-core/jasmine.js | 3 ++- spec/core/EnvSpec.js | 3 +++ src/core/deprecatingSpecProxy.js | 2 +- src/core/deprecatingSuiteProxy.js | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index c35c614b..f2c44c62 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -3736,7 +3736,7 @@ getJasmineRequireObj().deprecatingSpecProxy = function(j$) { } function isAllowedMember(prop) { - return prop === 'description' || prop === 'getFullName'; + return prop === 'id' || prop === 'description' || prop === 'getFullName'; } function msg(member) { @@ -3800,6 +3800,7 @@ getJasmineRequireObj().deprecatingSpecProxy = function(j$) { // TODO: Remove this in the next major release. getJasmineRequireObj().deprecatingSuiteProxy = function(j$) { var allowedMembers = [ + 'id', 'children', 'description', 'parentSuite', diff --git a/spec/core/EnvSpec.js b/spec/core/EnvSpec.js index 4c1faeb3..d8151ef9 100644 --- a/spec/core/EnvSpec.js +++ b/spec/core/EnvSpec.js @@ -87,14 +87,17 @@ describe('Env', function() { }); suite = env.topSuite(); + suite.id; suite.description; suite.getFullName(); suite.children; suite.parentSuite; + suite.children[0].id; suite.children[0].description; suite.children[0].getFullName(); suite.children[0].children; + suite.children[1].id; suite.children[1].description; suite.children[1].getFullName(); suite.children[1].parentSuite; diff --git a/src/core/deprecatingSpecProxy.js b/src/core/deprecatingSpecProxy.js index c490705f..710c86c4 100644 --- a/src/core/deprecatingSpecProxy.js +++ b/src/core/deprecatingSpecProxy.js @@ -9,7 +9,7 @@ getJasmineRequireObj().deprecatingSpecProxy = function(j$) { } function isAllowedMember(prop) { - return prop === 'description' || prop === 'getFullName'; + return prop === 'id' || prop === 'description' || prop === 'getFullName'; } function msg(member) { diff --git a/src/core/deprecatingSuiteProxy.js b/src/core/deprecatingSuiteProxy.js index 10c3f314..d92aac8b 100644 --- a/src/core/deprecatingSuiteProxy.js +++ b/src/core/deprecatingSuiteProxy.js @@ -2,6 +2,7 @@ // TODO: Remove this in the next major release. getJasmineRequireObj().deprecatingSuiteProxy = function(j$) { var allowedMembers = [ + 'id', 'children', 'description', 'parentSuite', From 799d9897fd2810932833066bd68871b454dbaa56 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Thu, 29 Jul 2021 21:28:47 -0700 Subject: [PATCH 3/3] Deprecated access to non-public members in specs and suites returned from it(), describe(), etc. --- lib/jasmine-core/jasmine.js | 24 ++++-- spec/core/EnvSpec.js | 100 +++++++++++++++++++++-- spec/core/integration/SpecRunningSpec.js | 11 ++- src/core/Env.js | 20 +++-- src/core/deprecatingSpecProxy.js | 2 +- src/core/deprecatingSuiteProxy.js | 2 +- 6 files changed, 131 insertions(+), 28 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index f2c44c62..39fd9d0b 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2155,7 +2155,7 @@ getJasmineRequireObj().Env = function(j$) { 'Please either remove the describe or add children to it.' ); } - return suite; + return j$.deprecatingSuiteProxy(suite, suite.parentSuite, this); }; this.xdescribe = function(description, specDefinitions) { @@ -2164,7 +2164,7 @@ getJasmineRequireObj().Env = function(j$) { var suite = suiteFactory(description); suite.pend(); addSpecsToSuite(suite, specDefinitions); - return suite; + return j$.deprecatingSuiteProxy(suite, suite.parentSuite, this); }; var focusedRunnables = []; @@ -2179,7 +2179,7 @@ getJasmineRequireObj().Env = function(j$) { unfocusAncestor(); addSpecsToSuite(suite, specDefinitions); - return suite; + return j$.deprecatingSuiteProxy(suite, suite.parentSuite, this); }; function addSpecsToSuite(suite, specDefinitions) { @@ -2269,7 +2269,7 @@ getJasmineRequireObj().Env = function(j$) { } }; - this.it = function(description, fn, timeout) { + this.it_ = function(description, fn, timeout) { ensureIsNotNested('it'); // it() sometimes doesn't have a fn argument, so only check the type if // it's given. @@ -2281,9 +2281,15 @@ getJasmineRequireObj().Env = function(j$) { spec.pend(); } currentDeclarationSuite.addChild(spec); + return spec; }; + this.it = function(description, fn, timeout) { + var spec = this.it_(description, fn, timeout); + return j$.deprecatingSpecProxy(spec, this); + }; + this.xit = function(description, fn, timeout) { ensureIsNotNested('xit'); // xit(), like it(), doesn't always have a fn argument, so only check the @@ -2291,9 +2297,9 @@ getJasmineRequireObj().Env = function(j$) { if (arguments.length > 1 && typeof fn !== 'undefined') { ensureIsFunctionOrAsync(fn, 'xit'); } - var spec = this.it.apply(this, arguments); + var spec = this.it_.apply(this, arguments); spec.pend('Temporarily disabled with xit'); - return spec; + return j$.deprecatingSpecProxy(spec, this); }; this.fit = function(description, fn, timeout) { @@ -2303,7 +2309,7 @@ getJasmineRequireObj().Env = function(j$) { currentDeclarationSuite.addChild(spec); focusedRunnables.push(spec.id); unfocusAncestor(); - return spec; + return j$.deprecatingSpecProxy(spec, this); }; /** @@ -3744,7 +3750,7 @@ getJasmineRequireObj().deprecatingSpecProxy = function(j$) { return ( 'Access to private Spec members (in this case `' + memberName + - '`) via Env#topSuite is not supported and will break in ' + + '`) is not supported and will break in ' + 'a future release. See ' + 'for correct usage.' ); @@ -3823,7 +3829,7 @@ getJasmineRequireObj().deprecatingSuiteProxy = function(j$) { return ( 'Access to private Suite members (in this case `' + memberName + - '`) via Env#topSuite is not supported and will break in ' + + '`) is not supported and will break in ' + 'a future release. See ' + 'for correct usage.' ); diff --git a/spec/core/EnvSpec.js b/spec/core/EnvSpec.js index d8151ef9..7bf29af6 100644 --- a/spec/core/EnvSpec.js +++ b/spec/core/EnvSpec.js @@ -106,7 +106,91 @@ describe('Env', function() { expect(env.deprecated).not.toHaveBeenCalled(); }); - it('deprecates access to internal Suite and Spec members', function() { + it('deprecates access to internal Spec members via it(), fit(), and xit()', function() { + jasmine.getEnv().requireProxy(); + spyOn(env, 'deprecated'); + + ['it', 'fit', 'xit'].forEach(function(method) { + var spec = env[method]('a spec', function() {}); + expect(env.deprecated).not.toHaveBeenCalled(); + + spec.pend(); + expect(env.deprecated) + .withContext('via ' + method) + .toHaveBeenCalledWith( + 'Access to private Spec members (in this case `pend`) is not ' + + 'supported and will break in a future release. See ' + + ' for correct usage.' + ); + env.deprecated.calls.reset(); + + spec.expectationFactory = {}; + expect(env.deprecated) + .withContext('via ' + method) + .toHaveBeenCalledWith( + 'Access to private Spec members (in this case `expectationFactory`) is not ' + + 'supported and will break in a future release. See ' + + ' for correct usage.' + ); + env.deprecated.calls.reset(); + + spec.expectationFactory = {}; + expect(env.deprecated) + .withContext('via ' + method) + .toHaveBeenCalledWith( + 'Access to private Spec members (in this case `expectationFactory`) is not ' + + 'supported and will break in a future release. See ' + + ' for correct usage.' + ); + env.deprecated.calls.reset(); + }); + }); + + it('deprecates access to internal Spec and Suite members via describe(), fdescribe(), and xdescribe()', function() { + jasmine.getEnv().requireProxy(); + spyOn(env, 'deprecated'); + + ['describe', 'fdescribe', 'xdescribe'].forEach(function(method) { + var suite = env[method]('a suite', function() { + env.it('a spec'); + }); + + suite.expectationFactory; + expect(env.deprecated) + .withContext('via ' + method) + .toHaveBeenCalledWith( + 'Access to private Suite ' + + 'members (in this case `expectationFactory`) is ' + + 'not supported and will break in a future release. See ' + + ' for correct usage.' + ); + env.deprecated.calls.reset(); + + suite.expectationFactory = {}; + expect(env.deprecated) + .withContext('via ' + method) + .toHaveBeenCalledWith( + 'Access to private Suite ' + + 'members (in this case `expectationFactory`) is ' + + 'not supported and will break in a future release. See ' + + ' for correct usage.' + ); + env.deprecated.calls.reset(); + + suite.status(); + expect(env.deprecated) + .withContext('via ' + method) + .toHaveBeenCalledWith( + 'Access to private Suite ' + + 'members (in this case `status`) is ' + + 'not supported and will break in a future release. See ' + + ' for correct usage.' + ); + env.deprecated.calls.reset(); + }); + }); + + it('deprecates access to internal Suite and Spec members via topSuite', function() { jasmine.getEnv().requireProxy(); var topSuite, expectationFactory, spec; @@ -117,7 +201,7 @@ describe('Env', function() { topSuite.expectationFactory; expect(env.deprecated).toHaveBeenCalledWith( 'Access to private Suite ' + - 'members (in this case `expectationFactory`) via Env#topSuite is ' + + 'members (in this case `expectationFactory`) is ' + 'not supported and will break in a future release. See ' + ' for correct usage.' ); @@ -126,7 +210,7 @@ describe('Env', function() { topSuite.expectationFactory = expectationFactory; expect(env.deprecated).toHaveBeenCalledWith( 'Access to private Suite ' + - 'members (in this case `expectationFactory`) via Env#topSuite is ' + + 'members (in this case `expectationFactory`) is ' + 'not supported and will break in a future release. See ' + ' for correct usage.' ); @@ -134,7 +218,7 @@ describe('Env', function() { topSuite.status(); expect(env.deprecated).toHaveBeenCalledWith( 'Access to private Suite ' + - 'members (in this case `status`) via Env#topSuite is ' + + 'members (in this case `status`) is ' + 'not supported and will break in a future release. See ' + ' for correct usage.' ); @@ -143,7 +227,7 @@ describe('Env', function() { spec.pend(); expect(env.deprecated).toHaveBeenCalledWith( 'Access to private Spec ' + - 'members (in this case `pend`) via Env#topSuite ' + + 'members (in this case `pend`) ' + 'is not supported and will break in a future release. See ' + ' for correct usage.' ); @@ -151,7 +235,7 @@ describe('Env', function() { expectationFactory = spec.expectationFactory; expect(env.deprecated).toHaveBeenCalledWith( 'Access to private Spec ' + - 'members (in this case `expectationFactory`) via Env#topSuite ' + + 'members (in this case `expectationFactory`) ' + 'is not supported and will break in a future release. See ' + ' for correct usage.' ); @@ -160,7 +244,7 @@ describe('Env', function() { spec.expectationFactory = expectationFactory; expect(env.deprecated).toHaveBeenCalledWith( 'Access to private Spec ' + - 'members (in this case `expectationFactory`) via Env#topSuite ' + + 'members (in this case `expectationFactory`) ' + 'is not supported and will break in a future release. See ' + ' for correct usage.' ); @@ -347,7 +431,7 @@ describe('Env', function() { describe('#xit', function() { it('calls spec.pend with "Temporarily disabled with xit"', function() { var pendSpy = jasmine.createSpy(); - spyOn(env, 'it').and.returnValue({ + spyOn(env, 'it_').and.returnValue({ pend: pendSpy }); env.xit('foo', function() {}); diff --git a/spec/core/integration/SpecRunningSpec.js b/spec/core/integration/SpecRunningSpec.js index d6e26104..aa8b79b9 100644 --- a/spec/core/integration/SpecRunningSpec.js +++ b/spec/core/integration/SpecRunningSpec.js @@ -550,10 +550,17 @@ describe('spec running', function() { var pendingSpec, suite = env.describe('default current suite', function() { pendingSpec = env.it('I am a pending spec'); - }); + }), + reporter = jasmine.createSpyObj('reporter', ['specDone']); + + env.addReporter(reporter); env.execute(null, function() { - expect(pendingSpec.status()).toBe('pending'); + expect(reporter.specDone).toHaveBeenCalledWith( + jasmine.objectContaining({ + status: 'pending' + }) + ); done(); }); }); diff --git a/src/core/Env.js b/src/core/Env.js index 8fb10fdb..1efa1d37 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -1117,7 +1117,7 @@ getJasmineRequireObj().Env = function(j$) { 'Please either remove the describe or add children to it.' ); } - return suite; + return j$.deprecatingSuiteProxy(suite, suite.parentSuite, this); }; this.xdescribe = function(description, specDefinitions) { @@ -1126,7 +1126,7 @@ getJasmineRequireObj().Env = function(j$) { var suite = suiteFactory(description); suite.pend(); addSpecsToSuite(suite, specDefinitions); - return suite; + return j$.deprecatingSuiteProxy(suite, suite.parentSuite, this); }; var focusedRunnables = []; @@ -1141,7 +1141,7 @@ getJasmineRequireObj().Env = function(j$) { unfocusAncestor(); addSpecsToSuite(suite, specDefinitions); - return suite; + return j$.deprecatingSuiteProxy(suite, suite.parentSuite, this); }; function addSpecsToSuite(suite, specDefinitions) { @@ -1231,7 +1231,7 @@ getJasmineRequireObj().Env = function(j$) { } }; - this.it = function(description, fn, timeout) { + this.it_ = function(description, fn, timeout) { ensureIsNotNested('it'); // it() sometimes doesn't have a fn argument, so only check the type if // it's given. @@ -1243,9 +1243,15 @@ getJasmineRequireObj().Env = function(j$) { spec.pend(); } currentDeclarationSuite.addChild(spec); + return spec; }; + this.it = function(description, fn, timeout) { + var spec = this.it_(description, fn, timeout); + return j$.deprecatingSpecProxy(spec, this); + }; + this.xit = function(description, fn, timeout) { ensureIsNotNested('xit'); // xit(), like it(), doesn't always have a fn argument, so only check the @@ -1253,9 +1259,9 @@ getJasmineRequireObj().Env = function(j$) { if (arguments.length > 1 && typeof fn !== 'undefined') { ensureIsFunctionOrAsync(fn, 'xit'); } - var spec = this.it.apply(this, arguments); + var spec = this.it_.apply(this, arguments); spec.pend('Temporarily disabled with xit'); - return spec; + return j$.deprecatingSpecProxy(spec, this); }; this.fit = function(description, fn, timeout) { @@ -1265,7 +1271,7 @@ getJasmineRequireObj().Env = function(j$) { currentDeclarationSuite.addChild(spec); focusedRunnables.push(spec.id); unfocusAncestor(); - return spec; + return j$.deprecatingSpecProxy(spec, this); }; /** diff --git a/src/core/deprecatingSpecProxy.js b/src/core/deprecatingSpecProxy.js index 710c86c4..ed80919c 100644 --- a/src/core/deprecatingSpecProxy.js +++ b/src/core/deprecatingSpecProxy.js @@ -17,7 +17,7 @@ getJasmineRequireObj().deprecatingSpecProxy = function(j$) { return ( 'Access to private Spec members (in this case `' + memberName + - '`) via Env#topSuite is not supported and will break in ' + + '`) is not supported and will break in ' + 'a future release. See ' + 'for correct usage.' ); diff --git a/src/core/deprecatingSuiteProxy.js b/src/core/deprecatingSuiteProxy.js index d92aac8b..e3cf8999 100644 --- a/src/core/deprecatingSuiteProxy.js +++ b/src/core/deprecatingSuiteProxy.js @@ -25,7 +25,7 @@ getJasmineRequireObj().deprecatingSuiteProxy = function(j$) { return ( 'Access to private Suite members (in this case `' + memberName + - '`) via Env#topSuite is not supported and will break in ' + + '`) is not supported and will break in ' + 'a future release. See ' + 'for correct usage.' );