jest-util
Advanced tools
Comparing version 28.0.0-alpha.4 to 28.0.0-alpha.5
@@ -14,29 +14,22 @@ 'use strict'; | ||
*/ | ||
/* eslint-disable local/ban-types-eventually */ | ||
// See: https://github.com/facebook/jest/pull/5154 | ||
function convertDescriptorToString(descriptor) { | ||
if ( | ||
typeof descriptor === 'string' || | ||
typeof descriptor === 'number' || | ||
descriptor === undefined | ||
) { | ||
return descriptor; | ||
} | ||
switch (typeof descriptor) { | ||
case 'function': | ||
if (descriptor.name) { | ||
return descriptor.name; | ||
} | ||
if (typeof descriptor !== 'function') { | ||
throw new Error('describe expects a class, function, number, or string.'); | ||
break; | ||
case 'number': | ||
case 'undefined': | ||
return `${descriptor}`; | ||
case 'string': | ||
return descriptor; | ||
} | ||
if (descriptor.name !== undefined) { | ||
return descriptor.name; | ||
} // Fallback for old browsers, pardon Flow | ||
const stringified = descriptor.toString(); | ||
const typeDescriptorMatch = stringified.match(/class|function/); | ||
const indexOfNameSpace = // @ts-expect-error: typeDescriptorMatch exists | ||
typeDescriptorMatch.index + typeDescriptorMatch[0].length; | ||
const indexOfNameAfterSpace = stringified.search(/\(|\{/); | ||
const name = stringified.substring(indexOfNameSpace, indexOfNameAfterSpace); | ||
return name.trim(); | ||
throw new Error( | ||
`Invalid first argument, ${descriptor}. It must be a named class, named function, number, or string.` | ||
); | ||
} |
@@ -7,22 +7,120 @@ /** | ||
*/ | ||
import * as preRunMessage from './preRunMessage'; | ||
import * as specialChars from './specialChars'; | ||
export { default as clearLine } from './clearLine'; | ||
export { default as createDirectory } from './createDirectory'; | ||
export { default as ErrorWithStack } from './ErrorWithStack'; | ||
export { default as installCommonGlobals } from './installCommonGlobals'; | ||
export { default as interopRequireDefault } from './interopRequireDefault'; | ||
export { default as isInteractive } from './isInteractive'; | ||
export { default as isPromise } from './isPromise'; | ||
export { default as setGlobal } from './setGlobal'; | ||
export { default as deepCyclicCopy } from './deepCyclicCopy'; | ||
export { default as convertDescriptorToString } from './convertDescriptorToString'; | ||
export { specialChars }; | ||
export { default as replacePathSepForGlob } from './replacePathSepForGlob'; | ||
export { default as testPathPatternToRegExp } from './testPathPatternToRegExp'; | ||
export { default as globsToMatcher } from './globsToMatcher'; | ||
export { preRunMessage }; | ||
export { default as pluralize } from './pluralize'; | ||
export { default as formatTime } from './formatTime'; | ||
export { default as tryRealpath } from './tryRealpath'; | ||
export { default as requireOrImportModule } from './requireOrImportModule'; | ||
/// <reference types="node" /> | ||
import type {Config} from '@jest/types'; | ||
import type {Global} from '@jest/types'; | ||
declare const ARROW = ' \u203A '; | ||
declare const CLEAR: string; | ||
export declare function clearLine(stream: NodeJS.WriteStream): void; | ||
export declare function convertDescriptorToString( | ||
descriptor: Global.BlockNameLike | undefined, | ||
): string; | ||
export declare function createDirectory(path: string): void; | ||
export declare function deepCyclicCopy<T>( | ||
value: T, | ||
options?: DeepCyclicCopyOptions, | ||
cycles?: WeakMap<any, any>, | ||
): T; | ||
declare type DeepCyclicCopyOptions = { | ||
blacklist?: Set<string>; | ||
keepPrototype?: boolean; | ||
}; | ||
export declare class ErrorWithStack extends Error { | ||
constructor( | ||
message: string | undefined, | ||
callsite: (...args: Array<any>) => unknown, | ||
stackLimit?: number, | ||
); | ||
} | ||
export declare function formatTime( | ||
time: number, | ||
prefixPower?: number, | ||
padLeftLength?: number, | ||
): string; | ||
/** | ||
* Converts a list of globs into a function that matches a path against the | ||
* globs. | ||
* | ||
* Every time picomatch is called, it will parse the glob strings and turn | ||
* them into regexp instances. Instead of calling picomatch repeatedly with | ||
* the same globs, we can use this function which will build the picomatch | ||
* matchers ahead of time and then have an optimized path for determining | ||
* whether an individual path matches. | ||
* | ||
* This function is intended to match the behavior of `micromatch()`. | ||
* | ||
* @example | ||
* const isMatch = globsToMatcher(['*.js', '!*.test.js']); | ||
* isMatch('pizza.js'); // true | ||
* isMatch('pizza.test.js'); // false | ||
*/ | ||
export declare function globsToMatcher(globs: Array<string>): Matcher; | ||
declare const ICONS: { | ||
failed: string; | ||
pending: string; | ||
success: string; | ||
todo: string; | ||
}; | ||
export declare function installCommonGlobals( | ||
globalObject: typeof globalThis, | ||
globals: Config.ConfigGlobals, | ||
): typeof globalThis & Config.ConfigGlobals; | ||
export declare function interopRequireDefault(obj: any): any; | ||
export declare const isInteractive: boolean; | ||
export declare const isPromise: ( | ||
candidate: unknown, | ||
) => candidate is Promise<unknown>; | ||
declare type Matcher = (str: string) => boolean; | ||
export declare function pluralize(word: string, count: number): string; | ||
declare namespace preRunMessage { | ||
export {print_2 as print, remove}; | ||
} | ||
export {preRunMessage}; | ||
declare const print_2: (stream: NodeJS.WriteStream) => void; | ||
declare const remove: (stream: NodeJS.WriteStream) => void; | ||
export declare function replacePathSepForGlob(path: string): string; | ||
export declare function requireOrImportModule<T>( | ||
filePath: string, | ||
applyInteropRequireDefault?: boolean, | ||
): Promise<T>; | ||
export declare function setGlobal( | ||
globalToMutate: typeof globalThis | Global.Global, | ||
key: string, | ||
value: unknown, | ||
): void; | ||
declare namespace specialChars { | ||
export {ARROW, ICONS, CLEAR}; | ||
} | ||
export {specialChars}; | ||
export declare function testPathPatternToRegExp( | ||
testPathPattern: Config.GlobalConfig['testPathPattern'], | ||
): RegExp; | ||
export declare function tryRealpath(path: string): string; | ||
export {}; |
{ | ||
"name": "jest-util", | ||
"version": "28.0.0-alpha.4", | ||
"version": "28.0.0-alpha.5", | ||
"repository": { | ||
@@ -20,3 +20,3 @@ "type": "git", | ||
"dependencies": { | ||
"@jest/types": "^28.0.0-alpha.4", | ||
"@jest/types": "^28.0.0-alpha.5", | ||
"@types/node": "*", | ||
@@ -39,3 +39,3 @@ "chalk": "^4.0.0", | ||
}, | ||
"gitHead": "c13dab19491ba6b57c2d703e7d7c4b20189e1e17" | ||
"gitHead": "46fb19b2628bd87676c10730ba19592c30b05478" | ||
} |
35898
1101
24
Updated@jest/types@^28.0.0-alpha.5