fix(tapbundle): Fix TypeScript IDE warning about tapTools parameter possibly being undefined

This commit is contained in:
Juergen Kunz
2025-07-24 22:24:52 +00:00
parent e4fc6623ea
commit 008844a9e2
3 changed files with 14 additions and 5 deletions

View File

@@ -1,5 +1,12 @@
# Changelog
## 2025-07-24 - 2.3.2 - fix(tapbundle)
Fix TypeScript IDE warning about tapTools parameter possibly being undefined
- Changed ITestFunction from interface with optional parameter to union type
- Updated test runner to handle both function signatures (with and without tapTools)
- Resolves IDE warnings while maintaining backward compatibility
## 2025-05-26 - 2.3.1 - fix(tapParser/logger)
Fix test duration reporting and summary formatting in TAP parser and logger

View File

@@ -1,6 +1,6 @@
{
"name": "@git.zone/tstest",
"version": "2.3.1",
"version": "2.3.2",
"private": false,
"description": "a test utility to run tests that match test/**/*.ts",
"exports": {

View File

@@ -11,9 +11,9 @@ import { HrtMeasurement } from '@push.rocks/smarttime';
// interfaces
export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout' | 'skipped';
export interface ITestFunction<T> {
(tapTools?: TapTools): Promise<T>;
}
export type ITestFunction<T> =
| ((tapTools: TapTools) => Promise<T>)
| (() => Promise<T>);
export class TapTest<T = unknown> {
public description: string;
@@ -173,7 +173,9 @@ export class TapTest<T = unknown> {
}
// Run the test function with potential timeout
const testPromise = this.testFunction(this.tapTools);
const testPromise = this.testFunction.length === 0
? (this.testFunction as () => Promise<T>)()
: (this.testFunction as (tapTools: TapTools) => Promise<T>)(this.tapTools);
const testReturnValue = timeoutPromise
? await Promise.race([testPromise, timeoutPromise])
: await testPromise;