Spaces:
Runtime error
Runtime error
File size: 1,289 Bytes
077865a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { createApp } from '../../app.js';
import { initDb } from '../../db/index.js';
// CLIENT_DIST relocates the built dashboard for embedders (the desktop app
// ships client/dist in extraResources, out of reach of the default
// __dirname-relative path).
describe('CLIENT_DIST override', () => {
let tmpDir: string;
beforeAll(() => {
process.env.ENCRYPTION_KEY = '0'.repeat(64);
initDb(':memory:');
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'freeapi-client-dist-'));
fs.writeFileSync(path.join(tmpDir, 'index.html'), '<!doctype html><title>custom-dist</title>');
});
afterAll(() => {
delete process.env.CLIENT_DIST;
fs.rmSync(tmpDir, { recursive: true, force: true });
});
it('serves the SPA from the overridden directory', async () => {
process.env.CLIENT_DIST = tmpDir;
const app = createApp();
const server = app.listen(0);
const port = (server.address() as any).port;
const res = await fetch(`http://127.0.0.1:${port}/`);
const html = await res.text();
server.close();
expect(res.status).toBe(200);
expect(html).toContain('custom-dist');
});
});
|