OptionalcircularDefines a custom message to display when a circular reference is detected in a value.
The default is a function that returns the string "[
OptionaldefDefiines the default assertion failure message to display if no message is provided.
OptionaldefDefines the default fatal message to display if no message is provided.
OptionalformatOptions for configuring value formatting.
These options allow you to customize how values are formatted in assertion error messages. Custom formatters can be added via the format manager (see IConfigApi.formatMgr). Custom formatters are checked in order: current context formatters first, then parent context formatters, and finally default formatters. This allows you to provide specialized formatting for certain value types that takes precedence over inherited and default formatting.
Additionally, you can control post-processing of the formatted output using IFormatterOptions.finalize and IFormatterOptions.finalizeFn to escape ANSI codes, wrap output, or apply other transformations.
import { assertConfig, eFormatResult } from '@nevware21/tripwire';
import { escapeAnsi, gray, replaceAnsi } from '@nevware21/chromacon';
// Example 1: Custom formatters with default ANSI escaping
assertConfig.format = {
finalize: true // Enable default escapeAnsi
};
assertConfig.formatMgr.addFormatter({
name: "stringFormatter",
value: (ctx, value) => {
if (typeof value === 'string') {
return { res: FormatResult.Ok, val: `'${value}'` };
}
return { res: FormatResult.Skip };
}
});
// Example 2: Custom formatters with custom finalization
assertConfig.format = {
finalize: true,
finalizeFn: (value) => replaceAnsi(value, (match) => gray(escapeAnsi(match)))
};
assertConfig.formatMgr.addFormatter({
name: "arrayFormatter",
value: (ctx, value) => {
if (Array.isArray(value)) {
return { res: FormatResult.Ok, val: `[${value.length} items]` };
}
return { res: FormatResult.Skip };
}
});
OptionalfullIdentifies if the current context is in full-stack mode, which will include the full stack trace in the error message if an assertion fails.
OptionalisIdentifies if the current context is verbose mode, which will include additional information in the execution context and any resulting assertion failures.
OptionalmaxMaximum number of recently visited items to check for circular references during deep comparisons. Limiting this prevents O(n²) performance degradation in deeply nested structures.
OptionalmaxMaximum depth for deep equality comparisons before throwing a fatal error. This prevents stack overflow with extremely deep object structures.
OptionalretriesDefault retry count for failed tests when no per-suite or per-test override is defined.
OptionalshowIndicates whether to show the difference between expected and actual values in the error message.
OptionalslowDefault threshold in milliseconds for considering a test execution as slow.
OptionaltimeoutDefault timeout in milliseconds for test cases and hooks that do not have a specific timeout defined.
Provides the options for the current context