Skip to content

Commit a0812d8

Browse files
authored
test: more resilient debug tests (#2695)
1 parent 415a540 commit a0812d8

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

test/node-test/debug.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const { spawn } = require('node:child_process')
55
const { join } = require('node:path')
66
const { tspl } = require('@matteo.collina/tspl')
77

8+
// eslint-disable-next-line no-control-regex
9+
const removeEscapeColorsRE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g
10+
811
test('debug#websocket', async t => {
912
const assert = tspl(t, { plan: 6 })
1013
const child = spawn(
@@ -32,9 +35,9 @@ test('debug#websocket', async t => {
3235
chunks.push(chunk)
3336
})
3437
child.stderr.on('end', () => {
35-
assert.strictEqual(chunks.length, assertions.length)
38+
assert.strictEqual(chunks.length, assertions.length, JSON.stringify(chunks))
3639
for (let i = 1; i < chunks.length; i++) {
37-
assert.match(chunks[i], assertions[i])
40+
assert.match(chunks[i].replace(removeEscapeColorsRE, ''), assertions[i])
3841
}
3942
})
4043

@@ -65,9 +68,9 @@ test('debug#fetch', async t => {
6568
chunks.push(chunk)
6669
})
6770
child.stderr.on('end', () => {
68-
assert.strictEqual(chunks.length, assertions.length)
71+
assert.strictEqual(chunks.length, assertions.length, JSON.stringify(chunks))
6972
for (let i = 0; i < chunks.length; i++) {
70-
assert.match(chunks[i], assertions[i])
73+
assert.match(chunks[i].replace(removeEscapeColorsRE, ''), assertions[i])
7174
}
7275
})
7376

@@ -101,9 +104,9 @@ test('debug#undici', async t => {
101104
chunks.push(chunk)
102105
})
103106
child.stderr.on('end', () => {
104-
assert.strictEqual(chunks.length, assertions.length)
107+
assert.strictEqual(chunks.length, assertions.length, JSON.stringify(chunks))
105108
for (let i = 0; i < chunks.length; i++) {
106-
assert.match(chunks[i], assertions[i])
109+
assert.match(chunks[i].replace(removeEscapeColorsRE, ''), assertions[i])
107110
}
108111
})
109112

0 commit comments

Comments
 (0)