forked from boos/BoosAPI
feat: implement macOS notarization and ad-hoc signing in afterSign script
feat: add run-server script to manage server execution and compatibility checks feat: create main application logic for desktop with window management, server handling, and auto-updater test: add unit tests for desktop runtime helpers feat: implement desktop server environment configuration and health check test: add tests for server configuration and desktop routes feat: add native module guard for better-sqlite3 compatibility test: add tests for native module guard functionality test: add comprehensive tests for account verification feedback handling feat: implement account verification feedback helpers chore: add TypeScript configuration for desktop builds
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
buildDesktopServerEnv,
|
||||
createDesktopServerUrl,
|
||||
isFatalServerExit,
|
||||
waitForServerReady,
|
||||
} from './runtime.js';
|
||||
|
||||
describe('desktop runtime helpers', () => {
|
||||
it('builds desktop server env with loopback host and app directories', () => {
|
||||
const env = buildDesktopServerEnv({
|
||||
inheritedEnv: {
|
||||
AUTH_TOKEN: 'admin-token',
|
||||
PROXY_TOKEN: 'proxy-token',
|
||||
},
|
||||
userDataDir: '/tmp/metapi-data',
|
||||
logsDir: '/tmp/metapi-logs',
|
||||
port: 4312,
|
||||
});
|
||||
|
||||
expect(env.HOST).toBe('127.0.0.1');
|
||||
expect(env.PORT).toBe('4312');
|
||||
expect(env.DATA_DIR).toBe('/tmp/metapi-data');
|
||||
expect(env.METAPI_LOG_DIR).toBe('/tmp/metapi-logs');
|
||||
expect(env.AUTH_TOKEN).toBe('admin-token');
|
||||
expect(env.PROXY_TOKEN).toBe('proxy-token');
|
||||
});
|
||||
|
||||
it('creates the browser URL from the local desktop port', () => {
|
||||
expect(createDesktopServerUrl(4312)).toBe('http://127.0.0.1:4312');
|
||||
});
|
||||
|
||||
it('waits until the health probe returns ok', async () => {
|
||||
const fetcher = vi.fn()
|
||||
.mockRejectedValueOnce(new Error('offline'))
|
||||
.mockResolvedValueOnce({ ok: false })
|
||||
.mockResolvedValueOnce({ ok: true });
|
||||
|
||||
await expect(waitForServerReady({
|
||||
url: 'http://127.0.0.1:4312/api/desktop/health',
|
||||
fetcher,
|
||||
timeoutMs: 250,
|
||||
intervalMs: 1,
|
||||
})).resolves.toBeUndefined();
|
||||
|
||||
expect(fetcher).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
it('fails when the health probe never becomes ready', async () => {
|
||||
const fetcher = vi.fn().mockResolvedValue({ ok: false });
|
||||
|
||||
await expect(waitForServerReady({
|
||||
url: 'http://127.0.0.1:4312/api/desktop/health',
|
||||
fetcher,
|
||||
timeoutMs: 10,
|
||||
intervalMs: 1,
|
||||
})).rejects.toThrow('Timed out waiting for metapi desktop server');
|
||||
});
|
||||
|
||||
it('treats non-zero non-signal exits as fatal', () => {
|
||||
expect(isFatalServerExit({ code: 1, signal: null })).toBe(true);
|
||||
expect(isFatalServerExit({ code: 0, signal: null })).toBe(false);
|
||||
expect(isFatalServerExit({ code: null, signal: 'SIGTERM' })).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user