diff --git a/test/node-test/debug.js b/test/node-test/debug.js index 276e8d3613d..055b2a121df 100644 --- a/test/node-test/debug.js +++ b/test/node-test/debug.js @@ -9,7 +9,7 @@ const { tspl } = require('@matteo.collina/tspl') const removeEscapeColorsRE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g test('debug#websocket', async t => { - const assert = tspl(t, { plan: 6 }) + const assert = tspl(t, { plan: 8 }) const child = spawn( process.execPath, [join(__dirname, '../fixtures/websocket.js')], @@ -24,10 +24,12 @@ test('debug#websocket', async t => { /(WEBSOCKET [0-9]+:) (connecting to)/, // Skip the chunk that comes with the experimental warning /(\[UNDICI-WS\])/, + /\(Use `node --trace-warnings \.\.\.` to show where the warning was created\)/, /(WEBSOCKET [0-9]+:) (connected to)/, /(WEBSOCKET [0-9]+:) (sending request)/, /(WEBSOCKET [0-9]+:) (connection opened)/, - /(WEBSOCKET [0-9]+:) (closed connection to)/ + /(WEBSOCKET [0-9]+:) (closed connection to)/, + /^$/ ] child.stderr.setEncoding('utf8') @@ -35,9 +37,10 @@ test('debug#websocket', async t => { chunks.push(chunk) }) child.stderr.on('end', () => { - assert.strictEqual(chunks.length, assertions.length, JSON.stringify(chunks)) - for (let i = 1; i < chunks.length; i++) { - assert.match(chunks[i].replace(removeEscapeColorsRE, ''), assertions[i]) + const lines = extractLines(chunks) + assert.strictEqual(lines.length, assertions.length) + for (let i = 1; i < lines.length; i++) { + assert.match(lines[i], assertions[i]) } }) @@ -46,7 +49,7 @@ test('debug#websocket', async t => { }) test('debug#fetch', async t => { - const assert = tspl(t, { plan: 6 }) + const assert = tspl(t, { plan: 7 }) const child = spawn( process.execPath, [join(__dirname, '../fixtures/fetch.js')], @@ -60,7 +63,8 @@ test('debug#fetch', async t => { /(FETCH [0-9]+:) (connected to)/, /(FETCH [0-9]+:) (sending request)/, /(FETCH [0-9]+:) (received response)/, - /(FETCH [0-9]+:) (trailers received)/ + /(FETCH [0-9]+:) (trailers received)/, + /^$/ ] child.stderr.setEncoding('utf8') @@ -68,9 +72,10 @@ test('debug#fetch', async t => { chunks.push(chunk) }) child.stderr.on('end', () => { - assert.strictEqual(chunks.length, assertions.length, JSON.stringify(chunks)) - for (let i = 0; i < chunks.length; i++) { - assert.match(chunks[i].replace(removeEscapeColorsRE, ''), assertions[i]) + const lines = extractLines(chunks) + assert.strictEqual(lines.length, assertions.length) + for (let i = 0; i < lines.length; i++) { + assert.match(lines[i], assertions[i]) } }) @@ -80,7 +85,7 @@ test('debug#fetch', async t => { test('debug#undici', async t => { // Due to Node.js webpage redirect - const assert = tspl(t, { plan: 6 }) + const assert = tspl(t, { plan: 7 }) const child = spawn( process.execPath, [join(__dirname, '../fixtures/undici.js')], @@ -96,7 +101,8 @@ test('debug#undici', async t => { /(UNDICI [0-9]+:) (connected to)/, /(UNDICI [0-9]+:) (sending request)/, /(UNDICI [0-9]+:) (received response)/, - /(UNDICI [0-9]+:) (trailers received)/ + /(UNDICI [0-9]+:) (trailers received)/, + /^$/ ] child.stderr.setEncoding('utf8') @@ -104,12 +110,20 @@ test('debug#undici', async t => { chunks.push(chunk) }) child.stderr.on('end', () => { - assert.strictEqual(chunks.length, assertions.length, JSON.stringify(chunks)) - for (let i = 0; i < chunks.length; i++) { - assert.match(chunks[i].replace(removeEscapeColorsRE, ''), assertions[i]) + const lines = extractLines(chunks) + assert.strictEqual(lines.length, assertions.length) + for (let i = 0; i < lines.length; i++) { + assert.match(lines[i], assertions[i]) } }) await assert.completed child.kill() }) + +function extractLines (chunks) { + return chunks + .join('') + .split('\n') + .map(v => v.replace(removeEscapeColorsRE, '')) +}