@@ -10,72 +10,89 @@ it.skipIf(
10
10
// no need to test in bun (also, bun does not support increasing timeouts per test)
11
11
globalThis . Bun ,
12
12
) (
13
- 'should correctly calculate the leaking objects' ,
13
+ 'should correctly calculate no leaking objects' ,
14
14
{
15
15
// parsing snapshots can take a while, so we increase the timeout
16
16
timeout : 30_000 ,
17
17
} ,
18
18
async ( ) => {
19
- await using snap1 = await archivedFixtureFile (
19
+ await using snaps = await archivedFixtureFiles ( [
20
20
'http-server-under-load/1.heapsnapshot' ,
21
- ) ;
22
- await using snap2 = await archivedFixtureFile (
23
21
'http-server-under-load/2.heapsnapshot' ,
24
- ) ;
25
- await using snap3 = await archivedFixtureFile (
26
22
'http-server-under-load/3.heapsnapshot' ,
27
- ) ;
28
- await using snap4 = await archivedFixtureFile (
29
23
'http-server-under-load/4.heapsnapshot' ,
30
- ) ;
31
- await expect (
32
- leakingObjectsInHeapSnapshotFiles ( [
33
- snap1 . filepath ,
34
- snap2 . filepath ,
35
- snap3 . filepath ,
36
- snap4 . filepath ,
37
- ] ) ,
38
- ) . resolves . toMatchInlineSnapshot ( `
24
+ ] ) ;
25
+ await expect ( leakingObjectsInHeapSnapshotFiles ( snaps . filepaths ) ) . resolves
26
+ . toMatchInlineSnapshot ( `
27
+ {}
28
+ ` ) ;
29
+ } ,
30
+ ) ;
31
+
32
+ it . skipIf (
33
+ // no need to test in bun (also, bun does not support increasing timeouts per test)
34
+ globalThis . Bun ,
35
+ ) (
36
+ 'should correctly detect randomly growing and freeing objects in size' ,
37
+ {
38
+ // parsing snapshots can take a while, so we increase the timeout
39
+ timeout : 30_000 ,
40
+ } ,
41
+ async ( ) => {
42
+ await using snaps = await archivedFixtureFiles ( [
43
+ 'random-grow-and-free/1.heapsnapshot' ,
44
+ 'random-grow-and-free/2.heapsnapshot' ,
45
+ 'random-grow-and-free/3.heapsnapshot' ,
46
+ 'random-grow-and-free/4.heapsnapshot' ,
47
+ 'random-grow-and-free/5.heapsnapshot' ,
48
+ 'random-grow-and-free/6.heapsnapshot' ,
49
+ ] ) ;
50
+ await expect ( leakingObjectsInHeapSnapshotFiles ( snaps . filepaths ) ) . resolves
51
+ . toMatchInlineSnapshot ( `
39
52
{
40
53
"(compiled code)": {
41
- "addedCount": 1727 ,
42
- "addedSize": 228096 ,
43
- "countDelta": 91 ,
54
+ "addedCount": 24267 ,
55
+ "addedSize": 4981944 ,
56
+ "countDelta": -19747 ,
44
57
"name": "(compiled code)",
45
- "removedCount": 1636 ,
46
- "removedSize": 163328 ,
47
- "sizeDelta": 64768 ,
58
+ "removedCount": 44014 ,
59
+ "removedSize": 2541944 ,
60
+ "sizeDelta": 2440000 ,
48
61
},
49
62
}
50
63
` ) ;
51
64
} ,
52
65
) ;
53
66
54
67
/**
55
- * Unarchives the {@link archivedFile provided fixture file } for using in
56
- * tests and then removes it on disposal.
68
+ * Unarchives the {@link archivedFiles provided fixture files } for using in
69
+ * tests and then removes them on disposal.
57
70
*
58
- * @param archivedFile - The name of the archived fixture file (without `.tar.gz`). Is the
71
+ * @param archivedFiles - An array of file names of the archived fixture file (without `.tar.gz`). Is the
59
72
* filename of the file inside the archive.
60
73
*/
61
- async function archivedFixtureFile ( archivedFile : string ) {
62
- const filepath = path . join ( __fixtures , archivedFile ) ;
63
- const [ , waitForExit ] = await spawn (
64
- {
65
- cwd : __fixtures ,
66
- } ,
67
- 'tar' ,
68
- '-xz' ,
69
- '-f' ,
70
- archivedFile + '.tar.gz' ,
71
- '-C' ,
72
- path . dirname ( filepath ) ,
73
- ) ;
74
- await waitForExit ;
74
+ async function archivedFixtureFiles ( archivedFiles : string [ ] ) {
75
+ const filepaths : string [ ] = [ ] ;
76
+ for ( const archivedFile of archivedFiles ) {
77
+ const filepath = path . join ( __fixtures , archivedFile ) ;
78
+ const [ , waitForExit ] = await spawn (
79
+ {
80
+ cwd : __fixtures ,
81
+ } ,
82
+ 'tar' ,
83
+ '-xz' ,
84
+ '-f' ,
85
+ archivedFile + '.tar.gz' ,
86
+ '-C' ,
87
+ path . dirname ( filepath ) ,
88
+ ) ;
89
+ await waitForExit ;
90
+ filepaths . push ( filepath ) ;
91
+ }
75
92
return {
76
- [ Symbol . asyncDispose ] ( ) {
77
- return fs . unlink ( filepath ) ;
93
+ async [ Symbol . asyncDispose ] ( ) {
94
+ await Promise . all ( filepaths . map ( ( filepath ) => fs . unlink ( filepath ) ) ) ;
78
95
} ,
79
- filepath ,
96
+ filepaths ,
80
97
} ;
81
98
}
0 commit comments