From a0812d8aed8752f76cdbd11f14693abd43689fa6 Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Mon, 5 Feb 2024 12:55:50 +0100 Subject: [PATCH] test: more resilient debug tests (#2695) --- test/node-test/debug.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/node-test/debug.js b/test/node-test/debug.js index f60500da2b2..276e8d3613d 100644 --- a/test/node-test/debug.js +++ b/test/node-test/debug.js @@ -5,6 +5,9 @@ const { spawn } = require('node:child_process') const { join } = require('node:path') const { tspl } = require('@matteo.collina/tspl') +// eslint-disable-next-line no-control-regex +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 child = spawn( @@ -32,9 +35,9 @@ test('debug#websocket', async t => { chunks.push(chunk) }) child.stderr.on('end', () => { - assert.strictEqual(chunks.length, assertions.length) + assert.strictEqual(chunks.length, assertions.length, JSON.stringify(chunks)) for (let i = 1; i < chunks.length; i++) { - assert.match(chunks[i], assertions[i]) + assert.match(chunks[i].replace(removeEscapeColorsRE, ''), assertions[i]) } }) @@ -65,9 +68,9 @@ test('debug#fetch', async t => { chunks.push(chunk) }) child.stderr.on('end', () => { - assert.strictEqual(chunks.length, assertions.length) + assert.strictEqual(chunks.length, assertions.length, JSON.stringify(chunks)) for (let i = 0; i < chunks.length; i++) { - assert.match(chunks[i], assertions[i]) + assert.match(chunks[i].replace(removeEscapeColorsRE, ''), assertions[i]) } }) @@ -101,9 +104,9 @@ test('debug#undici', async t => { chunks.push(chunk) }) child.stderr.on('end', () => { - assert.strictEqual(chunks.length, assertions.length) + assert.strictEqual(chunks.length, assertions.length, JSON.stringify(chunks)) for (let i = 0; i < chunks.length; i++) { - assert.match(chunks[i], assertions[i]) + assert.match(chunks[i].replace(removeEscapeColorsRE, ''), assertions[i]) } })