Deprecated access to non-public members in specs and suites returned from it(), describe(), etc.

This commit is contained in:
Steve Gravrock
2021-07-29 21:28:47 -07:00
parent 2a2a671b65
commit 799d9897fd
6 changed files with 131 additions and 28 deletions

View File

@@ -2155,7 +2155,7 @@ getJasmineRequireObj().Env = function(j$) {
'Please either remove the describe or add children to it.' 'Please either remove the describe or add children to it.'
); );
} }
return suite; return j$.deprecatingSuiteProxy(suite, suite.parentSuite, this);
}; };
this.xdescribe = function(description, specDefinitions) { this.xdescribe = function(description, specDefinitions) {
@@ -2164,7 +2164,7 @@ getJasmineRequireObj().Env = function(j$) {
var suite = suiteFactory(description); var suite = suiteFactory(description);
suite.pend(); suite.pend();
addSpecsToSuite(suite, specDefinitions); addSpecsToSuite(suite, specDefinitions);
return suite; return j$.deprecatingSuiteProxy(suite, suite.parentSuite, this);
}; };
var focusedRunnables = []; var focusedRunnables = [];
@@ -2179,7 +2179,7 @@ getJasmineRequireObj().Env = function(j$) {
unfocusAncestor(); unfocusAncestor();
addSpecsToSuite(suite, specDefinitions); addSpecsToSuite(suite, specDefinitions);
return suite; return j$.deprecatingSuiteProxy(suite, suite.parentSuite, this);
}; };
function addSpecsToSuite(suite, specDefinitions) { 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'); ensureIsNotNested('it');
// it() sometimes doesn't have a fn argument, so only check the type if // it() sometimes doesn't have a fn argument, so only check the type if
// it's given. // it's given.
@@ -2281,9 +2281,15 @@ getJasmineRequireObj().Env = function(j$) {
spec.pend(); spec.pend();
} }
currentDeclarationSuite.addChild(spec); currentDeclarationSuite.addChild(spec);
return 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) { this.xit = function(description, fn, timeout) {
ensureIsNotNested('xit'); ensureIsNotNested('xit');
// xit(), like it(), doesn't always have a fn argument, so only check the // 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') { if (arguments.length > 1 && typeof fn !== 'undefined') {
ensureIsFunctionOrAsync(fn, 'xit'); ensureIsFunctionOrAsync(fn, 'xit');
} }
var spec = this.it.apply(this, arguments); var spec = this.it_.apply(this, arguments);
spec.pend('Temporarily disabled with xit'); spec.pend('Temporarily disabled with xit');
return spec; return j$.deprecatingSpecProxy(spec, this);
}; };
this.fit = function(description, fn, timeout) { this.fit = function(description, fn, timeout) {
@@ -2303,7 +2309,7 @@ getJasmineRequireObj().Env = function(j$) {
currentDeclarationSuite.addChild(spec); currentDeclarationSuite.addChild(spec);
focusedRunnables.push(spec.id); focusedRunnables.push(spec.id);
unfocusAncestor(); unfocusAncestor();
return spec; return j$.deprecatingSpecProxy(spec, this);
}; };
/** /**
@@ -3744,7 +3750,7 @@ getJasmineRequireObj().deprecatingSpecProxy = function(j$) {
return ( return (
'Access to private Spec members (in this case `' + 'Access to private Spec members (in this case `' +
memberName + memberName +
'`) via Env#topSuite is not supported and will break in ' + '`) is not supported and will break in ' +
'a future release. See <https://jasmine.github.io/api/edge/Spec.html> ' + 'a future release. See <https://jasmine.github.io/api/edge/Spec.html> ' +
'for correct usage.' 'for correct usage.'
); );
@@ -3823,7 +3829,7 @@ getJasmineRequireObj().deprecatingSuiteProxy = function(j$) {
return ( return (
'Access to private Suite members (in this case `' + 'Access to private Suite members (in this case `' +
memberName + memberName +
'`) via Env#topSuite is not supported and will break in ' + '`) is not supported and will break in ' +
'a future release. See <https://jasmine.github.io/api/edge/Suite.html> ' + 'a future release. See <https://jasmine.github.io/api/edge/Suite.html> ' +
'for correct usage.' 'for correct usage.'
); );

View File

@@ -106,7 +106,91 @@ describe('Env', function() {
expect(env.deprecated).not.toHaveBeenCalled(); 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 ' +
'<https://jasmine.github.io/api/edge/Spec.html> 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 ' +
'<https://jasmine.github.io/api/edge/Spec.html> 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 ' +
'<https://jasmine.github.io/api/edge/Spec.html> 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 ' +
'<https://jasmine.github.io/api/edge/Suite.html> 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 ' +
'<https://jasmine.github.io/api/edge/Suite.html> 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 ' +
'<https://jasmine.github.io/api/edge/Suite.html> for correct usage.'
);
env.deprecated.calls.reset();
});
});
it('deprecates access to internal Suite and Spec members via topSuite', function() {
jasmine.getEnv().requireProxy(); jasmine.getEnv().requireProxy();
var topSuite, expectationFactory, spec; var topSuite, expectationFactory, spec;
@@ -117,7 +201,7 @@ describe('Env', function() {
topSuite.expectationFactory; topSuite.expectationFactory;
expect(env.deprecated).toHaveBeenCalledWith( expect(env.deprecated).toHaveBeenCalledWith(
'Access to private Suite ' + '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 ' + 'not supported and will break in a future release. See ' +
'<https://jasmine.github.io/api/edge/Suite.html> for correct usage.' '<https://jasmine.github.io/api/edge/Suite.html> for correct usage.'
); );
@@ -126,7 +210,7 @@ describe('Env', function() {
topSuite.expectationFactory = expectationFactory; topSuite.expectationFactory = expectationFactory;
expect(env.deprecated).toHaveBeenCalledWith( expect(env.deprecated).toHaveBeenCalledWith(
'Access to private Suite ' + '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 ' + 'not supported and will break in a future release. See ' +
'<https://jasmine.github.io/api/edge/Suite.html> for correct usage.' '<https://jasmine.github.io/api/edge/Suite.html> for correct usage.'
); );
@@ -134,7 +218,7 @@ describe('Env', function() {
topSuite.status(); topSuite.status();
expect(env.deprecated).toHaveBeenCalledWith( expect(env.deprecated).toHaveBeenCalledWith(
'Access to private Suite ' + '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 ' + 'not supported and will break in a future release. See ' +
'<https://jasmine.github.io/api/edge/Suite.html> for correct usage.' '<https://jasmine.github.io/api/edge/Suite.html> for correct usage.'
); );
@@ -143,7 +227,7 @@ describe('Env', function() {
spec.pend(); spec.pend();
expect(env.deprecated).toHaveBeenCalledWith( expect(env.deprecated).toHaveBeenCalledWith(
'Access to private Spec ' + '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 ' + 'is not supported and will break in a future release. See ' +
'<https://jasmine.github.io/api/edge/Spec.html> for correct usage.' '<https://jasmine.github.io/api/edge/Spec.html> for correct usage.'
); );
@@ -151,7 +235,7 @@ describe('Env', function() {
expectationFactory = spec.expectationFactory; expectationFactory = spec.expectationFactory;
expect(env.deprecated).toHaveBeenCalledWith( expect(env.deprecated).toHaveBeenCalledWith(
'Access to private Spec ' + '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 ' + 'is not supported and will break in a future release. See ' +
'<https://jasmine.github.io/api/edge/Spec.html> for correct usage.' '<https://jasmine.github.io/api/edge/Spec.html> for correct usage.'
); );
@@ -160,7 +244,7 @@ describe('Env', function() {
spec.expectationFactory = expectationFactory; spec.expectationFactory = expectationFactory;
expect(env.deprecated).toHaveBeenCalledWith( expect(env.deprecated).toHaveBeenCalledWith(
'Access to private Spec ' + '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 ' + 'is not supported and will break in a future release. See ' +
'<https://jasmine.github.io/api/edge/Spec.html> for correct usage.' '<https://jasmine.github.io/api/edge/Spec.html> for correct usage.'
); );
@@ -347,7 +431,7 @@ describe('Env', function() {
describe('#xit', function() { describe('#xit', function() {
it('calls spec.pend with "Temporarily disabled with xit"', function() { it('calls spec.pend with "Temporarily disabled with xit"', function() {
var pendSpy = jasmine.createSpy(); var pendSpy = jasmine.createSpy();
spyOn(env, 'it').and.returnValue({ spyOn(env, 'it_').and.returnValue({
pend: pendSpy pend: pendSpy
}); });
env.xit('foo', function() {}); env.xit('foo', function() {});

View File

@@ -550,10 +550,17 @@ describe('spec running', function() {
var pendingSpec, var pendingSpec,
suite = env.describe('default current suite', function() { suite = env.describe('default current suite', function() {
pendingSpec = env.it('I am a pending spec'); pendingSpec = env.it('I am a pending spec');
}); }),
reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
env.execute(null, function() { env.execute(null, function() {
expect(pendingSpec.status()).toBe('pending'); expect(reporter.specDone).toHaveBeenCalledWith(
jasmine.objectContaining({
status: 'pending'
})
);
done(); done();
}); });
}); });

View File

@@ -1117,7 +1117,7 @@ getJasmineRequireObj().Env = function(j$) {
'Please either remove the describe or add children to it.' 'Please either remove the describe or add children to it.'
); );
} }
return suite; return j$.deprecatingSuiteProxy(suite, suite.parentSuite, this);
}; };
this.xdescribe = function(description, specDefinitions) { this.xdescribe = function(description, specDefinitions) {
@@ -1126,7 +1126,7 @@ getJasmineRequireObj().Env = function(j$) {
var suite = suiteFactory(description); var suite = suiteFactory(description);
suite.pend(); suite.pend();
addSpecsToSuite(suite, specDefinitions); addSpecsToSuite(suite, specDefinitions);
return suite; return j$.deprecatingSuiteProxy(suite, suite.parentSuite, this);
}; };
var focusedRunnables = []; var focusedRunnables = [];
@@ -1141,7 +1141,7 @@ getJasmineRequireObj().Env = function(j$) {
unfocusAncestor(); unfocusAncestor();
addSpecsToSuite(suite, specDefinitions); addSpecsToSuite(suite, specDefinitions);
return suite; return j$.deprecatingSuiteProxy(suite, suite.parentSuite, this);
}; };
function addSpecsToSuite(suite, specDefinitions) { 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'); ensureIsNotNested('it');
// it() sometimes doesn't have a fn argument, so only check the type if // it() sometimes doesn't have a fn argument, so only check the type if
// it's given. // it's given.
@@ -1243,9 +1243,15 @@ getJasmineRequireObj().Env = function(j$) {
spec.pend(); spec.pend();
} }
currentDeclarationSuite.addChild(spec); currentDeclarationSuite.addChild(spec);
return 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) { this.xit = function(description, fn, timeout) {
ensureIsNotNested('xit'); ensureIsNotNested('xit');
// xit(), like it(), doesn't always have a fn argument, so only check the // 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') { if (arguments.length > 1 && typeof fn !== 'undefined') {
ensureIsFunctionOrAsync(fn, 'xit'); ensureIsFunctionOrAsync(fn, 'xit');
} }
var spec = this.it.apply(this, arguments); var spec = this.it_.apply(this, arguments);
spec.pend('Temporarily disabled with xit'); spec.pend('Temporarily disabled with xit');
return spec; return j$.deprecatingSpecProxy(spec, this);
}; };
this.fit = function(description, fn, timeout) { this.fit = function(description, fn, timeout) {
@@ -1265,7 +1271,7 @@ getJasmineRequireObj().Env = function(j$) {
currentDeclarationSuite.addChild(spec); currentDeclarationSuite.addChild(spec);
focusedRunnables.push(spec.id); focusedRunnables.push(spec.id);
unfocusAncestor(); unfocusAncestor();
return spec; return j$.deprecatingSpecProxy(spec, this);
}; };
/** /**

View File

@@ -17,7 +17,7 @@ getJasmineRequireObj().deprecatingSpecProxy = function(j$) {
return ( return (
'Access to private Spec members (in this case `' + 'Access to private Spec members (in this case `' +
memberName + memberName +
'`) via Env#topSuite is not supported and will break in ' + '`) is not supported and will break in ' +
'a future release. See <https://jasmine.github.io/api/edge/Spec.html> ' + 'a future release. See <https://jasmine.github.io/api/edge/Spec.html> ' +
'for correct usage.' 'for correct usage.'
); );

View File

@@ -25,7 +25,7 @@ getJasmineRequireObj().deprecatingSuiteProxy = function(j$) {
return ( return (
'Access to private Suite members (in this case `' + 'Access to private Suite members (in this case `' +
memberName + memberName +
'`) via Env#topSuite is not supported and will break in ' + '`) is not supported and will break in ' +
'a future release. See <https://jasmine.github.io/api/edge/Suite.html> ' + 'a future release. See <https://jasmine.github.io/api/edge/Suite.html> ' +
'for correct usage.' 'for correct usage.'
); );