test: speed terminal comparisons and retry policy checks (#26396)

This commit is contained in:
Neil
2026-10-07 21:01:48 -07:00
committed by GitHub
parent 265c62645d
commit 00a82505c4
2 changed files with 37 additions and 4 deletions
@@ -132,6 +132,29 @@ function sameCellFields(expected: Cell, actual: Cell): boolean {
)
}
// Match the frozen default-blank descriptor without formatting every trailing cell.
function isDefaultBlank(line: BufferLine | undefined, x: number, scratch: Cell): boolean {
if (!line || x >= line.length) {
return true
}
const cell = line.getCell(x, scratch)
if (!cell) {
return true
}
const chars = cell.getChars()
return (
cell.getWidth() === 1 &&
cell.getBgColorMode() === 0 &&
cell.getBgColor() === -1 &&
cell.isInverse() === 0 &&
(chars === '' ||
(chars === ' ' &&
cell.isUnderline() === 0 &&
cell.isStrikethrough() === 0 &&
cell.isOverline() === 0))
)
}
function trimmedEnd(
buffer: Buffer,
start: number,
@@ -143,7 +166,7 @@ function trimmedEnd(
const line = buffer.getLine(end - 1)
let blank = true
for (let x = 0; x < cols; x++) {
if (cellDescriptor(line, x, cols, scratch) !== DEFAULT_BLANK) {
if (!isDefaultBlank(line, x, scratch)) {
blank = false
break
}
@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { retryTransientMainEvaluate } from './electron-main-evaluate-retry'
const transientMessages = [
@@ -6,6 +6,8 @@ const transientMessages = [
'electronApplication.evaluate: Resulting promise was garbage collected.'
]
afterEach(() => vi.useRealTimers())
describe('retryTransientMainEvaluate', () => {
it('returns the first successful read without retrying', async () => {
let calls = 0
@@ -19,8 +21,9 @@ describe('retryTransientMainEvaluate', () => {
})
it.each(transientMessages)('retries a transient startup failure: %s', async (message) => {
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
let calls = 0
await expect(
const outcome = expect(
retryTransientMainEvaluate(async () => {
calls += 1
if (calls < 3) {
@@ -29,6 +32,9 @@ describe('retryTransientMainEvaluate', () => {
return '/isolated/home'
})
).resolves.toBe('/isolated/home')
void outcome.catch(() => undefined)
await vi.advanceTimersByTimeAsync(400)
await outcome
expect(calls).toBe(3)
})
@@ -46,13 +52,17 @@ describe('retryTransientMainEvaluate', () => {
it.each(transientMessages)(
'bounds retries when evaluation keeps failing: %s',
async (message) => {
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
let calls = 0
await expect(
const outcome = expect(
retryTransientMainEvaluate(async () => {
calls += 1
throw new Error(message)
})
).rejects.toThrow(message)
void outcome.catch(() => undefined)
await vi.advanceTimersByTimeAsync(800)
await outcome
expect(calls).toBe(5)
}
)