Don't display late errors as AfterAll errors in the HTML reporter

This commit is contained in:
Steve Gravrock
2021-09-11 08:57:50 -07:00
parent d092a59bd1
commit 6e10f22403
7 changed files with 82 additions and 20 deletions

View File

@@ -303,8 +303,10 @@ jasmineRequire.HtmlReporter = function(j$) {
} else {
return prefix;
}
} else {
} else if (failure.globalErrorType === 'afterAll') {
return afterAllMessagePrefix + failure.message;
} else {
return failure.message;
}
}

View File

@@ -1331,15 +1331,15 @@ getJasmineRequireObj().Env = function(j$) {
};
function recordLateError(error) {
topSuite.result.failedExpectations.push(
expectationResultFactory({
error,
passed: false,
matcherName: '',
expected: '',
actual: ''
})
);
const result = expectationResultFactory({
error,
passed: false,
matcherName: '',
expected: '',
actual: ''
});
result.globalErrorType = 'lateError';
topSuite.result.failedExpectations.push(result);
}
function recordLateExpectation(runable, runableType, result) {
@@ -3912,6 +3912,9 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
* @property {Boolean} passed - Whether the expectation passed or failed.
* @property {Object} expected - If the expectation failed, what was the expected value.
* @property {Object} actual - If the expectation failed, what actual value was produced.
* @property {String|undefined} globalErrorType - The type of an error that
* is reported on the top suite. Valid values are undefined, "afterAll",
* "load", "lateExpectation", and "lateError".
*/
var result = {
matcherName: options.matcherName,

View File

@@ -534,9 +534,11 @@ describe('Env integration', function() {
expect(errors[0].message)
.withContext('top beforeAll')
.toContain(message);
expect(errors[0].globalErrorType).toEqual('lateError');
expect(errors[1].message)
.withContext('top afterAll')
.toContain(message);
expect(errors[1].globalErrorType).toEqual('lateError');
done();
});
});
@@ -568,9 +570,11 @@ describe('Env integration', function() {
expect(errors[0].message)
.withContext('suite beforeAll')
.toContain(message);
expect(errors[0].globalErrorType).toEqual('lateError');
expect(errors[1].message)
.withContext('suite afterAll')
.toContain(message);
expect(errors[1].globalErrorType).toEqual('lateError');
done();
});
});
@@ -605,12 +609,15 @@ describe('Env integration', function() {
expect(errors[0].message)
.withContext('error caused by beforeEach')
.toContain(message);
expect(errors[0].globalErrorType).toEqual('lateError');
expect(errors[1].message)
.withContext('error caused by it')
.toContain(message);
expect(errors[1].globalErrorType).toEqual('lateError');
expect(errors[2].message)
.withContext('error caused by afterEach')
.toContain(message);
expect(errors[2].globalErrorType).toEqual('lateError');
done();
});
});
@@ -634,6 +641,7 @@ describe('Env integration', function() {
.failedExpectations;
expect(errors.length).toEqual(1);
expect(errors[0].message).toContain(message);
expect(errors[0].globalErrorType).toEqual('lateError');
done();
});
});

View File

@@ -704,6 +704,50 @@ describe('HtmlReporter', function() {
expect(alertBars[2].innerHTML).not.toMatch(/line/);
});
it('does not display the "AfterAll" prefix for other error types', function() {
const container = document.createElement('div');
const getContainer = function() {
return container;
};
const reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() {
return document.createElement.apply(document, arguments);
},
createTextNode: function() {
return document.createTextNode.apply(document, arguments);
}
});
reporter.initialize();
reporter.jasmineStarted({});
reporter.jasmineDone({
failedExpectations: [
{ message: 'load error', globalErrorType: 'load' },
{
message: 'lateExpectation error',
globalErrorType: 'lateExpectation'
},
{ message: 'lateError error', globalErrorType: 'lateError' }
]
});
const alertBars = container.querySelectorAll(
'.jasmine-alert .jasmine-bar'
);
expect(alertBars.length).toEqual(4);
expect(alertBars[1].textContent).toContain('load error');
expect(alertBars[2].textContent).toContain('lateExpectation error');
expect(alertBars[3].textContent).toContain('lateError error');
for (let bar of alertBars) {
expect(bar.textContent).not.toContain('AfterAll');
}
});
it('displays file and line information if available', function() {
var container = document.createElement('div'),
getContainer = function() {

View File

@@ -339,15 +339,15 @@ getJasmineRequireObj().Env = function(j$) {
};
function recordLateError(error) {
topSuite.result.failedExpectations.push(
expectationResultFactory({
error,
passed: false,
matcherName: '',
expected: '',
actual: ''
})
);
const result = expectationResultFactory({
error,
passed: false,
matcherName: '',
expected: '',
actual: ''
});
result.globalErrorType = 'lateError';
topSuite.result.failedExpectations.push(result);
}
function recordLateExpectation(runable, runableType, result) {

View File

@@ -12,6 +12,9 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
* @property {Boolean} passed - Whether the expectation passed or failed.
* @property {Object} expected - If the expectation failed, what was the expected value.
* @property {Object} actual - If the expectation failed, what actual value was produced.
* @property {String|undefined} globalErrorType - The type of an error that
* is reported on the top suite. Valid values are undefined, "afterAll",
* "load", "lateExpectation", and "lateError".
*/
var result = {
matcherName: options.matcherName,

View File

@@ -272,8 +272,10 @@ jasmineRequire.HtmlReporter = function(j$) {
} else {
return prefix;
}
} else {
} else if (failure.globalErrorType === 'afterAll') {
return afterAllMessagePrefix + failure.message;
} else {
return failure.message;
}
}