Files
xget/test/setup.js
T
xixu-me 1979557fa9 Improve parsing, regex, and test consistency
Refines regex patterns for URL rewriting and authentication parsing, ensures parseInt uses radix 10 throughout, and updates test mocks and helpers for consistency. Also adds more global variables to ESLint config, improves error handling, and removes unused code in tests.
2025-12-08 19:19:10 +08:00

43 lines
1.1 KiB
JavaScript

/**
* Test setup and global configuration
* Simplified version - only essential setup
*/
import { beforeAll } from 'vitest';
/**
* Global setup - runs once before all tests
*/
beforeAll(async () => {
// Verify Cloudflare Workers environment
if (typeof globalThis.fetch === 'undefined') {
throw new Error('fetch is not available in test environment');
}
// Verify required Web APIs
const requiredGlobals = ['Request', 'Response', 'Headers', 'URL', 'URLSearchParams'];
for (const global of requiredGlobals) {
if (typeof globalThis[global] === 'undefined') {
throw new Error(`Required global ${global} is not available`);
}
}
// Verify SELF is available for Cloudflare Workers testing
try {
const { SELF } = await import('cloudflare:test');
if (!SELF) {
throw new Error('SELF is not available');
}
} catch {
console.warn('Warning: Cloudflare Workers test environment not available');
}
// Setup performance API if not available
if (typeof performance === 'undefined') {
globalThis.performance = {
now: () => Date.now()
};
}
});