This commit is contained in:
David Kale
2020-09-08 13:25:36 -04:00
parent e4246d2b5b
commit 91fcbb0108
4227 changed files with 416837 additions and 457884 deletions

View File

@@ -50,12 +50,8 @@ try {
// node internals in the browser though, so no issue.
}
const PATH_NODE_MODULES = `${_path.default.sep}node_modules${
_path.default.sep
}`;
const PATH_JEST_PACKAGES = `${_path.default.sep}jest${
_path.default.sep
}packages${_path.default.sep}`; // filter for noisy stack trace lines
const PATH_NODE_MODULES = `${_path.default.sep}node_modules${_path.default.sep}`;
const PATH_JEST_PACKAGES = `${_path.default.sep}jest${_path.default.sep}packages${_path.default.sep}`; // filter for noisy stack trace lines
const JASMINE_IGNORE = /^\s+at(?:(?:.jasmine\-)|\s+jasmine\.buildExpectationResult)/;
const JEST_INTERNALS_IGNORE = /^\s+at.*?jest(-.*?)?(\/|\\)(build|node_modules|packages)(\/|\\)/;
@@ -102,7 +98,9 @@ const getRenderedCallsite = (fileContent, line, column) => {
renderedCallsite = indentAllLines(renderedCallsite, MESSAGE_INDENT);
renderedCallsite = `\n${renderedCallsite}\n`;
return renderedCallsite;
}; // ExecError is an error thrown outside of the test suite (not inside an `it` or
};
const blankStringRegexp = /^\s*$/; // ExecError is an error thrown outside of the test suite (not inside an `it` or
// `before/after each` hooks). If it's thrown, none of the tests in the file
// are executed.
@@ -126,7 +124,7 @@ const formatExecError = (error, config, options, testPath, reuseMessage) => {
const separated = separateMessageFromStack(stack || '');
stack = separated.stack;
if (separated.message.indexOf(trim(message)) !== -1) {
if (separated.message.includes(trim(message))) {
// Often stack trace already contains the duplicate of the message
message = separated.message;
}
@@ -137,7 +135,7 @@ const formatExecError = (error, config, options, testPath, reuseMessage) => {
? '\n' + formatStackTrace(stack, config, options, testPath)
: '';
if (message.match(/^\s*$/) && stack.match(/^\s*$/)) {
if (blankStringRegexp.test(message) && blankStringRegexp.test(stack)) {
// this can happen if an empty object is thrown.
message = MESSAGE_INDENT + 'Error: No message was provided';
}
@@ -358,11 +356,19 @@ const formatResultsErrors = (testResults, config, options, testPath) => {
return title + '\n' + message + '\n' + stack;
})
.join('\n');
}; // jasmine and worker farm sometimes don't give us access to the actual
// Error object, so we have to regexp out the message from the stack string
// to format it.
};
exports.formatResultsErrors = formatResultsErrors;
const errorRegexp = /^Error:?\s*$/;
const removeBlankErrorLine = str =>
str
.split('\n') // Lines saying just `Error:` are useless
.filter(line => !errorRegexp.test(line))
.join('\n')
.trimRight(); // jasmine and worker farm sometimes don't give us access to the actual
// Error object, so we have to regexp out the message from the stack string
// to format it.
const separateMessageFromStack = content => {
if (!content) {
@@ -376,16 +382,16 @@ const separateMessageFromStack = content => {
// remove the prefix from the message because it is generally not useful.
const messageMatch = content.match(
/^(?:Error: )?([\s\S]*?(?=\n\s*at\s.*\:\d*\:\d*)|\s*.*)([\s\S]*)$/
/^(?:Error: )?([\s\S]*?(?=\n\s*at\s.*:\d*:\d*)|\s*.*)([\s\S]*)$/
);
if (!messageMatch) {
// For flow
// For typescript
throw new Error('If you hit this error, the regex above is buggy.');
}
const message = messageMatch[1];
const stack = messageMatch[2];
const message = removeBlankErrorLine(messageMatch[1]);
const stack = removeBlankErrorLine(messageMatch[2]);
return {
message,
stack