@@ -98,27 +98,44 @@ t.test('libc', (t) => {
9898 let PLATFORM = 'linux'
9999 let REPORT = { }
100100 let readFileSync
101+ let noCache = true
102+
103+ function withCache ( cb ) {
104+ noCache = false
105+ cb ( )
106+ noCache = true
107+ withoutLibcCache ( )
108+ }
101109
102110 function withoutLibcCache ( ) {
103111 readFileSync = ( ) => {
104112 throw new Error ( 'File not found' )
105113 }
106- noCacheChckPtfm = ( ... args ) => {
107- const original = t . mock ( '..' , {
108- '../lib/current-env' : t . mock ( '../lib/current-env' , {
109- 'node:fs' : {
110- readFileSync,
114+ const original = t . mock ( '..' , {
115+ '../lib/current-env' : t . mock ( '../lib/current-env ' , {
116+ 'node:fs' : {
117+ readFileSync : ( ) => {
118+ return readFileSync ( )
111119 } ,
112- 'node:process' : {
113- platform : PLATFORM ,
114- report : {
115- getReport : ( ) => REPORT ,
116- } ,
120+ } ,
121+ 'node:process' : Object . defineProperty ( {
122+ report : {
123+ getReport : ( ) => REPORT ,
117124 } ,
125+ } , 'platform' , {
126+ enumerable : true ,
127+ get : ( ) => PLATFORM ,
118128 } ) ,
119- } ) . checkPlatform
120- withoutLibcCache ( )
121- return original ( ...args )
129+ } ) ,
130+ } ) . checkPlatform
131+ noCacheChckPtfm = ( ...args ) => {
132+ try {
133+ original ( ...args )
134+ } finally {
135+ if ( noCache ) {
136+ withoutLibcCache ( )
137+ }
138+ }
122139 }
123140 }
124141
@@ -137,8 +154,16 @@ t.test('libc', (t) => {
137154 t . test ( 'glibc' , ( t ) => {
138155 PLATFORM = 'linux'
139156
140- readFileSync = ( ) => 'this ldd file contains GNU C Library'
141- t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , 'allows glibc on glibc from ldd file' )
157+ withCache ( ( ) => {
158+ readFileSync = ( ) => 'this ldd file contains GNU C Library'
159+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) ,
160+ 'allows glibc on glibc from ldd file' )
161+
162+ readFileSync = ( ) => {
163+ throw new Error ( 'File not found' )
164+ }
165+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , 'allows glibc from ldd file cache' )
166+ } )
142167
143168 REPORT = { }
144169 t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
@@ -148,8 +173,13 @@ t.test('libc', (t) => {
148173 t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
149174 'fails when header is missing glibcVersionRuntime property' )
150175
151- REPORT = { header : { glibcVersionRuntime : '1' } }
152- t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , 'allows glibc on glibc' )
176+ withCache ( ( ) => {
177+ REPORT = { header : { glibcVersionRuntime : '1' } }
178+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , 'allows glibc on glibc' )
179+
180+ REPORT = { }
181+ t . doesNotThrow ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , 'allows glibc from report cache' )
182+ } )
153183
154184 readFileSync = ( ) => 'this ldd file is unsupported'
155185 t . throws ( ( ) => noCacheChckPtfm ( { libc : 'glibc' } ) , { code : 'EBADPLATFORM' } ,
0 commit comments