jest-message-util
Advanced tools
Comparing version 23.0.0-alpha.2 to 23.0.0-alpha.4
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
@@ -34,3 +34,5 @@ }); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
@@ -41,9 +43,9 @@ // stack utils tries to create pretty stack by making paths relative. | ||
}); /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/ | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/ | ||
@@ -53,6 +55,7 @@ let nodeInternals = []; | ||
try { | ||
nodeInternals = _stackUtils2.default.nodeInternals() | ||
// this is to have the tests be the same in node 4 and node 6. | ||
// TODO: Remove when we drop support for node 4 | ||
.concat(new RegExp('internal/process/next_tick.js')); | ||
nodeInternals = _stackUtils2.default | ||
.nodeInternals() | ||
// this is to have the tests be the same in node 4 and node 6. | ||
// TODO: Remove when we drop support for node 4 | ||
.concat(new RegExp('internal/process/next_tick.js')); | ||
} catch (e) { | ||
@@ -63,4 +66,8 @@ // `StackUtils.nodeInternals()` fails in browsers. We don't need to remove | ||
const PATH_NODE_MODULES = `${_path2.default.sep}node_modules${_path2.default.sep}`; | ||
const PATH_JEST_PACKAGES = `${_path2.default.sep}jest${_path2.default.sep}packages${_path2.default.sep}`; | ||
const PATH_NODE_MODULES = `${_path2.default.sep}node_modules${ | ||
_path2.default.sep | ||
}`; | ||
const PATH_JEST_PACKAGES = `${_path2.default.sep}jest${ | ||
_path2.default.sep | ||
}packages${_path2.default.sep}`; | ||
@@ -90,8 +97,16 @@ // filter for noisy stack trace lines | ||
// which will get misaligned. | ||
const trimPaths = string => string.match(STACK_PATH_REGEXP) ? trim(string) : string; | ||
const trimPaths = string => | ||
string.match(STACK_PATH_REGEXP) ? trim(string) : string; | ||
const getRenderedCallsite = (fileContent, line) => { | ||
let renderedCallsite = (0, _codeFrame.codeFrameColumns)(fileContent, { start: { line } }, { highlightCode: true }); | ||
let renderedCallsite = (0, _codeFrame.codeFrameColumns)( | ||
fileContent, | ||
{start: {line}}, | ||
{highlightCode: true} | ||
); | ||
renderedCallsite = renderedCallsite.split('\n').map(line => MESSAGE_INDENT + line).join('\n'); | ||
renderedCallsite = renderedCallsite | ||
.split('\n') | ||
.map(line => MESSAGE_INDENT + line) | ||
.join('\n'); | ||
@@ -105,3 +120,8 @@ renderedCallsite = `\n${renderedCallsite}\n`; | ||
// are executed. | ||
const formatExecError = exports.formatExecError = (testResult, config, options, testPath) => { | ||
const formatExecError = (exports.formatExecError = ( | ||
testResult, | ||
config, | ||
options, | ||
testPath | ||
) => { | ||
let error = testResult.testExecError; | ||
@@ -115,5 +135,4 @@ if (!error || typeof error === 'number') { | ||
let message = _error.message, | ||
stack = _error.stack; | ||
stack = _error.stack; | ||
if (typeof error === 'string' || !error) { | ||
@@ -133,4 +152,10 @@ error || (error = 'EMPTY ERROR'); | ||
message = message.split(/\n/).map(line => MESSAGE_INDENT + line).join('\n'); | ||
stack = stack && !options.noStackTrace ? '\n' + formatStackTrace(stack, config, options, testPath) : ''; | ||
message = message | ||
.split(/\n/) | ||
.map(line => MESSAGE_INDENT + line) | ||
.join('\n'); | ||
stack = | ||
stack && !options.noStackTrace | ||
? '\n' + formatStackTrace(stack, config, options, testPath) | ||
: ''; | ||
@@ -142,4 +167,12 @@ if (message.match(/^\s*$/) && stack.match(/^\s*$/)) { | ||
return TITLE_INDENT + TITLE_BULLET + EXEC_ERROR_MESSAGE + '\n\n' + message + stack + '\n'; | ||
}; | ||
return ( | ||
TITLE_INDENT + | ||
TITLE_BULLET + | ||
EXEC_ERROR_MESSAGE + | ||
'\n\n' + | ||
message + | ||
stack + | ||
'\n' | ||
); | ||
}); | ||
@@ -201,5 +234,12 @@ const removeInternalStackEntries = (lines, options) => { | ||
let filePath = (0, _slash2.default)(_path2.default.relative(config.rootDir, match[2])); | ||
let filePath = (0, _slash2.default)( | ||
_path2.default.relative(config.rootDir, match[2]) | ||
); | ||
// highlight paths from the current test file | ||
if (config.testMatch && config.testMatch.length && (0, _micromatch2.default)(filePath, config.testMatch) || filePath === relativeTestPath) { | ||
if ( | ||
(config.testMatch && | ||
config.testMatch.length && | ||
(0, _micromatch2.default)(filePath, config.testMatch)) || | ||
filePath === relativeTestPath | ||
) { | ||
filePath = _chalk2.default.reset.cyan(filePath); | ||
@@ -226,6 +266,13 @@ } | ||
const formatStackTrace = exports.formatStackTrace = (stack, config, options, testPath) => { | ||
const formatStackTrace = (exports.formatStackTrace = ( | ||
stack, | ||
config, | ||
options, | ||
testPath | ||
) => { | ||
let lines = stack.split(/\n/); | ||
let renderedCallsite = ''; | ||
const relativeTestPath = testPath ? (0, _slash2.default)(_path2.default.relative(config.rootDir, testPath)) : null; | ||
const relativeTestPath = testPath | ||
? (0, _slash2.default)(_path2.default.relative(config.rootDir, testPath)) | ||
: null; | ||
lines = removeInternalStackEntries(lines, options); | ||
@@ -251,10 +298,21 @@ | ||
const stacktrace = lines.map(line => STACK_INDENT + formatPaths(config, options, relativeTestPath, trimPaths(line))).join('\n'); | ||
const stacktrace = lines | ||
.map( | ||
line => | ||
STACK_INDENT + | ||
formatPaths(config, options, relativeTestPath, trimPaths(line)) | ||
) | ||
.join('\n'); | ||
return renderedCallsite + stacktrace; | ||
}; | ||
}); | ||
const formatResultsErrors = exports.formatResultsErrors = (testResults, config, options, testPath) => { | ||
const formatResultsErrors = (exports.formatResultsErrors = ( | ||
testResults, | ||
config, | ||
options, | ||
testPath | ||
) => { | ||
const failedResults = testResults.reduce((errors, result) => { | ||
result.failureMessages.forEach(content => errors.push({ content, result })); | ||
result.failureMessages.forEach(content => errors.push({content, result})); | ||
return errors; | ||
@@ -267,20 +325,36 @@ }, []); | ||
return failedResults.map((_ref) => { | ||
let result = _ref.result, | ||
return failedResults | ||
.map(_ref => { | ||
let result = _ref.result, | ||
content = _ref.content; | ||
var _separateMessageFromS = separateMessageFromStack(content); | ||
var _separateMessageFromS = separateMessageFromStack(content); | ||
let message = _separateMessageFromS.message, | ||
let message = _separateMessageFromS.message, | ||
stack = _separateMessageFromS.stack; | ||
stack = options.noStackTrace ? '' : STACK_TRACE_COLOR(formatStackTrace(stack, config, options, testPath)) + '\n'; | ||
stack = options.noStackTrace | ||
? '' | ||
: STACK_TRACE_COLOR( | ||
formatStackTrace(stack, config, options, testPath) | ||
) + '\n'; | ||
message = message.split(/\n/).map(line => MESSAGE_INDENT + line).join('\n'); | ||
message = message | ||
.split(/\n/) | ||
.map(line => MESSAGE_INDENT + line) | ||
.join('\n'); | ||
const title = _chalk2.default.bold.red(TITLE_INDENT + TITLE_BULLET + result.ancestorTitles.join(ANCESTRY_SEPARATOR) + (result.ancestorTitles.length ? ANCESTRY_SEPARATOR : '') + result.title) + '\n'; | ||
const title = | ||
_chalk2.default.bold.red( | ||
TITLE_INDENT + | ||
TITLE_BULLET + | ||
result.ancestorTitles.join(ANCESTRY_SEPARATOR) + | ||
(result.ancestorTitles.length ? ANCESTRY_SEPARATOR : '') + | ||
result.title | ||
) + '\n'; | ||
return title + '\n' + message + '\n' + stack; | ||
}).join('\n'); | ||
}; | ||
return title + '\n' + message + '\n' + stack; | ||
}) | ||
.join('\n'); | ||
}); | ||
@@ -290,5 +364,5 @@ // jasmine and worker farm sometimes don't give us access to the actual | ||
// to format it. | ||
const separateMessageFromStack = exports.separateMessageFromStack = content => { | ||
const separateMessageFromStack = (exports.separateMessageFromStack = content => { | ||
if (!content) { | ||
return { message: '', stack: '' }; | ||
return {message: '', stack: ''}; | ||
} | ||
@@ -304,3 +378,3 @@ | ||
} | ||
return { message, stack }; | ||
}; | ||
return {message, stack}; | ||
}); |
{ | ||
"name": "jest-message-util", | ||
"version": "23.0.0-alpha.2", | ||
"version": "23.0.0-alpha.4", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
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
10364
297