fix(tapbundle_serverside): add TapNodeTools cleanup hooks to stop SmartNetwork processes after tests

This commit is contained in:
2026-03-27 18:23:42 +00:00
parent 7490da22c0
commit 2946169360
10 changed files with 151 additions and 152 deletions

View File

@@ -117,7 +117,8 @@ export class Tap<T> {
private settingsManager = new SettingsManager();
private _skipCount = 0;
private _filterTags: string[] = [];
private _cleanupFunctions: Array<() => Promise<void> | void> = [];
constructor() {
// Get filter tags from environment
if (typeof process !== 'undefined' && process.env && process.env.TSTEST_FILTER_TAGS) {
@@ -125,6 +126,14 @@ export class Tap<T> {
}
}
/**
* Register a cleanup function to be called when tap.start() finishes.
* Use this to tear down resources that would otherwise keep the event loop alive.
*/
public registerCleanup(fn: () => Promise<void> | void) {
this._cleanupFunctions.push(fn);
}
// Fluent test builder
public tags(...tags: string[]) {
const builder = new TestBuilder<T>(this);
@@ -610,6 +619,15 @@ export class Tap<T> {
}
}
// Run registered cleanup functions (e.g. tapNodeTools stopping SmartNetwork Rust bridge)
for (const cleanupFn of this._cleanupFunctions) {
try {
await cleanupFn();
} catch (e) {
// Don't let cleanup errors break the test run
}
}
if (optionsArg && optionsArg.throwOnError && failReasons.length > 0) {
if (!smartenvInstance.isBrowser && typeof process !== 'undefined') process.exit(1);
}