Files
tspm/test/test.daemon.ts

65 lines
2.0 KiB
TypeScript

import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as tspm from '../ts/index.js';
import * as path from 'path';
import * as fs from 'fs/promises';
// These tests have been disabled after the architecture refactoring
// TspmDaemon is now internal to the daemon and not exported
// Future tests should focus on testing via the IPC client interface
tap.test('Daemon exports available', async () => {
// Test that the daemon can be started via the exported function
expect(tspm.startDaemon).toBeTypeOf('function');
});
tap.test('PID file management utilities', async (tools) => {
const testDir = path.join(process.cwd(), '.nogit');
const testPidFile = path.join(testDir, 'test-daemon.pid');
// Create directory if it doesn't exist
await fs.mkdir(testDir, { recursive: true });
// Clean up any existing test file
await fs.unlink(testPidFile).catch(() => {});
// Test writing PID file
await fs.writeFile(testPidFile, process.pid.toString());
const pidContent = await fs.readFile(testPidFile, 'utf-8');
expect(parseInt(pidContent)).toEqual(process.pid);
// Clean up
await fs.unlink(testPidFile);
});
tap.test('Process memory usage reporting', async () => {
const memUsage = process.memoryUsage();
expect(memUsage.heapUsed).toBeGreaterThan(0);
expect(memUsage.heapTotal).toBeGreaterThan(0);
expect(memUsage.rss).toBeGreaterThan(0);
});
tap.test('Process CPU usage calculation', async () => {
const cpuUsage = process.cpuUsage();
expect(cpuUsage.user).toBeGreaterThanOrEqual(0);
expect(cpuUsage.system).toBeGreaterThanOrEqual(0);
// Test conversion to seconds
const cpuSeconds = cpuUsage.user / 1000000;
expect(cpuSeconds).toBeGreaterThanOrEqual(0);
});
tap.test('Uptime calculation', async () => {
const startTime = Date.now();
// Wait a bit
await new Promise((resolve) => setTimeout(resolve, 100));
const uptime = Date.now() - startTime;
expect(uptime).toBeGreaterThanOrEqual(95); // Allow some timing variance
expect(uptime).toBeLessThan(200);
});
export default tap.start();