Files
bare-operating-system/packages/bare-os-coreutils/test/baretop-bundle.test.mjs
T
2026-08-18 18:11:34 -04:00

49 lines
2.1 KiB
JavaScript

import test from 'brittle'
import { readFile } from 'node:fs/promises'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const tuiPath = join(__dirname, '../lib/baretop/baretop-tui.js')
const kernelBaretop = join(__dirname, '../../../kernel/bin/baretop')
const kernelBtop = join(__dirname, '../../../kernel/bin/btop')
test('baretop-tui uses alternate screen teardown pattern', async (t) => {
const src = await readFile(tuiPath, 'utf8')
t.ok(src.includes('[?1049h'), 'expected alternate-screen enter')
t.ok(src.includes('[?1049l'), 'expected alternate-screen leave in finally')
t.ok(src.includes('BARE_TOP_NO_ALTSCREEN'), 'expected env gate')
t.ok(
(src.match(/\\x1b\[2J\\x1b\[H/g) || []).length >= 1,
'expected full clear fallback in finally'
)
t.ok(
src.includes('incrementalFrameDiff'),
'expected incremental frame diff gate in tui source'
)
t.ok(src.includes('ctx.tui.run'), 'prefers ctx.tui.run TEA dashboard')
t.ok(src.includes('bareTopCreateTuiApp'), 'exports TEA factory')
t.ok(src.includes('bareOsRunBareTopTuiLegacy'), 'keeps pre-SDK fallback')
})
test('shipped kernel/bin/baretop includes snapshot + TUI', async (t) => {
const bin = await readFile(kernelBaretop, 'utf8')
t.ok(bin.includes('bareTopFetchSnapshot'), 'expected snapshot in bundle')
t.ok(bin.includes('bareOsRunBareTopTui'), 'expected TUI runner in bundle')
t.ok(bin.includes('[?1049l'), 'expected teardown in bundle')
t.ok(bin.includes('BARE_TOP_THEME'), 'expected theme env in bundle')
t.ok(bin.includes('bareTopStrings'), 'expected i18n string table in bundle')
t.ok(bin.includes('SIGWINCH'), 'expected resize hook in bundle')
t.ok(
bin.includes('bareTopParseMeminfoMetrics'),
'expected UI helpers in bundle'
)
t.ok(bin.includes('TAB_PROC'), 'expected processes tab in bundle')
})
test('shipped kernel/bin/btop matches baretop bundle', async (t) => {
const a = await readFile(kernelBaretop, 'utf8')
const b = await readFile(kernelBtop, 'utf8')
t.is(a, b, 'btop should be same concatenated bundle as baretop')
})