@@ -37,16 +37,16 @@ let activeCleanups = 0;
37
37
/**
38
38
* Logs the cleanup of a resource.
39
39
* @param resource - The resource that is being cleaned up.
40
- * @param fn - The cleanup function .
40
+ * @param promise - The cleanup promise to await. .
41
41
*/
42
- async function logCleanup ( resource : string , fn : ( ) => Promise < void > ) {
42
+ async function logCleanup ( resource : string , promise : Promise < unknown > ) {
43
43
const start = new Date ( ) ;
44
44
const order = cleanupOrder ++ ;
45
45
const activeAtStart = ++ activeCleanups ;
46
46
47
47
let error : unknown = null ;
48
48
try {
49
- await fn ( ) ;
49
+ await promise ;
50
50
} catch ( err ) {
51
51
error = err instanceof Error ? err . message : String ( err ) ;
52
52
}
@@ -58,11 +58,11 @@ async function logCleanup(resource: string, fn: () => Promise<void>) {
58
58
console . log (
59
59
JSON . stringify ( {
60
60
order,
61
+ resource,
62
+ durationMs : end . getTime ( ) - start . getTime ( ) ,
61
63
start : start . toISOString ( ) ,
62
64
end : end . toISOString ( ) ,
63
65
parallel,
64
- resource,
65
- durationMs : end . getTime ( ) - start . getTime ( ) ,
66
66
error,
67
67
activeAtStart,
68
68
activeAtEnd,
@@ -76,9 +76,7 @@ const network = async ({}, use: Use<StartedNetwork>) => {
76
76
await use ( network ) ;
77
77
} finally {
78
78
// Make sure to stop the network after use
79
- await logCleanup ( "network" , async ( ) => {
80
- await network . stop ( ) ;
81
- } ) ;
79
+ await logCleanup ( "network" , network . stop ( ) ) ;
82
80
}
83
81
} ;
84
82
@@ -92,9 +90,7 @@ const postgresContainer = async (
92
90
} finally {
93
91
// WARNING: Testcontainers by default will not wait until the container has stopped. It will simply issue the stop command and return immediately.
94
92
// If you need to wait for the container to be stopped, you can provide a timeout. The unit of timeout option here is second
95
- await logCleanup ( "postgresContainer" , async ( ) => {
96
- await container . stop ( { timeout : 30 } ) ;
97
- } ) ;
93
+ await logCleanup ( "postgresContainer" , container . stop ( { timeout : 30 } ) ) ;
98
94
}
99
95
} ;
100
96
@@ -116,9 +112,7 @@ const prisma = async (
116
112
try {
117
113
await use ( prisma ) ;
118
114
} finally {
119
- await logCleanup ( "prisma" , async ( ) => {
120
- await prisma . $disconnect ( ) ;
121
- } ) ;
115
+ await logCleanup ( "prisma" , prisma . $disconnect ( ) ) ;
122
116
}
123
117
} ;
124
118
@@ -137,9 +131,7 @@ const redisContainer = async (
137
131
} finally {
138
132
// WARNING: Testcontainers by default will not wait until the container has stopped. It will simply issue the stop command and return immediately.
139
133
// If you need to wait for the container to be stopped, you can provide a timeout. The unit of timeout option here is second
140
- await logCleanup ( "redisContainer" , async ( ) => {
141
- await container . stop ( { timeout : 30 } ) ;
142
- } ) ;
134
+ await logCleanup ( "redisContainer" , container . stop ( { timeout : 30 } ) ) ;
143
135
}
144
136
} ;
145
137
@@ -191,9 +183,7 @@ const electricOrigin = async (
191
183
} finally {
192
184
// WARNING: Testcontainers by default will not wait until the container has stopped. It will simply issue the stop command and return immediately.
193
185
// If you need to wait for the container to be stopped, you can provide a timeout. The unit of timeout option here is second
194
- await logCleanup ( "electricContainer" , async ( ) => {
195
- await container . stop ( { timeout : 30 } ) ;
196
- } ) ;
186
+ await logCleanup ( "electricContainer" , container . stop ( { timeout : 30 } ) ) ;
197
187
}
198
188
} ;
199
189
0 commit comments