jest-message-util
Advanced tools
Comparing version 29.1.2 to 29.2.0
@@ -15,25 +15,14 @@ 'use strict'; | ||
void 0; | ||
var path = _interopRequireWildcard(require('path')); | ||
var _url = require('url'); | ||
var _codeFrame = require('@babel/code-frame'); | ||
var _chalk = _interopRequireDefault(require('chalk')); | ||
var fs = _interopRequireWildcard(require('graceful-fs')); | ||
var _micromatch = _interopRequireDefault(require('micromatch')); | ||
var _slash = _interopRequireDefault(require('slash')); | ||
var _stackUtils = _interopRequireDefault(require('stack-utils')); | ||
var _prettyFormat = require('pretty-format'); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -47,3 +36,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -81,3 +69,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol; | ||
@@ -92,3 +79,2 @@ var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol; | ||
let nodeInternals = []; | ||
try { | ||
@@ -100,6 +86,6 @@ nodeInternals = _stackUtils.default.nodeInternals(); | ||
} | ||
const PATH_NODE_MODULES = `${path.sep}node_modules${path.sep}`; | ||
const PATH_JEST_PACKAGES = `${path.sep}jest${path.sep}packages${path.sep}`; // filter for noisy stack trace lines | ||
const PATH_JEST_PACKAGES = `${path.sep}jest${path.sep}packages${path.sep}`; | ||
// filter for noisy stack trace lines | ||
const JASMINE_IGNORE = | ||
@@ -117,5 +103,3 @@ /^\s+at(?:(?:.jasmine-)|\s+jasmine\.buildExpectationResult)/; | ||
const ANCESTRY_SEPARATOR = ' \u203A '; | ||
const TITLE_BULLET = _chalk.default.bold('\u25cf '); | ||
const STACK_TRACE_COLOR = _chalk.default.dim; | ||
@@ -125,16 +109,13 @@ const STACK_PATH_REGEXP = /\s*at.*\(?(:\d*:\d*|native)\)?/; | ||
const NOT_EMPTY_LINE_REGEXP = /^(?!$)/gm; | ||
const indentAllLines = lines => | ||
lines.replace(NOT_EMPTY_LINE_REGEXP, MESSAGE_INDENT); | ||
exports.indentAllLines = indentAllLines; | ||
const trim = string => (string || '').trim(); | ||
const trim = string => (string || '').trim(); // Some errors contain not only line numbers in stack traces | ||
// Some errors contain not only line numbers in stack traces | ||
// e.g. SyntaxErrors can contain snippets of code, and we don't | ||
// want to trim those, because they may have pointers to the column/character | ||
// which will get misaligned. | ||
const trimPaths = string => | ||
string.match(STACK_PATH_REGEXP) ? trim(string) : string; | ||
const getRenderedCallsite = (fileContent, line, column) => { | ||
@@ -157,5 +138,3 @@ let renderedCallsite = (0, _codeFrame.codeFrameColumns)( | ||
}; | ||
const blankStringRegexp = /^\s*$/; | ||
function checkForCommonEnvironmentErrors(error) { | ||
@@ -171,6 +150,4 @@ if ( | ||
} | ||
return error; | ||
} | ||
function warnAboutWrongTestEnvironment(error, env) { | ||
@@ -184,6 +161,7 @@ return ( | ||
); | ||
} // ExecError is an error thrown outside of the test suite (not inside an `it` or | ||
} | ||
// 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. | ||
const formatExecError = (error, config, options, testPath, reuseMessage) => { | ||
@@ -194,5 +172,3 @@ if (!error || typeof error === 'number') { | ||
} | ||
let message, stack; | ||
if (typeof error === 'string' || !error) { | ||
@@ -211,6 +187,4 @@ error || (error = 'EMPTY ERROR'); | ||
} | ||
const separated = separateMessageFromStack(stack || ''); | ||
stack = separated.stack; | ||
if (separated.message.includes(trim(message))) { | ||
@@ -220,3 +194,2 @@ // Often stack trace already contains the duplicate of the message | ||
} | ||
message = checkForCommonEnvironmentErrors(message); | ||
@@ -228,3 +201,2 @@ message = indentAllLines(message); | ||
: ''; | ||
if ( | ||
@@ -239,5 +211,3 @@ typeof stack !== 'string' || | ||
} | ||
let messageToUse; | ||
if (reuseMessage) { | ||
@@ -248,8 +218,5 @@ messageToUse = ` ${message.trim()}`; | ||
} | ||
return `${TITLE_INDENT + TITLE_BULLET + messageToUse + stack}\n`; | ||
}; | ||
exports.formatExecError = formatExecError; | ||
const removeInternalStackEntries = (lines, options) => { | ||
@@ -261,27 +228,20 @@ let pathCounter = 0; | ||
} | ||
if (ANONYMOUS_PROMISE_IGNORE.test(line)) { | ||
return false; | ||
} | ||
if (ANONYMOUS_GENERATOR_IGNORE.test(line)) { | ||
return false; | ||
} | ||
if (NATIVE_NEXT_IGNORE.test(line)) { | ||
return false; | ||
} | ||
if (nodeInternals.some(internal => internal.test(line))) { | ||
return false; | ||
} | ||
if (!STACK_PATH_REGEXP.test(line)) { | ||
return true; | ||
} | ||
if (JASMINE_IGNORE.test(line)) { | ||
return false; | ||
} | ||
if (++pathCounter === 1) { | ||
@@ -294,21 +254,16 @@ return true; // always keep the first line even if it's from Jest | ||
} | ||
if (JEST_INTERNALS_IGNORE.test(line)) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
}; | ||
const formatPath = (line, config, relativeTestPath = null) => { | ||
// Extract the file path from the trace line. | ||
const match = line.match(/(^\s*at .*?\(?)([^()]+)(:[0-9]+:[0-9]+\)?.*$)/); | ||
if (!match) { | ||
return line; | ||
} | ||
let filePath = (0, _slash.default)(path.relative(config.rootDir, match[2])); // highlight paths from the current test file | ||
let filePath = (0, _slash.default)(path.relative(config.rootDir, match[2])); | ||
// highlight paths from the current test file | ||
if ( | ||
@@ -322,8 +277,5 @@ (config.testMatch && | ||
} | ||
return STACK_TRACE_COLOR(match[1]) + filePath + STACK_TRACE_COLOR(match[3]); | ||
}; | ||
exports.formatPath = formatPath; | ||
const getStackTraceLines = ( | ||
@@ -336,5 +288,3 @@ stack, | ||
) => removeInternalStackEntries(stack.split(/\n/), options); | ||
exports.getStackTraceLines = getStackTraceLines; | ||
const getTopFrame = lines => { | ||
@@ -345,5 +295,3 @@ for (const line of lines) { | ||
} | ||
const parsedFrame = stackUtils.parseLine(line.trim()); | ||
if (parsedFrame && parsedFrame.file) { | ||
@@ -355,12 +303,8 @@ if (parsedFrame.file.startsWith('file://')) { | ||
} | ||
return parsedFrame; | ||
} | ||
} | ||
return null; | ||
}; | ||
exports.getTopFrame = getTopFrame; | ||
const formatStackTrace = (stack, config, options, testPath) => { | ||
@@ -372,12 +316,8 @@ const lines = getStackTraceLines(stack, options); | ||
: null; | ||
if (!options.noStackTrace && !options.noCodeFrame) { | ||
const topFrame = getTopFrame(lines); | ||
if (topFrame) { | ||
const {column, file: filename, line} = topFrame; | ||
if (line && filename && path.isAbsolute(filename)) { | ||
let fileContent; | ||
try { | ||
@@ -394,3 +334,2 @@ // TODO: check & read HasteFS instead of reading the filesystem: | ||
} | ||
const stacktrace = lines | ||
@@ -407,5 +346,3 @@ .filter(Boolean) | ||
}; | ||
exports.formatStackTrace = formatStackTrace; | ||
const formatResultsErrors = (testResults, config, options, testPath) => { | ||
@@ -421,7 +358,5 @@ const failedResults = testResults.reduce((errors, result) => { | ||
}, []); | ||
if (!failedResults.length) { | ||
return null; | ||
} | ||
return failedResults | ||
@@ -447,15 +382,15 @@ .map(({result, content}) => { | ||
}; | ||
exports.formatResultsErrors = formatResultsErrors; | ||
const errorRegexp = /^Error:?\s*$/; | ||
const removeBlankErrorLine = str => | ||
str | ||
.split('\n') // Lines saying just `Error:` are useless | ||
.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 | ||
.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 => { | ||
@@ -467,11 +402,11 @@ if (!content) { | ||
}; | ||
} // All lines up to what looks like a stack -- or if nothing looks like a stack | ||
} | ||
// All lines up to what looks like a stack -- or if nothing looks like a stack | ||
// (maybe it's a code frame instead), just the first non-empty line. | ||
// If the error is a plain "Error:" instead of a SyntaxError or TypeError we | ||
// 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]*)$/ | ||
); | ||
if (!messageMatch) { | ||
@@ -481,3 +416,2 @@ // For typescript | ||
} | ||
const message = removeBlankErrorLine(messageMatch[1]); | ||
@@ -490,3 +424,2 @@ const stack = removeBlankErrorLine(messageMatch[2]); | ||
}; | ||
exports.separateMessageFromStack = separateMessageFromStack; |
{ | ||
"name": "jest-message-util", | ||
"version": "29.1.2", | ||
"version": "29.2.0", | ||
"repository": { | ||
@@ -24,3 +24,3 @@ "type": "git", | ||
"@babel/code-frame": "^7.12.13", | ||
"@jest/types": "^29.1.2", | ||
"@jest/types": "^29.2.0", | ||
"@types/stack-utils": "^2.0.0", | ||
@@ -30,3 +30,3 @@ "chalk": "^4.0.0", | ||
"micromatch": "^4.0.4", | ||
"pretty-format": "^29.1.2", | ||
"pretty-format": "^29.2.0", | ||
"slash": "^3.0.0", | ||
@@ -43,3 +43,3 @@ "stack-utils": "^2.0.3" | ||
}, | ||
"gitHead": "3c31dd619e8c022cde53f40fa12ea2a67f4752ce" | ||
"gitHead": "ee5b37a4f4433afcfffb0356cea47739d8092287" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
444
16968
Updated@jest/types@^29.2.0
Updatedpretty-format@^29.2.0