MCPcopy
hub / github.com/nodejs/undici / runSingleTest

Function runSingleTest

test/web-platform-tests/wpt-runner.mjs:333–422  ·  view source on GitHub ↗
(url, options, expectation, timeout = 10000)

Source from the content-addressed store, hash-verified

331}
332
333function runSingleTest (url, options, expectation, timeout = 10000) {
334 const startTime = Date.now()
335 const { promise, resolve, reject } = Promise.withResolvers()
336 // NODE_EXTRA_CA_CERTS is required for HTTPS/WSS pages, but it causes the
337 // WebSocket-over-HTTP/2 WPT variants to exit without emitting harness output.
338 const useExtraCACerts = !(url.pathname.startsWith('/websockets/') && url.searchParams.get('wpt_flags')?.includes('h2'))
339
340 const proc = spawn('node', [
341 '--expose-gc',
342 '--no-warnings',
343 join(import.meta.dirname, 'runner/test-runner.mjs'),
344 url.toString()
345 ], {
346 stdio: ['ignore', 'pipe', 'pipe'],
347 env: {
348 ...process.env,
349 NO_COLOR: '1',
350 ...(useExtraCACerts ? { NODE_EXTRA_CA_CERTS: CA_CERT_PATH } : {})
351 }
352 })
353
354 const cases = []
355 let harnessStatus = null
356 let stdoutOutput = ''
357 let stderrOutput = ''
358 let error
359
360 const timer = setTimeout(() => {
361 if (!proc.killed) {
362 proc.kill('SIGINT')
363 }
364 }, timeout)
365
366 proc.stdout.setEncoding('utf-8')
367 proc.stdout.on('data', (chunk) => {
368 stdoutOutput += chunk
369
370 let delimiterIndex
371 while ((delimiterIndex = stdoutOutput.indexOf('#$#$#')) !== -1) {
372 const endIndex = stdoutOutput.indexOf('\n', delimiterIndex)
373 if (endIndex !== -1) {
374 const message = stdoutOutput.slice(delimiterIndex + 5, endIndex)
375 try {
376 const { tests, harnessStatus: _harnessStatus } = JSON.parse(message)
377 harnessStatus = _harnessStatus
378 cases.push(...tests)
379 } catch {
380 console.error('Failed to parse:', message)
381 }
382 stdoutOutput = stdoutOutput.slice(endIndex + 1)
383 } else {
384 break
385 }
386 }
387 })
388
389 proc.stderr.setEncoding('utf-8')
390 proc.stderr.on('data', (chunk) => {

Callers 1

runFunction · 0.85

Calls 10

setTimeoutFunction · 0.85
clearTimeoutFunction · 0.85
resolveFunction · 0.85
rejectFunction · 0.85
setEncodingMethod · 0.80
getMethod · 0.65
toStringMethod · 0.45
onMethod · 0.45
pushMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…