Files
SnowLuma/packages/proton/test/helpers/index.ts
T
手瓜一十雪 36c3ed031b Apply formatting and fix web request utilities
Add consistent indent rule to ESLint and normalize formatting/indentation across multiple files. Refactor RequestUtil: improve cookie extraction, redirect handling, and HttpGetJson/HttpGetText request flow; fix cookie string builder formatting. Fix uploadGroupNoticeImage promise/error handling and network request flow. Also apply minor style/refactor tweaks in bridge web APIs, onebot handlers, message-store SQL alignment, and Proton AST collector utilities to improve readability and correctness.
2026-05-20 19:16:06 +08:00

22 lines
683 B
TypeScript

import { readFileSync } from 'fs';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
const fixturesDir = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'fixtures');
/** Load a fixture file as a string. */
export function loadFixture(name: string): string {
return readFileSync(resolve(fixturesDir, name), 'utf-8');
}
/**
* Run generated code via `new Function()` and return a named global value.
* Cleans up the global after retrieval.
*/
export function execAndGet<T>(code: string, globalKey: string): T {
new Function(code)();
const val = (globalThis as any)[globalKey] as T;
delete (globalThis as any)[globalKey];
return val;
}