This commit introduces a custom error object to provide additional context for errors throwing during parsing and compiling operations, improving troubleshooting. By integrating error context handling, the error messages become more informative and user-friendly, providing sequence of trace with context to aid in troubleshooting. Changes include: - Introduce custom error object that extends errors with contextual information. This replaces previous usages of `AggregateError` which is not displayed well by browsers when logged. - Improve parsing functions to encapsulate error context with more details. - Increase unit test coverage and refactor the related code to be more testable.
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
export interface DataValidationTestScenario<T> {
|
|
readonly description: string;
|
|
readonly data: T;
|
|
readonly expectedPass: boolean;
|
|
readonly expectedMessage?: string;
|
|
}
|
|
|
|
export function generateDataValidationTestScenarios<T>(
|
|
...conditionBasedScenarios: DataValidationConditionBasedTestScenario<T>[]
|
|
): DataValidationTestScenario<T>[] {
|
|
return conditionBasedScenarios.flatMap((conditionScenario) => [
|
|
conditionScenario.expectFail.map((failDefinition): DataValidationTestScenario<T> => ({
|
|
description: `fails: "${failDefinition.description}"`,
|
|
data: failDefinition.data,
|
|
expectedPass: false,
|
|
expectedMessage: conditionScenario.assertErrorMessage,
|
|
})),
|
|
conditionScenario.expectPass.map((passDefinition): DataValidationTestScenario<T> => ({
|
|
description: `passes: "${passDefinition.description}"`,
|
|
data: passDefinition.data,
|
|
expectedPass: true,
|
|
expectedMessage: conditionScenario.assertErrorMessage,
|
|
})),
|
|
].flat());
|
|
}
|
|
|
|
interface DataValidationConditionBasedTestScenario<T> {
|
|
readonly assertErrorMessage?: string;
|
|
readonly expectPass: readonly DataValidationScenarioDefinition<T>[];
|
|
readonly expectFail: readonly DataValidationScenarioDefinition<T>[];
|
|
}
|
|
|
|
interface DataValidationScenarioDefinition<T> {
|
|
readonly description: string;
|
|
readonly data: T;
|
|
}
|