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.
25 lines
681 B
TypeScript
25 lines
681 B
TypeScript
import type { Constructible } from '@/TypeHelpers';
|
|
|
|
interface TransientFactoryTestData<T> {
|
|
readonly getter: () => T;
|
|
readonly expectedType?: Constructible<T>;
|
|
}
|
|
|
|
export function itIsTransientFactory<T>(test: TransientFactoryTestData<T>): void {
|
|
if (test.expectedType !== undefined) {
|
|
it('gets the expected type', () => {
|
|
// act
|
|
const instance = test.getter();
|
|
// assert
|
|
expect(instance).to.be.instanceOf(test.expectedType);
|
|
});
|
|
}
|
|
it('multiple calls get different instances', () => {
|
|
// act
|
|
const instance1 = test.getter();
|
|
const instance2 = test.getter();
|
|
// assert
|
|
expect(instance1).to.not.equal(instance2);
|
|
});
|
|
}
|