jest-util
Advanced tools
Comparing version 14.0.0 to 14.2.0-alpha.ca8bfb6e
@@ -22,28 +22,28 @@ /** | ||
if (appendedLastLine.length > 80) { | ||
wrappedDesc.push(word);} else | ||
{ | ||
wrappedDesc[lastLineIdx] = appendedLastLine;} | ||
wrappedDesc.push(word); | ||
} else { | ||
wrappedDesc[lastLineIdx] = appendedLastLine; | ||
} | ||
return wrappedDesc; | ||
}, ['']).join(indent); | ||
} | ||
return wrappedDesc;}, | ||
['']).join(indent);} | ||
const warnAboutUnrecognizedOptions = (argv, options) => { | ||
const yargsSpecialOptions = ['$0', '_']; | ||
const allowedOptions = Object.keys(options).reduce((acc, option) => | ||
const allowedOptions = Object.keys(options).reduce((acc, option) => | ||
acc. | ||
add(option). | ||
add(options[option].alias), | ||
add(options[option].alias), | ||
new Set(yargsSpecialOptions)); | ||
const unrecognizedOptions = Object.keys(argv).filter(arg => | ||
const unrecognizedOptions = Object.keys(argv).filter(arg => | ||
!allowedOptions.has(arg)); | ||
if (unrecognizedOptions.length) { | ||
console.warn('Unrecognized options: ' + unrecognizedOptions.join(', '));}}; | ||
console.warn('Unrecognized options: ' + unrecognizedOptions.join(', ')); | ||
} | ||
}; | ||
module.exports = { | ||
warnAboutUnrecognizedOptions, | ||
module.exports = { | ||
warnAboutUnrecognizedOptions, | ||
wrap }; |
@@ -40,10 +40,10 @@ /** | ||
warn() { | ||
return super.warn(chalk.yellow(util.format.apply(this, arguments)));} | ||
return super.warn(chalk.yellow(util.format.apply(this, arguments))); | ||
} | ||
error() { | ||
return super.error(chalk.red(util.format.apply(this, arguments)));}} | ||
return super.error(chalk.red(util.format.apply(this, arguments))); | ||
}} | ||
module.exports = CustomConsole; |
@@ -69,17 +69,17 @@ /** | ||
// Store original timer APIs for future reference | ||
this._timerAPIs = { | ||
clearImmediate: global.clearImmediate, | ||
clearInterval: global.clearInterval, | ||
clearTimeout: global.clearTimeout, | ||
setImmediate: global.setImmediate, | ||
setInterval: global.setInterval, | ||
this._timerAPIs = { | ||
clearImmediate: global.clearImmediate, | ||
clearInterval: global.clearInterval, | ||
clearTimeout: global.clearTimeout, | ||
setImmediate: global.setImmediate, | ||
setInterval: global.setInterval, | ||
setTimeout: global.setTimeout }; | ||
this._fakeTimerAPIs = { | ||
clearImmediate: fn(this._fakeClearImmediate.bind(this)), | ||
clearInterval: fn(this._fakeClearTimer.bind(this)), | ||
clearTimeout: fn(this._fakeClearTimer.bind(this)), | ||
setImmediate: fn(this._fakeSetImmediate.bind(this)), | ||
setInterval: fn(this._fakeSetInterval.bind(this)), | ||
this._fakeTimerAPIs = { | ||
clearImmediate: fn(this._fakeClearImmediate.bind(this)), | ||
clearInterval: fn(this._fakeClearTimer.bind(this)), | ||
clearTimeout: fn(this._fakeClearTimer.bind(this)), | ||
setImmediate: fn(this._fakeSetImmediate.bind(this)), | ||
setInterval: fn(this._fakeSetInterval.bind(this)), | ||
setTimeout: fn(this._fakeSetTimeout.bind(this)) }; | ||
@@ -90,8 +90,8 @@ | ||
// (only applicable to node/node-emulating environments) | ||
if (typeof global.process === 'object' && | ||
if (typeof global.process === 'object' && | ||
typeof global.process.nextTick === 'function') { | ||
this._timerAPIs.nextTick = global.process.nextTick; | ||
this._fakeTimerAPIs.nextTick = fn(this._fakeNextTick.bind(this));} | ||
this._fakeTimerAPIs.nextTick = fn(this._fakeNextTick.bind(this)); | ||
} | ||
this.useFakeTimers(); | ||
@@ -107,5 +107,5 @@ | ||
global.mockClearTimers = this.clearAllTimers.bind(this); | ||
global.mockGetTimersCount = () => Object.keys(this._timers).length;} | ||
global.mockGetTimersCount = () => Object.keys(this._timers).length; | ||
} | ||
clearAllTimers() { | ||
@@ -116,11 +116,11 @@ this._immediates.forEach( | ||
for (const uuid in this._timers) { | ||
delete this._timers[uuid];}} | ||
delete this._timers[uuid]; | ||
} | ||
} | ||
dispose() { | ||
this._disposed = true; | ||
this.clearAllTimers();} | ||
this.clearAllTimers(); | ||
} | ||
reset() { | ||
@@ -132,5 +132,5 @@ this._cancelledTicks = {}; | ||
this._immediates = []; | ||
this._timers = {};} | ||
this._timers = {}; | ||
} | ||
// Used to be called runTicksRepeatedly | ||
@@ -145,20 +145,20 @@ runAllTicks() { | ||
if (tick === undefined) { | ||
break;} | ||
break; | ||
} | ||
if (!this._cancelledTicks.hasOwnProperty(tick.uuid)) { | ||
// Callback may throw, so update the map prior calling. | ||
this._cancelledTicks[tick.uuid] = true; | ||
tick.callback();}} | ||
tick.callback(); | ||
} | ||
} | ||
if (i === this._maxLoops) { | ||
throw new Error( | ||
'Ran ' + this._maxLoops + ' ticks, and there are still more! ' + | ||
'Assuming we\'ve hit an infinite recursion and bailing out...');}} | ||
'Ran ' + this._maxLoops + ' ticks, and there are still more! ' + | ||
'Assuming we\'ve hit an infinite recursion and bailing out...'); | ||
} | ||
} | ||
runAllImmediates() { | ||
@@ -170,16 +170,16 @@ // Only run a generous number of immediates and then bail. | ||
if (immediate === undefined) { | ||
break;} | ||
break; | ||
} | ||
this._runImmediate(immediate); | ||
} | ||
this._runImmediate(immediate);} | ||
if (i === this._maxLoops) { | ||
throw new Error( | ||
'Ran ' + this._maxLoops + | ||
' immediates, and there are still more! Assuming ' + | ||
'we\'ve hit an infinite recursion and bailing out...');}} | ||
'Ran ' + this._maxLoops + | ||
' immediates, and there are still more! Assuming ' + | ||
'we\'ve hit an infinite recursion and bailing out...'); | ||
} | ||
} | ||
_runImmediate(immediate) { | ||
@@ -189,6 +189,6 @@ if (!this._cancelledImmediates.hasOwnProperty(immediate.uuid)) { | ||
this._cancelledImmediates[immediate.uuid] = true; | ||
immediate.callback();}} | ||
immediate.callback(); | ||
} | ||
} | ||
// Used to be called runTimersRepeatedly | ||
@@ -207,5 +207,5 @@ runAllTimers() { | ||
if (nextTimerHandle === null) { | ||
break;} | ||
break; | ||
} | ||
this._runTimerHandle(nextTimerHandle); | ||
@@ -217,14 +217,14 @@ | ||
if (this._immediates.length) { | ||
this.runAllImmediates();}} | ||
this.runAllImmediates(); | ||
} | ||
} | ||
if (i === this._maxLoops) { | ||
throw new Error( | ||
'Ran ' + this._maxLoops + ' timers, and there are still more! ' + | ||
'Assuming we\'ve hit an infinite recursion and bailing out...');}} | ||
'Ran ' + this._maxLoops + ' timers, and there are still more! ' + | ||
'Assuming we\'ve hit an infinite recursion and bailing out...'); | ||
} | ||
} | ||
// Used to be called runTimersOnce | ||
@@ -236,5 +236,5 @@ runOnlyPendingTimers() { | ||
sort((left, right) => timers[left].expiry - timers[right].expiry). | ||
forEach(this._runTimerHandle, this);} | ||
forEach(this._runTimerHandle, this); | ||
} | ||
// Use to be runTimersToTime | ||
@@ -250,5 +250,5 @@ runTimersToTime(msToRun) { | ||
if (timerHandle === null) { | ||
break;} | ||
break; | ||
} | ||
const nextTimerExpiry = this._timers[timerHandle].expiry; | ||
@@ -259,21 +259,21 @@ if (this._now + msToRun < nextTimerExpiry) { | ||
this._now += msToRun; | ||
break;} else | ||
{ | ||
break; | ||
} else { | ||
msToRun -= nextTimerExpiry - this._now; | ||
this._now = nextTimerExpiry; | ||
this._runTimerHandle(timerHandle);}} | ||
this._runTimerHandle(timerHandle); | ||
} | ||
} | ||
if (i === this._maxLoops) { | ||
throw new Error( | ||
'Ran ' + this._maxLoops + ' timers, and there are still more! ' + | ||
'Assuming we\'ve hit an infinite recursion and bailing out...');}} | ||
'Ran ' + this._maxLoops + ' timers, and there are still more! ' + | ||
'Assuming we\'ve hit an infinite recursion and bailing out...'); | ||
} | ||
} | ||
runWithRealTimers(cb) { | ||
const hasNextTick = | ||
typeof this._global.process === 'object' && | ||
const hasNextTick = | ||
typeof this._global.process === 'object' && | ||
typeof this._global.process.nextTick === 'function'; | ||
@@ -295,8 +295,8 @@ | ||
try { | ||
cb();} | ||
catch (e) { | ||
cb(); | ||
} catch (e) { | ||
errThrown = true; | ||
cbErr = e;} | ||
cbErr = e; | ||
} | ||
this._global.clearImmediate = prevClearImmediate; | ||
@@ -309,13 +309,13 @@ this._global.clearInterval = prevClearInterval; | ||
if (hasNextTick) { | ||
this._global.process.nextTick = prevNextTick;} | ||
this._global.process.nextTick = prevNextTick; | ||
} | ||
if (errThrown) { | ||
throw cbErr;}} | ||
throw cbErr; | ||
} | ||
} | ||
useRealTimers() { | ||
const hasNextTick = | ||
typeof this._global.process === 'object' && | ||
const hasNextTick = | ||
typeof this._global.process === 'object' && | ||
typeof this._global.process.nextTick === 'function'; | ||
@@ -330,9 +330,9 @@ | ||
if (hasNextTick) { | ||
this._global.process.nextTick = this._timerAPIs.nextTick;}} | ||
this._global.process.nextTick = this._timerAPIs.nextTick; | ||
} | ||
} | ||
useFakeTimers() { | ||
const hasNextTick = | ||
typeof this._global.process === 'object' && | ||
const hasNextTick = | ||
typeof this._global.process === 'object' && | ||
typeof this._global.process.nextTick === 'function'; | ||
@@ -347,30 +347,30 @@ | ||
if (hasNextTick) { | ||
this._global.process.nextTick = this._fakeTimerAPIs.nextTick;}} | ||
this._global.process.nextTick = this._fakeTimerAPIs.nextTick; | ||
} | ||
} | ||
_fakeClearTimer(uuid) { | ||
if (this._timers.hasOwnProperty(uuid)) { | ||
delete this._timers[uuid];}} | ||
delete this._timers[uuid]; | ||
} | ||
} | ||
_fakeClearImmediate(uuid) { | ||
this._cancelledImmediates[uuid] = true;} | ||
this._cancelledImmediates[uuid] = true; | ||
} | ||
_fakeNextTick(callback) { | ||
if (this._disposed) { | ||
return;} | ||
return; | ||
} | ||
const args = []; | ||
for (let ii = 1, ll = arguments.length; ii < ll; ii++) { | ||
args.push(arguments[ii]);} | ||
args.push(arguments[ii]); | ||
} | ||
const uuid = String(this._uuidCounter++); | ||
this._ticks.push({ | ||
uuid, | ||
this._ticks.push({ | ||
uuid, | ||
callback: () => callback.apply(null, args) }); | ||
@@ -385,21 +385,21 @@ | ||
cancelledTicks[uuid] = true; | ||
callback.apply(null, args);}});} | ||
callback.apply(null, args); | ||
} | ||
}); | ||
} | ||
_fakeSetImmediate(callback) { | ||
if (this._disposed) { | ||
return null;} | ||
return null; | ||
} | ||
const args = []; | ||
for (let ii = 1, ll = arguments.length; ii < ll; ii++) { | ||
args.push(arguments[ii]);} | ||
args.push(arguments[ii]); | ||
} | ||
const uuid = this._uuidCounter++; | ||
this._immediates.push({ | ||
uuid: String(uuid), | ||
this._immediates.push({ | ||
uuid: String(uuid), | ||
callback: () => callback.apply(null, args) }); | ||
@@ -413,61 +413,61 @@ | ||
cancelledImmediates[String(uuid)] = true; | ||
callback.apply(null, args);}}); | ||
callback.apply(null, args); | ||
} | ||
}); | ||
return uuid; | ||
} | ||
return uuid;} | ||
_fakeSetInterval(callback, intervalDelay) { | ||
if (this._disposed) { | ||
return null;} | ||
return null; | ||
} | ||
if (intervalDelay == null) { | ||
intervalDelay = 0;} | ||
intervalDelay = 0; | ||
} | ||
const args = []; | ||
for (let ii = 2, ll = arguments.length; ii < ll; ii++) { | ||
args.push(arguments[ii]);} | ||
args.push(arguments[ii]); | ||
} | ||
const uuid = this._uuidCounter++; | ||
this._timers[String(uuid)] = { | ||
type: 'interval', | ||
callback: () => callback.apply(null, args), | ||
expiry: this._now + intervalDelay, | ||
this._timers[String(uuid)] = { | ||
type: 'interval', | ||
callback: () => callback.apply(null, args), | ||
expiry: this._now + intervalDelay, | ||
interval: intervalDelay }; | ||
return uuid;} | ||
return uuid; | ||
} | ||
_fakeSetTimeout(callback, delay) { | ||
if (this._disposed) { | ||
return null;} | ||
return null; | ||
} | ||
if (delay == null) { | ||
delay = 0;} | ||
delay = 0; | ||
} | ||
const args = []; | ||
for (let ii = 2, ll = arguments.length; ii < ll; ii++) { | ||
args.push(arguments[ii]);} | ||
args.push(arguments[ii]); | ||
} | ||
const uuid = this._uuidCounter++; | ||
this._timers[String(uuid)] = { | ||
type: 'timeout', | ||
callback: () => callback.apply(null, args), | ||
expiry: this._now + delay, | ||
this._timers[String(uuid)] = { | ||
type: 'timeout', | ||
callback: () => callback.apply(null, args), | ||
expiry: this._now + delay, | ||
interval: null }; | ||
return uuid;} | ||
return uuid; | ||
} | ||
_getNextTimerHandle() { | ||
@@ -482,9 +482,9 @@ let nextTimerHandle = null; | ||
soonestTime = timer.expiry; | ||
nextTimerHandle = uuid;}} | ||
nextTimerHandle = uuid; | ||
} | ||
} | ||
return nextTimerHandle; | ||
} | ||
return nextTimerHandle;} | ||
_runTimerHandle(timerHandle) { | ||
@@ -494,5 +494,5 @@ const timer = this._timers[timerHandle]; | ||
if (!timer) { | ||
return;} | ||
return; | ||
} | ||
switch (timer.type) { | ||
@@ -511,8 +511,8 @@ case 'timeout': | ||
default: | ||
throw new Error('Unexpected timer type: ' + timer.type);}}} | ||
throw new Error('Unexpected timer type: ' + timer.type);} | ||
}} | ||
module.exports = FakeTimers; |
@@ -17,79 +17,151 @@ /** | ||
const path = require('path'); | ||
const separateMessageFromStack = require('./separateMessageFromStack'); | ||
const ERROR_TITLE_COLOR = chalk.bold.red; | ||
// filter for noisy stack trace lines | ||
const JASMINE_IGNORE = | ||
const JASMINE_IGNORE = | ||
/^\s+at(?:(?:.*?vendor\/|jasmine\-)|\s+jasmine\.buildExpectationResult)/; | ||
const STACK_TRACE_IGNORE = | ||
const STACK_TRACE_IGNORE = | ||
/^\s+at.*?jest(-.*?)?(\/|\\)(vendor|build|node_modules|packages)(\/|\\)/; | ||
const TITLE_INDENT = ' '; | ||
const MESSAGE_INDENT = ' '; | ||
const STACK_INDENT = ' '; | ||
const ANCESTRY_SEPARATOR = ' \u203A '; | ||
const TITLE_BULLET = chalk.bold('\u25cf '); | ||
const STACK_TRACE_COLOR = chalk.gray; | ||
const ERROR_MESSAGE_COLOR = chalk.red; | ||
const STACK_PATH_REGEXP = /\s*at.*\(?(\:\d*\:\d*|native)\)?/; | ||
const EXEC_ERROR_MESSAGE = 'Test suite failed to run:'; | ||
const formatStackTrace = (stackTrace, config) => { | ||
const msgBullet = ' - '; | ||
const msgIndent = msgBullet.replace(/./g, ' '); | ||
let stackTraceLines = 0; | ||
return msgBullet + stackTrace | ||
// jasmine doesn't give us access to the actual Error object, so we | ||
// have to regexp out the message from the stack string in order to | ||
// colorize the `message` value | ||
.replace(/(^(.|\n)*?(?=\n\s*at\s))/, ERROR_TITLE_COLOR('$1')). | ||
split('\n'). | ||
map(line => { | ||
// Extract the file path from the trace line. | ||
let matches = line.match(/(^\s+at .*?\()([^()]+)(:[0-9]+:[0-9]+\).*$)/); | ||
if (!matches) { | ||
matches = line.match(/(^\s+at )([^()]+)(:[0-9]+:[0-9]+.*$)/); | ||
if (!matches) { | ||
return line;}} | ||
const trim = string => string.replace(/^\s+/, '').replace(/\s+$/, ''); | ||
// 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; | ||
// 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 = ( | ||
testResult, | ||
config, | ||
testPath) => | ||
{ | ||
const error = testResult.testExecError;let | ||
message = error.message;let stack = error.stack; | ||
// Filter out noisy and unhelpful lines from the stack trace. | ||
// Always keep the first stack trace line (except Jasmine), | ||
// even if it comes from Jest. | ||
stackTraceLines++; | ||
if ( | ||
config.noStackTrace || | ||
JASMINE_IGNORE.test(line) || | ||
STACK_TRACE_IGNORE.test(line) && stackTraceLines > 1) | ||
{ | ||
return null;} | ||
const separated = separateMessageFromStack(stack || ''); | ||
stack = separated.stack; | ||
if (separated.message.indexOf(trim(message)) !== -1) { | ||
// Often stack trace already contains the duplicate of the message | ||
message = separated.message; | ||
} else { | ||
message = message + '\n' + separated.message; | ||
} | ||
const filePath = matches[2]; | ||
return matches[1] + path.relative(config.rootDir, filePath) + matches[3];}). | ||
message = message.split(/\n/).map(line => MESSAGE_INDENT + line).join('\n'); | ||
filter(line => line !== null). | ||
join('\n' + msgIndent);}; | ||
message = message && ERROR_MESSAGE_COLOR(message); | ||
stack = stack && !config.noStackTrace ? | ||
'\n' + STACK_TRACE_COLOR(formatStackTrace(stack, config, testPath)) : | ||
''; | ||
return TITLE_INDENT + ERROR_MESSAGE_COLOR(EXEC_ERROR_MESSAGE) + '\n' + | ||
message + stack + '\n'; | ||
}; | ||
const formatFailureMessage = (testResult, config) => { | ||
const ancestrySeparator = ' \u203A '; | ||
const descBullet = config.verbose ? ' ' : chalk.bold('\u25cf '); | ||
const removeInternalStackEntries = (lines, config) => { | ||
let pathCounter = 0; | ||
if (testResult.testExecError) { | ||
const error = testResult.testExecError; | ||
return ( | ||
descBullet + ( | ||
config.verbose ? 'Runtime Error' : chalk.bold('Runtime Error')) + '\n' + ( | ||
error.stack ? formatStackTrace(error.stack, config) : error.message));} | ||
return lines.filter(line => { | ||
const isPath = STACK_PATH_REGEXP.test(line); | ||
if (!isPath) { | ||
return true; | ||
} | ||
if (JASMINE_IGNORE.test(line)) { | ||
return false; | ||
} | ||
if (++pathCounter === 1) { | ||
return true; // always keep the first line even if it's from Jest | ||
} | ||
return !(STACK_TRACE_IGNORE.test(line) || config.noStackTrace); | ||
}); | ||
}; | ||
return testResult.testResults. | ||
filter(result => result.failureMessages.length !== 0). | ||
map(result => { | ||
const failureMessages = result.failureMessages. | ||
map(stackTrace => formatStackTrace(stackTrace, config)). | ||
join('\n'); | ||
const formatPaths = (config, relativeTestPath, line) => { | ||
// Extract the file path from the trace line. | ||
let matches = line.match(/(^\s*at .*?\()([^()]+)(:[0-9]+:[0-9]+\).*$)/); | ||
if (!matches) { | ||
matches = line.match(/(^\s+at )([^()]+)(:[0-9]+:[0-9]+.*$)/); | ||
if (!matches) { | ||
return line; | ||
} | ||
} | ||
const testTitleAncestry = result.ancestorTitles. | ||
map(title => chalk.bold(title)). | ||
join(ancestrySeparator); | ||
let filePath = matches[2]; | ||
filePath = path.relative(config.rootDir, filePath); | ||
return descBullet + testTitleAncestry + ancestrySeparator + result.title + | ||
'\n' + failureMessages;}). | ||
if (filePath === relativeTestPath) { | ||
// highlight paths from the current test file | ||
filePath = chalk.cyan(filePath); | ||
} | ||
// make paths relative to the <rootDir> | ||
return matches[1] + filePath + matches[3]; | ||
}; | ||
join('\n');}; | ||
const formatStackTrace = (stack, config, testPath) => { | ||
let lines = stack.split(/\n/); | ||
const relativeTestPath = testPath ? | ||
path.relative(config.rootDir, testPath) : | ||
null; | ||
lines = removeInternalStackEntries(lines, config); | ||
return lines.map(trimPaths). | ||
map(formatPaths.bind(null, config, relativeTestPath)). | ||
map(line => STACK_INDENT + line). | ||
join('\n'); | ||
}; | ||
const formatResultsErrors = ( | ||
testResults, | ||
config, | ||
testPath) => | ||
{ | ||
const failedResults = testResults.testResults.reduce( | ||
(errors, result) => { | ||
result.failureMessages.forEach(content => errors.push({ result, content })); | ||
return errors; | ||
}, | ||
[]); | ||
module.exports = formatFailureMessage; | ||
if (!failedResults.length) { | ||
return null; | ||
} | ||
return failedResults.map(_ref => {let result = _ref.result;let content = _ref.content;var _separateMessageFromS = | ||
separateMessageFromStack(content);let message = _separateMessageFromS.message;let stack = _separateMessageFromS.stack; | ||
stack = config.noStackTrace ? | ||
'' : | ||
STACK_TRACE_COLOR(formatStackTrace(stack, config, testPath)) + '\n'; | ||
message = message. | ||
split(/\n/). | ||
map(line => MESSAGE_INDENT + line). | ||
join('\n'); | ||
const title = TITLE_INDENT + TITLE_BULLET + | ||
result.ancestorTitles.join(ANCESTRY_SEPARATOR) + | ||
ANCESTRY_SEPARATOR + result.title + '\n'; | ||
return title + '\n' + ERROR_MESSAGE_COLOR(message) + '\n' + stack; | ||
}).join('\n'); | ||
}; | ||
module.exports = { | ||
formatExecError, | ||
formatResultsErrors }; |
@@ -17,3 +17,3 @@ /** | ||
const escapeStrForRegex = | ||
const escapeStrForRegex = | ||
string => string.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); | ||
@@ -23,17 +23,17 @@ | ||
if (path.sep === '\\') { | ||
return string.replace(/(\/|\\(?!\.))/g, '\\\\');} | ||
return string.replace(/(\/|\\(?!\.))/g, '\\\\'); | ||
} | ||
return string; | ||
}; | ||
return string;}; | ||
const createDirectory = path => { | ||
try { | ||
mkdirp.sync(path, '777');} | ||
catch (e) { | ||
mkdirp.sync(path, '777'); | ||
} catch (e) { | ||
if (e.code !== 'EEXIST') { | ||
throw e;}}}; | ||
throw e; | ||
} | ||
} | ||
}; | ||
const getPackageRoot = () => { | ||
@@ -47,10 +47,10 @@ const cwd = process.cwd(); | ||
root = cwd; | ||
break;} | ||
break; | ||
} | ||
root = path.resolve(root, '..'); | ||
} | ||
root = path.resolve(root, '..');} | ||
return root; | ||
}; | ||
return root;}; | ||
exports.Console = require('./Console'); | ||
@@ -63,8 +63,11 @@ exports.FakeTimers = require('./FakeTimers'); | ||
exports.escapeStrForRegex = escapeStrForRegex; | ||
exports.formatFailureMessage = require('./formatFailureMessage'); | ||
exports.formatResultsErrors = | ||
require('./formatFailureMessage').formatResultsErrors; | ||
exports.formatExecError = require('./formatFailureMessage').formatExecError; | ||
exports.getPackageRoot = getPackageRoot; | ||
exports.installCommonGlobals = require('./installCommonGlobals'); | ||
exports.replacePathSepForRegex = replacePathSepForRegex; | ||
exports.warnAboutUnrecognizedOptions = | ||
exports.separateMessageFromStack = require('./separateMessageFromStack'); | ||
exports.warnAboutUnrecognizedOptions = | ||
require('./args').warnAboutUnrecognizedOptions; | ||
exports.wrap = require('./args').wrap; |
@@ -21,9 +21,9 @@ /** | ||
if (typeof value === 'object' && value !== null) { | ||
value = deepCopy(value);} | ||
value = deepCopy(value); | ||
} | ||
newObj[key] = value; | ||
} | ||
return newObj; | ||
} | ||
newObj[key] = value;} | ||
return newObj;} | ||
module.exports = (global, globals) => { | ||
@@ -50,2 +50,3 @@ // Forward some APIs | ||
Object.assign(global, deepCopy(globals));}; | ||
Object.assign(global, deepCopy(globals)); | ||
}; |
@@ -34,15 +34,15 @@ /** | ||
/* $FlowFixMe */ | ||
this._diffableMatchers = Object.assign(Object.create(null), { | ||
toBe: true, | ||
toNotBe: true, | ||
toEqual: true, | ||
toNotEqual: true });} | ||
this._diffableMatchers = Object.assign(Object.create(null), { | ||
toBe: true, | ||
toNotBe: true, | ||
toEqual: true, | ||
toNotEqual: true }); | ||
} | ||
formatDiffable( | ||
matcherName, | ||
isNot, | ||
actual, | ||
expected) | ||
matcherName, | ||
isNot, | ||
actual, | ||
expected) | ||
{ | ||
@@ -55,24 +55,24 @@ const ppActual = this.prettyPrint(actual); | ||
return ( | ||
ERROR_TITLE_COLOR('Expected:') + ' ' + colorDiff.a + ' ' + | ||
ERROR_TITLE_COLOR(matcherName + ':') + ' ' + colorDiff.b);} | ||
ERROR_TITLE_COLOR('Expected:') + ' ' + colorDiff.a + ' ' + | ||
ERROR_TITLE_COLOR(matcherName + ':') + ' ' + colorDiff.b); | ||
} | ||
formatMatchFailure(result) { | ||
let message; | ||
if (this._diffableMatchers[result.matcherName]) { | ||
const isNot = !!('isNot' in result ? | ||
result.isNot : | ||
const isNot = !!('isNot' in result ? | ||
result.isNot : | ||
/not to /.test(result.message || '')); | ||
message = this.formatDiffable( | ||
result.matcherName, | ||
isNot, | ||
result.actual, | ||
result.expected);} else | ||
result.matcherName, | ||
isNot, | ||
result.actual, | ||
result.expected); | ||
{ | ||
message = ERROR_TITLE_COLOR(result.message);} | ||
} else { | ||
message = ERROR_TITLE_COLOR(result.message); | ||
} | ||
if (!this._config.noStackTrace && result.stack) { | ||
@@ -82,7 +82,7 @@ const errorMessage = result.message || ''; | ||
replace(message, errorMessage). | ||
replace(/^.*Error:\s*/, '');} | ||
replace(/^.*Error:\s*/, ''); | ||
} | ||
return message; | ||
} | ||
return message;} | ||
highlightDifferences(a, b) { | ||
@@ -95,6 +95,6 @@ let differ; | ||
// whenever linebreaks are involved. | ||
differ = diff.diffLines;} else | ||
{ | ||
differ = diff.diffChars;} | ||
differ = diff.diffLines; | ||
} else { | ||
differ = diff.diffChars; | ||
} | ||
const changes = differ(a, b); | ||
@@ -105,27 +105,27 @@ const ret = { a: '', b: '' }; | ||
if (change.added) { | ||
ret.b += chalk.bgRed(change.value);} else | ||
if (change.removed) { | ||
ret.a += chalk.bgRed(change.value);} else | ||
{ | ||
ret.b += chalk.bgRed(change.value); | ||
} else if (change.removed) { | ||
ret.a += chalk.bgRed(change.value); | ||
} else { | ||
ret.a += change.value; | ||
ret.b += change.value;}} | ||
ret.b += change.value; | ||
} | ||
} | ||
return ret; | ||
} | ||
return ret;} | ||
prettyPrint( | ||
object, | ||
indent, | ||
cycleWeakMap) | ||
object, | ||
indent, | ||
cycleWeakMap) | ||
{ | ||
if (!indent) { | ||
indent = '';} | ||
indent = ''; | ||
} | ||
if (typeof object === 'object' && object !== null) { | ||
if ( | ||
this._environment.global.Node && | ||
object instanceof this._environment.global.Node && | ||
object.nodeType > 0) | ||
this._environment.global.Node && | ||
object instanceof this._environment.global.Node && | ||
object.nodeType > 0) | ||
{ | ||
@@ -137,19 +137,19 @@ let attrStr = ''; | ||
const attrValue = attr.value.trim(); | ||
attrStr += ' ' + attrName + '="' + attrValue + '"';}); | ||
attrStr += ' ' + attrName + '="' + attrValue + '"'; | ||
}); | ||
return ( | ||
`HTMLNode(<${ object.tagName + attrStr }>{...}</${ object.tagName }>)`);} else | ||
`HTMLNode(<${ object.tagName + attrStr }>{...}</${ object.tagName }>)`); | ||
{ | ||
return `HTMLNode(<${ object.constructor.name } />)`;}} | ||
} else { | ||
return `HTMLNode(<${ object.constructor.name } />)`; | ||
} | ||
} | ||
if (!cycleWeakMap) { | ||
cycleWeakMap = new WeakMap();} | ||
cycleWeakMap = new WeakMap(); | ||
} | ||
if (cycleWeakMap.get(object) === true) { | ||
return '<circular reference>';} | ||
return '<circular reference>'; | ||
} | ||
cycleWeakMap.set(object, true); | ||
@@ -164,10 +164,10 @@ | ||
indent + value[0] + ': ' + this.prettyPrint( | ||
value[1], | ||
indent, | ||
cycleWeakMap));} | ||
value[1], | ||
indent, | ||
cycleWeakMap)); | ||
return `Map {\n${ output.join(',') }\n}`;} | ||
} | ||
return `Map {\n${ output.join(',') }\n}`; | ||
} | ||
if (type === '[object Set]') { | ||
@@ -177,11 +177,11 @@ for (const value of object) { | ||
this.prettyPrint( | ||
value, | ||
chalk.gray('|') + ' ' + indent, | ||
cycleWeakMap));} | ||
value, | ||
chalk.gray('|') + ' ' + indent, | ||
cycleWeakMap)); | ||
} | ||
return `Set [\n${ indent }${ output.join(', ') }\n${ indent }]`; | ||
} | ||
return `Set [\n${ indent }${ output.join(', ') }\n${ indent }]`;} | ||
const orderedKeys = Object.keys(object).sort(); | ||
@@ -194,14 +194,14 @@ let value; | ||
keysOutput.push( | ||
indent + keyIndent + orderedKeys[i] + ': ' + | ||
this.prettyPrint(value, indent + keyIndent, cycleWeakMap));} | ||
indent + keyIndent + orderedKeys[i] + ': ' + | ||
this.prettyPrint(value, indent + keyIndent, cycleWeakMap)); | ||
} | ||
return '{\n' + keysOutput.join(',\n') + '\n' + indent + '}'; | ||
} else { | ||
return this._jasmine.pp(object); | ||
} | ||
}} | ||
return '{\n' + keysOutput.join(',\n') + '\n' + indent + '}';} else | ||
{ | ||
return this._jasmine.pp(object);}}} | ||
module.exports = JasmineFormatter; |
{ | ||
"name": "jest-util", | ||
"version": "14.0.0", | ||
"version": "14.2.0-alpha.ca8bfb6e", | ||
"repository": { | ||
@@ -15,3 +15,3 @@ "type": "git", | ||
"mkdirp": "^0.5.1", | ||
"jest-mock": "^14.0.0" | ||
"jest-mock": "^14.2.0-alpha.ca8bfb6e" | ||
}, | ||
@@ -21,7 +21,2 @@ "devDependencies": { | ||
}, | ||
"jest": { | ||
"rootDir": "./src", | ||
"scriptPreprocessor": "../../babel-jest", | ||
"testEnvironment": "node" | ||
}, | ||
"scripts": { | ||
@@ -28,0 +23,0 @@ "test": "../../packages/jest-cli/bin/jest.js" |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
31150
11
877
2
+ Addedjest-mock@14.2.0-alpha.ca8bfb6e(transitive)
- Removedjest-mock@14.0.0(transitive)