test: cover publishing, authentication and storage persistence
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { access, cp, readFile } from 'node:fs/promises';
|
||||
import { spawn, spawnSync } from 'node:child_process';
|
||||
import { access, cp, readFile, mkdtemp, rm } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { once } from 'node:events';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
|
||||
@@ -23,6 +25,8 @@ async function waitForServer(process, getLogs) {
|
||||
}
|
||||
|
||||
test('the standalone server renders both locales and serves local images', async (t) => {
|
||||
const dataDir = await mkdtemp(path.join(tmpdir(), 'portfolio-runtime-'));
|
||||
const env = { ...process.env, DATA_DIR: dataDir, SITE_URL: origin, HOSTNAME: '127.0.0.1', PORT: String(port) };
|
||||
await access(path.join(standaloneRoot, 'server.js'));
|
||||
await cp(path.join(projectRoot, 'public'), path.join(standaloneRoot, 'public'), { recursive: true });
|
||||
await cp(
|
||||
@@ -31,15 +35,17 @@ test('the standalone server renders both locales and serves local images', async
|
||||
{ recursive: true },
|
||||
);
|
||||
|
||||
const imported = spawnSync(process.execPath, ['maintenance.mjs', 'import-legacy'], { cwd: standaloneRoot, env, encoding: 'utf8' });
|
||||
assert.equal(imported.status, 0, imported.stderr);
|
||||
const server = spawn(process.execPath, ['server.js'], {
|
||||
cwd: standaloneRoot,
|
||||
env: { ...process.env, HOSTNAME: '127.0.0.1', PORT: String(port) },
|
||||
env,
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
let serverLogs = '';
|
||||
server.stdout.on('data', (chunk) => { serverLogs += chunk; });
|
||||
server.stderr.on('data', (chunk) => { serverLogs += chunk; });
|
||||
t.after(() => server.kill());
|
||||
t.after(async () => { if (server.exitCode === null) { const exited = once(server, 'exit'); server.kill(); await exited; } await rm(dataDir, { recursive: true, force: true }); });
|
||||
await waitForServer(server, () => serverLogs);
|
||||
|
||||
const [englishResponse, persianResponse] = await Promise.all([
|
||||
|
||||
Reference in New Issue
Block a user