@@ -13,6 +13,7 @@ const { spawnSync } = require('child_process');
1313const { backends, WPTRunner } = require ( '../common/wpt' ) ;
1414
1515const queueProbe = process . env . NODE_TEST_WPT_QUEUE_PROBE === '1' ;
16+ const backendProbe = process . env . NODE_TEST_WPT_BACKEND_PROBE ;
1617
1718const harnessPath = fixtures . path ( 'wpt' , 'resources' , 'testharness.js' ) ;
1819const specPath = fixtures . path ( 'wpt-backends-spec.js' ) ;
@@ -156,7 +157,74 @@ function checkQueuedSpecsKeepRunnerAlive() {
156157 assert . strictEqual ( status , 0 , `Queued WPT probe failed:\n${ stdout } ${ stderr } ` ) ;
157158}
158159
160+ function runDefaultBackendProbe ( ) {
161+ const runner = new WPTRunner ( 'compression' ) ;
162+ assert . strictEqual ( runner . runSpec , backends [ backendProbe ] ) ;
163+ }
164+
165+ function checkBackendSelection ( ) {
166+ const env = { ...process . env } ;
167+ delete env . WPT_BACKEND ;
168+ delete env . WPT_INSPECT ;
169+
170+ for ( const [ name , expected , args , overrides ] of [
171+ [ 'default' , 'thread' , [ __filename ] ] ,
172+ [ 'environment override' , 'process' , [ __filename ] , { WPT_BACKEND : 'process' } ] ,
173+ [ 'inspect override' , 'process' , [ __filename ] , {
174+ WPT_BACKEND : 'thread' ,
175+ WPT_INSPECT : '1' ,
176+ } ] ,
177+ ] ) {
178+ const result = spawnSync ( process . execPath , args , {
179+ env : {
180+ ...env ,
181+ ...overrides ,
182+ NODE_TEST_WPT_BACKEND_PROBE : expected ,
183+ } ,
184+ encoding : 'utf8' ,
185+ timeout : common . platformTimeout ( 10_000 ) ,
186+ } ) ;
187+ const { error, status, stdout, stderr } = result ;
188+ assert . ifError ( error ) ;
189+ assert . strictEqual (
190+ status ,
191+ 0 ,
192+ `${ name } WPT backend probe failed:\n${ stdout } ${ stderr } ` ,
193+ ) ;
194+ }
195+ }
196+
197+ function checkInspectSelection ( ) {
198+ const driver = path . join ( __dirname , '../wpt/test-compression.js' ) ;
199+ const env = { ...process . env , WPT_INSPECT : '1' } ;
200+ delete env . WPT_BACKEND ;
201+
202+ const runFailure = common . mustCall ( ( args , expected ) => {
203+ const result = spawnSync ( process . execPath , [ driver , ...args ] , {
204+ env,
205+ encoding : 'utf8' ,
206+ timeout : common . platformTimeout ( 10_000 ) ,
207+ } ) ;
208+ const { error, status, stdout, stderr } = result ;
209+ assert . ifError ( error ) ;
210+ assert . strictEqual ( status , 1 , `WPT inspect probe passed:\n${ stdout } ${ stderr } ` ) ;
211+ assert . match ( stderr , expected ) ;
212+ } , 3 ) ;
213+
214+ runFailure ( [ ] , / W P T _ I N S P E C T r e q u i r e s a W P T t e s t p a t h / ) ;
215+ runFailure (
216+ [ 'compression-bad-chunks.any.js' ] ,
217+ / W P T _ I N S P E C T r e q u i r e s e x a c t l y o n e g e n e r a t e d W P T t e s t p a t h ; .* m a t c h e d 2 : \r ? \n c o m p r e s s i o n \/ c o m p r e s s i o n - b a d - c h u n k s \. a n y \. h t m l \r ? \n c o m p r e s s i o n \/ c o m p r e s s i o n - b a d - c h u n k s \. a n y \. w o r k e r \. h t m l / ,
218+ ) ;
219+ runFailure (
220+ [ 'compression/compression-bad-chunks.any.worker.html' ] ,
221+ / W P T _ I N S P E C T d o e s n o t s u p p o r t w o r k e r t e s t s : c o m p r e s s i o n \/ c o m p r e s s i o n - b a d - c h u n k s \. a n y \. w o r k e r \. h t m l / ,
222+ ) ;
223+ }
224+
159225async function main ( ) {
226+ checkBackendSelection ( ) ;
227+ checkInspectSelection ( ) ;
160228 checkQueuedSpecsKeepRunnerAlive ( ) ;
161229
162230 const completed = await compare ( false ) ;
@@ -197,7 +265,9 @@ async function main() {
197265 assert . deepStrictEqual ( workerResults , windowResults ) ;
198266}
199267
200- if ( queueProbe ) {
268+ if ( backendProbe ) {
269+ runDefaultBackendProbe ( ) ;
270+ } else if ( queueProbe ) {
201271 runQueueProbe ( ) ;
202272} else {
203273 main ( ) . then ( common . mustCall ( ) ) ;
0 commit comments