summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/common/internal/logging/logger.ts
blob: 6b95f48b74afe35cb845ed46f3bd0ce2ead820d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { globalTestConfig } from '../../framework/test_config.js';
import { version } from '../version.js';

import { LiveTestCaseResult } from './result.js';
import { TestCaseRecorder } from './test_case_recorder.js';

export type LogResults = Map<string, LiveTestCaseResult>;

export class Logger {
  readonly overriddenDebugMode: boolean | undefined;
  readonly results: LogResults = new Map();

  constructor({ overrideDebugMode }: { overrideDebugMode?: boolean } = {}) {
    this.overriddenDebugMode = overrideDebugMode;
  }

  record(name: string): [TestCaseRecorder, LiveTestCaseResult] {
    const result: LiveTestCaseResult = { status: 'running', timems: -1 };
    this.results.set(name, result);
    return [
      new TestCaseRecorder(result, this.overriddenDebugMode ?? globalTestConfig.enableDebugLogs),
      result,
    ];
  }

  asJSON(space?: number): string {
    return JSON.stringify({ version, results: Array.from(this.results) }, undefined, space);
  }
}