Skip to content

Commit 947a68c

Browse files
committed
refactor: implement reset method in CliPlatformTest to clear static collections and prevent memory leaks
1 parent 8b1b85e commit 947a68c

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

packages/cli-testing/src/CliPlatformTest.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ import {FakeCliFs} from "./FakeCliFs.js";
2828
import {FakeCliHttpClient} from "./FakeCliHttpClient.js";
2929

3030
export class CliPlatformTest extends DITest {
31+
static async reset() {
32+
// Explicitly clear FakeCliFs static collections to prevent memory leaks
33+
FakeCliFs.files.clear();
34+
FakeCliFs.directories.clear();
35+
FakeCliExeca.entries.clear();
36+
FakeCliHttpClient.entries.clear();
37+
// Call parent reset method
38+
return super.reset();
39+
}
40+
3141
static async bootstrap(options: Partial<TsED.Configuration> = {}) {
3242
options = resolveConfiguration({
3343
name: "tsed",

packages/cli-testing/src/FakeCliFs.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,6 @@ export class FakeCliFs implements FileSystemHost {
297297
return matchGlobs(allFilePaths, patterns, this.getCurrentDirectory());
298298
}
299299

300-
$onDestroy() {
301-
FakeCliFs.files.clear();
302-
FakeCliFs.directories.clear();
303-
}
304-
305300
private normalizePath(path: any): string {
306301
return (normalizePath(path) as string).replace(/^\//, "") as string;
307302
}

packages/cli-testing/src/FakeCliHttpClient.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {CliHttpClient, type CliHttpClientOptions} from "@tsed/cli-core";
2-
import type {OnDestroy} from "@tsed/di";
32

4-
export class FakeCliHttpClient extends CliHttpClient implements OnDestroy {
3+
export class FakeCliHttpClient extends CliHttpClient {
54
static entries = new Map<string, (endpoint: string, options: CliHttpClientOptions) => any>();
65

76
get(endpoint: string, options: CliHttpClientOptions = {}): Promise<any> {
@@ -21,8 +20,4 @@ export class FakeCliHttpClient extends CliHttpClient implements OnDestroy {
2120

2221
return FakeCliHttpClient.entries.get(key)?.(endpoint, options);
2322
}
24-
25-
$onDestroy() {
26-
FakeCliHttpClient.entries.clear();
27-
}
2823
}

0 commit comments

Comments
 (0)