Parallel: Improved error messages for top-level before/afterAll

This commit is contained in:
Steve Gravrock
2022-11-25 13:13:05 -08:00
parent 75f97961f5
commit af9a4114f4
3 changed files with 38 additions and 15 deletions

View File

@@ -1830,11 +1830,9 @@ getJasmineRequireObj().Env = function(j$) {
} }
} }
function ensureNonParallelOrInDescribe(method) { function ensureNonParallelOrInDescribe(msg) {
if (parallelLoadingState && !suiteBuilder.inDescribe()) { if (parallelLoadingState && !suiteBuilder.inDescribe()) {
throw new Error( throw new Error(msg);
`In parallel mode, '${method}' must be in a describe block`
);
} }
} }
@@ -1987,7 +1985,13 @@ getJasmineRequireObj().Env = function(j$) {
this.beforeAll = function(beforeAllFunction, timeout) { this.beforeAll = function(beforeAllFunction, timeout) {
ensureIsNotNested('beforeAll'); ensureIsNotNested('beforeAll');
ensureNonParallelOrInDescribe('beforeAll'); // This message is -npm-specific, but currently parallel operation is
// only supported via -npm.
ensureNonParallelOrInDescribe(
"In parallel mode, 'beforeAll' " +
'must be in a describe block. Use the globalSetup config ' +
'property for exactly-once setup in parallel mode.'
);
suiteBuilder.beforeAll(beforeAllFunction, timeout); suiteBuilder.beforeAll(beforeAllFunction, timeout);
}; };
@@ -1999,7 +2003,13 @@ getJasmineRequireObj().Env = function(j$) {
this.afterAll = function(afterAllFunction, timeout) { this.afterAll = function(afterAllFunction, timeout) {
ensureIsNotNested('afterAll'); ensureIsNotNested('afterAll');
ensureNonParallelOrInDescribe('afterAll'); // This message is -npm-specific, but currently parallel operation is
// only supported via -npm.
ensureNonParallelOrInDescribe(
"In parallel mode, 'afterAll' " +
'must be in a describe block. Use the globalTeardown config ' +
'property for exactly-once teardown in parallel mode.'
);
suiteBuilder.afterAll(afterAllFunction, timeout); suiteBuilder.afterAll(afterAllFunction, timeout);
}; };

View File

@@ -1,6 +1,5 @@
// TODO: Fix these unit tests! // TODO: Fix these unit tests!
describe('Env', function() { describe('Env', function() {
beforeAll(function() {});
let env; let env;
beforeEach(function() { beforeEach(function() {
env = new jasmineUnderTest.Env(); env = new jasmineUnderTest.Env();
@@ -480,7 +479,9 @@ describe('Env', function() {
expect(function() { expect(function() {
env.beforeAll(function() {}); env.beforeAll(function() {});
}).toThrowError( }).toThrowError(
"In parallel mode, 'beforeAll' must be in a describe block" "In parallel mode, 'beforeAll' must be in a describe block. " +
'Use the globalSetup config property for exactly-once setup in' +
' parallel mode.'
); );
} }
}); });
@@ -585,7 +586,9 @@ describe('Env', function() {
expect(function() { expect(function() {
env.afterAll(function() {}); env.afterAll(function() {});
}).toThrowError( }).toThrowError(
"In parallel mode, 'afterAll' must be in a describe block" "In parallel mode, 'afterAll' must be in a describe block. " +
'Use the globalTeardown config property for exactly-once ' +
'teardown in parallel mode.'
); );
} }
}); });

View File

@@ -688,11 +688,9 @@ getJasmineRequireObj().Env = function(j$) {
} }
} }
function ensureNonParallelOrInDescribe(method) { function ensureNonParallelOrInDescribe(msg) {
if (parallelLoadingState && !suiteBuilder.inDescribe()) { if (parallelLoadingState && !suiteBuilder.inDescribe()) {
throw new Error( throw new Error(msg);
`In parallel mode, '${method}' must be in a describe block`
);
} }
} }
@@ -845,7 +843,13 @@ getJasmineRequireObj().Env = function(j$) {
this.beforeAll = function(beforeAllFunction, timeout) { this.beforeAll = function(beforeAllFunction, timeout) {
ensureIsNotNested('beforeAll'); ensureIsNotNested('beforeAll');
ensureNonParallelOrInDescribe('beforeAll'); // This message is -npm-specific, but currently parallel operation is
// only supported via -npm.
ensureNonParallelOrInDescribe(
"In parallel mode, 'beforeAll' " +
'must be in a describe block. Use the globalSetup config ' +
'property for exactly-once setup in parallel mode.'
);
suiteBuilder.beforeAll(beforeAllFunction, timeout); suiteBuilder.beforeAll(beforeAllFunction, timeout);
}; };
@@ -857,7 +861,13 @@ getJasmineRequireObj().Env = function(j$) {
this.afterAll = function(afterAllFunction, timeout) { this.afterAll = function(afterAllFunction, timeout) {
ensureIsNotNested('afterAll'); ensureIsNotNested('afterAll');
ensureNonParallelOrInDescribe('afterAll'); // This message is -npm-specific, but currently parallel operation is
// only supported via -npm.
ensureNonParallelOrInDescribe(
"In parallel mode, 'afterAll' " +
'must be in a describe block. Use the globalTeardown config ' +
'property for exactly-once teardown in parallel mode.'
);
suiteBuilder.afterAll(afterAllFunction, timeout); suiteBuilder.afterAll(afterAllFunction, timeout);
}; };