Collection of utility functions for Jest testing framework
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Core file system operations designed for Jest's testing needs, providing safe directory creation and path resolution that handle edge cases common in test environments.
Creates directories recursively, safely ignoring errors if the directory already exists.
/**
* Creates a directory recursively, ignoring EEXIST errors
* @param path - Directory path to create
* @throws Error if directory creation fails for reasons other than already existing
*/
function createDirectory(path: string): void;Usage Examples:
import { createDirectory } from "jest-util";
// Create test directories safely
createDirectory("/tmp/jest-tests/snapshots");
createDirectory("./test-output/coverage");
// Safe to call multiple times - won't throw if directory exists
createDirectory("/tmp/jest-tests"); // First call creates it
createDirectory("/tmp/jest-tests"); // Second call is safe, no errorError Handling:
EEXIST errors (directory already exists)Safely resolves the real path of a file or directory, falling back to the original path if resolution fails.
/**
* Safely resolves real path, falling back to original on error
* @param path - Path to resolve
* @returns Real path if successful, or original path if resolution fails
*/
function tryRealpath(path: string): string;Usage Examples:
import { tryRealpath } from "jest-util";
// Resolve symlinks safely
const configPath = tryRealpath("./jest.config.js");
const packagePath = tryRealpath("./node_modules/some-package");
// Handles missing files gracefully
const missingFile = tryRealpath("./non-existent.js");
// Returns "./non-existent.js" instead of throwing
// Resolves symlinks when they exist
const symlinkPath = "/usr/bin/node"; // might be a symlink
const realPath = tryRealpath(symlinkPath); // resolves to actual binary pathError Handling:
ENOENT errors (file not found)EISDIR errors (is a directory when file expected)