Skip to content

Commit

Permalink
test: more resilient debug tests (#2695)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Feb 5, 2024
1 parent 415a540 commit a0812d8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions test/node-test/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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])
}
})

Expand Down Expand Up @@ -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])
}
})

Expand Down Expand Up @@ -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])
}
})

Expand Down

0 comments on commit a0812d8

Please sign in to comment.