tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

logger.ts (1315B)


      1 import { globalTestConfig } from '../../framework/test_config.js';
      2 import { version } from '../version.js';
      3 
      4 import { LiveTestCaseResult } from './result.js';
      5 import { TestCaseRecorder } from './test_case_recorder.js';
      6 
      7 export type LogResults = Map<string, LiveTestCaseResult>;
      8 
      9 export class Logger {
     10  readonly overriddenDebugMode: boolean | undefined;
     11  readonly results: LogResults = new Map();
     12  defaultDeviceDescription: string | undefined;
     13 
     14  constructor({ overrideDebugMode }: { overrideDebugMode?: boolean } = {}) {
     15    this.overriddenDebugMode = overrideDebugMode;
     16  }
     17 
     18  record(name: string): [TestCaseRecorder, LiveTestCaseResult] {
     19    const result: LiveTestCaseResult = { status: 'running', timems: -1 };
     20    this.results.set(name, result);
     21    return [
     22      new TestCaseRecorder(result, this.overriddenDebugMode ?? globalTestConfig.enableDebugLogs),
     23      result,
     24    ];
     25  }
     26 
     27  asJSON(space?: number, predFunc?: (key: string, value: LiveTestCaseResult) => boolean): string {
     28    return JSON.stringify(
     29      {
     30        version,
     31        defaultDevice: this.defaultDeviceDescription,
     32        results: Array.from(
     33          new Map(
     34            [...this.results].filter(([key, value]) => (predFunc ? predFunc(key, value) : true))
     35          )
     36        ),
     37      },
     38      undefined,
     39      space
     40    );
     41  }
     42 }