jest-util
Advanced tools
Comparing version 0.0.3 to 1.0.0
58
index.js
@@ -11,20 +11,5 @@ /** | ||
const fs = require('graceful-fs'); | ||
const formatMessages = require('./lib/formatMessages'); | ||
const path = require('path'); | ||
// general functions | ||
function readFile(filePath) { | ||
return new Promise(function(resolve, reject) { | ||
fs.readFile(filePath, 'utf8', function(err, data) { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(data); | ||
}); | ||
}); | ||
} | ||
function escapeStrForRegex(str) { | ||
@@ -41,38 +26,2 @@ return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); | ||
exports.readFile = readFile; | ||
exports.escapeStrForRegex = escapeStrForRegex; | ||
exports.replacePathSepForRegex = replacePathSepForRegex; | ||
exports.cleanStackTrace = formatMessages.cleanStackTrace; | ||
exports.formatFailureMessage = formatMessages.formatFailureMessage; | ||
/** | ||
* Formats milliseconds into a greater | ||
* time signature. | ||
* | ||
* @param {number} time - the time in ms | ||
* @returns {string} | ||
*/ | ||
function formatTime(time) { | ||
if (time < 1000) { | ||
return round(time, 2) + 'ms'; | ||
} | ||
time /= 1000; | ||
if (time < 60) { | ||
return round(time, 2) + 's'; | ||
} | ||
time /= 60; | ||
if (time < 60) { | ||
return round(time, 2) + 'm'; | ||
} | ||
time /= 60; | ||
return round(time, 2) + 'hrs'; | ||
} | ||
function round(num, places) { | ||
return +(Math.round(num + 'e+' + places) + 'e-' + places); | ||
} | ||
exports.formatTime = formatTime; | ||
function deepCopy(obj) { | ||
@@ -90,4 +39,7 @@ const newObj = {}; | ||
} | ||
// lodash exports | ||
exports.deepCopy = deepCopy; | ||
exports.cleanStackTrace = formatMessages.cleanStackTrace; | ||
exports.deepCopy = deepCopy; | ||
exports.escapeStrForRegex = escapeStrForRegex; | ||
exports.formatFailureMessage = formatMessages.formatFailureMessage; | ||
exports.replacePathSepForRegex = replacePathSepForRegex; |
@@ -14,50 +14,11 @@ /** | ||
function isExternalStackEntry(entry) { | ||
return (entry ? true : false); | ||
} | ||
const KEEP_TRACE_LINES = 2; | ||
// filter for noisy stack trace lines | ||
const STACK_TRACE_LINE_IGNORE_RE = new RegExp([ | ||
'^timers.js$', | ||
'^' + path.resolve(__dirname, '..', 'lib', 'moduleMocker.js'), | ||
'^' + path.resolve(__dirname, '..', '..', 'vendor', 'jasmine'), | ||
].join('|')); | ||
function getRelevantStackFrom(stack) { | ||
stack = stack.split('\n'); | ||
let filteredStack = stack.filter((entry) => { | ||
return isExternalStackEntry(entry); | ||
}); | ||
if (filteredStack.length === 0) { | ||
filteredStack = stack; | ||
} | ||
return filteredStack; | ||
} | ||
function formatFailedStep(step) { | ||
let relevantMessage = []; | ||
let relevantStack = []; | ||
let stack = step.stack.replace('Error: ' + step.message, ''); | ||
let dirtyRelevantStack = getRelevantStackFrom(stack); | ||
dirtyRelevantStack.forEach((message) => { | ||
if (step.message && step.message.indexOf(message) === -1) { | ||
relevantStack.push(message); | ||
} else { | ||
relevantMessage.push(message); | ||
} | ||
}); | ||
if (relevantMessage.length === 0) { | ||
relevantMessage.push(step.message); | ||
if (relevantStack.length && relevantStack[0].indexOf(step.message) !== -1) { | ||
relevantStack.shift(); | ||
} | ||
} | ||
return relevantMessage.concat(relevantStack).join('\n'); | ||
} | ||
const KEEP_TRACE_LINES = 2; | ||
function cleanStackTrace(stackTrace) { | ||
// Remove jasmine jonx from the stack trace | ||
let lines = 0; | ||
@@ -71,20 +32,2 @@ const keepFirstLines = () => (lines++ < KEEP_TRACE_LINES); | ||
// A RegExp that matches paths that should not be included in error stack traces | ||
// (mostly because these paths represent noisy/unhelpful libs) | ||
const STACK_TRACE_LINE_IGNORE_RE = new RegExp([ | ||
'^timers.js$', | ||
'^' + path.resolve(__dirname, '..', 'lib', 'moduleMocker.js'), | ||
'^' + path.resolve(__dirname, '..', '..', 'vendor', 'jasmine'), | ||
].join('|')); | ||
/** | ||
* Given a test result, return a human readable string representing the | ||
* failures. | ||
* | ||
* @param {Object} testResult | ||
* @param {Object} config Containing the following keys: | ||
* `rootPath` - Root directory (for making stack trace paths relative). | ||
* `useColor` - True if message should include color flags. | ||
* @return {String} | ||
*/ | ||
function formatFailureMessage(testResult, config) { | ||
@@ -103,3 +46,3 @@ const rootDir = config.rootDir; | ||
(config.verbose ? 'Runtime Error' : chalk.bold('Runtime Error')) + '\n' + | ||
chalk.red(formatFailedStep(error)) | ||
(error.stack ? cleanStackTrace(error.stack) : error.message) | ||
); | ||
@@ -141,4 +84,4 @@ } | ||
const testTitleAncestry = result.ancestorTitles.map( | ||
title => chalk.bold(title) | ||
).join(ancestrySeparator) + ancestrySeparator; | ||
title => chalk.bold(title) | ||
).join(ancestrySeparator) + ancestrySeparator; | ||
@@ -145,0 +88,0 @@ return descBullet + testTitleAncestry + result.title + '\n' + |
{ | ||
"name": "jest-util", | ||
"version": "0.0.3", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
@@ -9,2 +9,2 @@ "dependencies": { | ||
} | ||
} | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
1
4246
115
1