@@ -9,7 +9,7 @@ const { tspl } = require('@matteo.collina/tspl')
99const removeEscapeColorsRE = / [ \u001b \u009b ] [ [ ( ) # ; ? ] * (?: [ 0 - 9 ] { 1 , 4 } (?: ; [ 0 - 9 ] { 0 , 4 } ) * ) ? [ 0 - 9 A - O R Z c f - n q r y = > < ] / g
1010
1111test ( 'debug#websocket' , async t => {
12- const assert = tspl ( t , { plan : 6 } )
12+ const assert = tspl ( t , { plan : 8 } )
1313 const child = spawn (
1414 process . execPath ,
1515 [ join ( __dirname , '../fixtures/websocket.js' ) ] ,
@@ -24,20 +24,23 @@ test('debug#websocket', async t => {
2424 / ( W E B S O C K E T [ 0 - 9 ] + : ) ( c o n n e c t i n g t o ) / ,
2525 // Skip the chunk that comes with the experimental warning
2626 / ( \[ U N D I C I - W S \] ) / ,
27+ / \( U s e ` n o d e - - t r a c e - w a r n i n g s \. \. \. ` t o s h o w w h e r e t h e w a r n i n g w a s c r e a t e d \) / ,
2728 / ( W E B S O C K E T [ 0 - 9 ] + : ) ( c o n n e c t e d t o ) / ,
2829 / ( W E B S O C K E T [ 0 - 9 ] + : ) ( s e n d i n g r e q u e s t ) / ,
2930 / ( W E B S O C K E T [ 0 - 9 ] + : ) ( c o n n e c t i o n o p e n e d ) / ,
30- / ( W E B S O C K E T [ 0 - 9 ] + : ) ( c l o s e d c o n n e c t i o n t o ) /
31+ / ( W E B S O C K E T [ 0 - 9 ] + : ) ( c l o s e d c o n n e c t i o n t o ) / ,
32+ / ^ $ /
3133 ]
3234
3335 child . stderr . setEncoding ( 'utf8' )
3436 child . stderr . on ( 'data' , chunk => {
3537 chunks . push ( chunk )
3638 } )
3739 child . stderr . on ( 'end' , ( ) => {
38- assert . strictEqual ( chunks . length , assertions . length , JSON . stringify ( chunks ) )
39- for ( let i = 1 ; i < chunks . length ; i ++ ) {
40- assert . match ( chunks [ i ] . replace ( removeEscapeColorsRE , '' ) , assertions [ i ] )
40+ const lines = extractLines ( chunks )
41+ assert . strictEqual ( lines . length , assertions . length )
42+ for ( let i = 1 ; i < lines . length ; i ++ ) {
43+ assert . match ( lines [ i ] , assertions [ i ] )
4144 }
4245 } )
4346
@@ -46,7 +49,7 @@ test('debug#websocket', async t => {
4649} )
4750
4851test ( 'debug#fetch' , async t => {
49- const assert = tspl ( t , { plan : 6 } )
52+ const assert = tspl ( t , { plan : 7 } )
5053 const child = spawn (
5154 process . execPath ,
5255 [ join ( __dirname , '../fixtures/fetch.js' ) ] ,
@@ -60,17 +63,19 @@ test('debug#fetch', async t => {
6063 / ( F E T C H [ 0 - 9 ] + : ) ( c o n n e c t e d t o ) / ,
6164 / ( F E T C H [ 0 - 9 ] + : ) ( s e n d i n g r e q u e s t ) / ,
6265 / ( F E T C H [ 0 - 9 ] + : ) ( r e c e i v e d r e s p o n s e ) / ,
63- / ( F E T C H [ 0 - 9 ] + : ) ( t r a i l e r s r e c e i v e d ) /
66+ / ( F E T C H [ 0 - 9 ] + : ) ( t r a i l e r s r e c e i v e d ) / ,
67+ / ^ $ /
6468 ]
6569
6670 child . stderr . setEncoding ( 'utf8' )
6771 child . stderr . on ( 'data' , chunk => {
6872 chunks . push ( chunk )
6973 } )
7074 child . stderr . on ( 'end' , ( ) => {
71- assert . strictEqual ( chunks . length , assertions . length , JSON . stringify ( chunks ) )
72- for ( let i = 0 ; i < chunks . length ; i ++ ) {
73- assert . match ( chunks [ i ] . replace ( removeEscapeColorsRE , '' ) , assertions [ i ] )
75+ const lines = extractLines ( chunks )
76+ assert . strictEqual ( lines . length , assertions . length )
77+ for ( let i = 0 ; i < lines . length ; i ++ ) {
78+ assert . match ( lines [ i ] , assertions [ i ] )
7479 }
7580 } )
7681
@@ -80,7 +85,7 @@ test('debug#fetch', async t => {
8085
8186test ( 'debug#undici' , async t => {
8287 // Due to Node.js webpage redirect
83- const assert = tspl ( t , { plan : 6 } )
88+ const assert = tspl ( t , { plan : 7 } )
8489 const child = spawn (
8590 process . execPath ,
8691 [ join ( __dirname , '../fixtures/undici.js' ) ] ,
@@ -96,20 +101,29 @@ test('debug#undici', async t => {
96101 / ( U N D I C I [ 0 - 9 ] + : ) ( c o n n e c t e d t o ) / ,
97102 / ( U N D I C I [ 0 - 9 ] + : ) ( s e n d i n g r e q u e s t ) / ,
98103 / ( U N D I C I [ 0 - 9 ] + : ) ( r e c e i v e d r e s p o n s e ) / ,
99- / ( U N D I C I [ 0 - 9 ] + : ) ( t r a i l e r s r e c e i v e d ) /
104+ / ( U N D I C I [ 0 - 9 ] + : ) ( t r a i l e r s r e c e i v e d ) / ,
105+ / ^ $ /
100106 ]
101107
102108 child . stderr . setEncoding ( 'utf8' )
103109 child . stderr . on ( 'data' , chunk => {
104110 chunks . push ( chunk )
105111 } )
106112 child . stderr . on ( 'end' , ( ) => {
107- assert . strictEqual ( chunks . length , assertions . length , JSON . stringify ( chunks ) )
108- for ( let i = 0 ; i < chunks . length ; i ++ ) {
109- assert . match ( chunks [ i ] . replace ( removeEscapeColorsRE , '' ) , assertions [ i ] )
113+ const lines = extractLines ( chunks )
114+ assert . strictEqual ( lines . length , assertions . length )
115+ for ( let i = 0 ; i < lines . length ; i ++ ) {
116+ assert . match ( lines [ i ] , assertions [ i ] )
110117 }
111118 } )
112119
113120 await assert . completed
114121 child . kill ( )
115122} )
123+
124+ function extractLines ( chunks ) {
125+ return chunks
126+ . join ( '' )
127+ . split ( '\n' )
128+ . map ( v => v . replace ( removeEscapeColorsRE , '' ) )
129+ }
0 commit comments