@apexcli/core
v0.4.0
Published
Core types and utilities for APEX
Readme
APEX Core Test Utilities
Cross-platform test utilities for handling platform-specific testing scenarios in the APEX ecosystem.
Quick Start
import {
isWindows,
skipOnWindows,
describeWindows,
runOnWindows,
mockPlatform,
testOnAllPlatforms
} from '@apex/core';
// Skip tests on specific platforms
it('Unix-only test', () => {
skipOnWindows();
// Test Unix-specific functionality
});
// Platform-specific test suites
describeWindows('Windows tests', () => {
it('should handle Windows paths', () => {
expect('C:\\Program Files').toMatch(/^[A-Z]:\\/);
});
});
// Conditional execution
it('should handle platform differences', () => {
const result = runOnWindows(() => 'windows-value') || 'default-value';
expect(result).toBeDefined();
});
// Test on all platforms
testOnAllPlatforms('cross-platform function', (platform) => {
const result = myFunction();
expect(result).toBeDefined();
});Available Utilities
Platform Detection
isWindows()- Check if running on WindowsisUnix()- Check if running on Unix-like systemsisMacOS()- Check if running on macOSisLinux()- Check if running on LinuxgetPlatform()- Get current platform name
Test Skipping
skipOnWindows()- Skip test on WindowsskipOnUnix()- Skip test on Unix-like systemsskipOnMacOS()- Skip test on macOSskipOnLinux()- Skip test on LinuxskipUnlessWindows()- Only run on WindowsskipUnlessUnix()- Only run on Unix-like systems
Platform-Specific Test Suites
describeWindows(name, fn)- Windows-only test suitedescribeUnix(name, fn)- Unix-only test suitedescribeMacOS(name, fn)- macOS-only test suitedescribeLinux(name, fn)- Linux-only test suite
Conditional Execution
runOnWindows(fn)- Execute function only on WindowsrunOnUnix(fn)- Execute function only on UnixrunOnMacOS(fn)- Execute function only on macOSrunOnLinux(fn)- Execute function only on Linux
Platform Mocking
mockPlatform(platform)- Mock platform for testingtestOnAllPlatforms(name, testFn)- Test on all platforms
Constants and Types
PLATFORMS- Platform name constantsisValidPlatform(platform)- Type guard for platformsPlatform- TypeScript type for valid platforms
Examples
See the full documentation for comprehensive examples and usage patterns.
Integration
These utilities integrate with:
- Vitest test framework
- Existing APEX shell utilities
- Cross-platform path utilities
- Container and runtime detection
