@ethaks/fvtt-quench
Version:
Types for a Foundry VTT module enabling tests using Mocha and Chai
104 lines (103 loc) • 3.23 kB
TypeScript
import type { Quench, QuenchReports, QuenchRunBatchOptions } from "./quench";
declare global {
namespace Hooks {
interface StaticCallbacks {
/**
* A hook event that fires when a batch run is completed and Quench's reports are ready.
*
* @group Reports
* @remarks This is called by {@link Hooks.callAll}
* @param reports - An object containing reports generated by the batch run
*/
quenchReports: (reports: QuenchReports) => void;
}
}
}
declare const CACHE_PROPERTIES: readonly ["tests", "pending", "failures", "passes"];
type CacheProperty = (typeof CACHE_PROPERTIES)[number];
/**
* Given a mocha Runner, reports test results to the singleton instance of {@link QuenchResults} and in the console if enabled
*
* @internal
*/
export declare class QuenchReporter extends Mocha.reporters.Base {
/**
* A cache object containing test data used to generate a JSON report
*
* @internal
*/
protected cache: Record<CacheProperty, Mocha.Test[]>;
/**
* @param runner - The runner this reporter should work with
* @param options - Additional options for this reporter
*/
constructor(runner: Mocha.Runner, options: Mocha.MochaOptions);
/**
* Uploads a JSON report to a file on Foundry's server
*
* @param json - The JSON report in already stringified form
* @param options - Options affecting e.g. the filename
* @private
* @internal
*/
private static uploadJsonReport;
/**
* Cleans a test object for JSON serialization by copying primitive values
*
* @param test - The test object to clean
* @private
* @internal
*/
private static clean;
/**
* Removes cyclic references from an error object
*
* @param obj - The error object to clean
* @private
* @internal
*/
private static cleanCycles;
/**
* Creates an object from an {@link Error} by only copying its own properties
*
* @param error - An error object to be cleaned
* @private
* @internal
*/
private static errorJSON;
/**
* Determines whether the setting to show detailed log results is enabled
*/
private static _shouldLogTestDetails;
}
/**
* Data belonging to a {@link Mocha.Test}, cleaned to be JSON-serializable
*/
export interface QuenchCleanedTestData {
title: string;
fullTitle: string;
file: string | undefined;
duration: number | undefined;
currentRetry: number;
speed: Mocha.Test["speed"];
err: unknown;
}
/**
* Data collected from a {@link Mocha.Runner} during a test run, made available after the run is complete
* as {@link Quench.reports | Quench.reports.json}.
*
* @see {@link Quench.reports | Quench.reports.json}
* @see {@link hookEvents!quenchReports}
*/
export interface QuenchJsonReport {
stats: Mocha.Stats;
tests: QuenchCleanedTestData[];
pending: QuenchCleanedTestData[];
failures: QuenchCleanedTestData[];
passes: QuenchCleanedTestData[];
}
export interface QuenchReporterOptions {
quench: Quench;
json?: QuenchRunBatchOptions["json"];
}
export {};