CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jest-util

Collection of utility functions for Jest testing framework

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

file-system.mddocs/

File System Utilities

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.

Capabilities

Create Directory

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 error

Error Handling:

  • Ignores EEXIST errors (directory already exists)
  • Re-throws all other errors (permission denied, invalid path, etc.)

Try Real Path

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 path

Error Handling:

  • Safely handles ENOENT errors (file not found)
  • Safely handles EISDIR errors (is a directory when file expected)
  • Returns original path unchanged if resolution fails
  • Does not throw exceptions for common file system edge cases

docs

data-manipulation.md

error-handling.md

file-system.md

garbage-collection.md

global-environment.md

index.md

module-loading.md

string-path.md

terminal.md

type-checking.md

tile.json