Parallel: Don't allow reporters to be added or removed in worker processes

This commit is contained in:
Steve Gravrock
2022-10-22 09:55:48 -07:00
parent 47c64a86d5
commit ed5e902106
3 changed files with 44 additions and 0 deletions

View File

@@ -1691,6 +1691,10 @@ getJasmineRequireObj().Env = function(j$) {
* @see custom_reporter * @see custom_reporter
*/ */
this.addReporter = function(reporterToAdd) { this.addReporter = function(reporterToAdd) {
if (parallelLoadingState) {
throw new Error('Reporters cannot be added via Env in parallel mode');
}
reporter.addReporter(reporterToAdd); reporter.addReporter(reporterToAdd);
}; };
@@ -1713,6 +1717,10 @@ getJasmineRequireObj().Env = function(j$) {
* @function * @function
*/ */
this.clearReporters = function() { this.clearReporters = function() {
if (parallelLoadingState) {
throw new Error('Reporters cannot be removed via Env in parallel mode');
}
reporter.clearReporters(); reporter.clearReporters();
}; };

View File

@@ -786,4 +786,32 @@ describe('Env', function() {
).toBeRejectedWithError(msg); ).toBeRejectedWithError(msg);
}); });
}); });
describe('#addReporter', function() {
it('throws when called in parallel mode', function() {
env.setParallelLoadingState('helpers');
expect(function() {
env.addReporter({});
}).toThrowError('Reporters cannot be added via Env in parallel mode');
env.setParallelLoadingState('specs');
expect(function() {
env.addReporter({});
}).toThrowError('Reporters cannot be added via Env in parallel mode');
});
});
describe('#clearReporters', function() {
it('throws when called in parallel mode', function() {
env.setParallelLoadingState('helpers');
expect(function() {
env.clearReporters();
}).toThrowError('Reporters cannot be removed via Env in parallel mode');
env.setParallelLoadingState('specs');
expect(function() {
env.clearReporters();
}).toThrowError('Reporters cannot be removed via Env in parallel mode');
});
});
}); });

View File

@@ -549,6 +549,10 @@ getJasmineRequireObj().Env = function(j$) {
* @see custom_reporter * @see custom_reporter
*/ */
this.addReporter = function(reporterToAdd) { this.addReporter = function(reporterToAdd) {
if (parallelLoadingState) {
throw new Error('Reporters cannot be added via Env in parallel mode');
}
reporter.addReporter(reporterToAdd); reporter.addReporter(reporterToAdd);
}; };
@@ -571,6 +575,10 @@ getJasmineRequireObj().Env = function(j$) {
* @function * @function
*/ */
this.clearReporters = function() { this.clearReporters = function() {
if (parallelLoadingState) {
throw new Error('Reporters cannot be removed via Env in parallel mode');
}
reporter.clearReporters(); reporter.clearReporters();
}; };