build-sidecar.mjs copies LICENSE and THIRD_PARTY_NOTICES.md from the repository root next to service.js in app/src-tauri/resources, and fails when either is missing. The resources/* glob of tauri.conf.json bundles them into every desktop installer, and build-server-archive.mjs refuses a payload without them, so the server archive carries them too. The copies are ignored by git. Tests cover the copy, the archive and the ignore rule.
149 lines
6.1 KiB
TypeScript
149 lines
6.1 KiB
TypeScript
/**
|
|
* scripts/release-smoke.mjs against stand-in payloads. The installer smoke
|
|
* test installs, checks, runs and removes a packed archive whose service is a
|
|
* small HTTP server; the desktop smoke test starts a stand-in .app that starts
|
|
* a stand-in sidecar, and must stop both.
|
|
*/
|
|
import { spawnSync } from 'node:child_process';
|
|
import fs from 'node:fs';
|
|
import net from 'node:net';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
|
|
const ROOT = path.resolve(import.meta.dirname, '..');
|
|
const SMOKE = path.join(ROOT, 'scripts', 'release-smoke.mjs');
|
|
const LAUNCHER = path.join(ROOT, 'packages', 'launcher', 'dist', 'cli.js');
|
|
const TARGETS: Record<string, string> = {
|
|
'win32-x64': 'windows-x64',
|
|
'darwin-arm64': 'macos-arm64',
|
|
'darwin-x64': 'macos-x64',
|
|
'linux-x64': 'linux-x64',
|
|
};
|
|
const target = TARGETS[`${process.platform}-${process.arch}`];
|
|
|
|
// Answers /health the way the sidecar does.
|
|
const healthServer = (port: string) => `
|
|
const http = require('node:http');
|
|
const port = Number(${port});
|
|
http.createServer((request, response) => {
|
|
response.setHeader('content-type', 'application/json');
|
|
response.end(JSON.stringify(request.url === '/health' ? { status: 'ok', mode: 'local', port } : {}));
|
|
}).listen(port, '127.0.0.1');
|
|
`;
|
|
|
|
const temps: string[] = [];
|
|
function tempDir(prefix: string): string {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
temps.push(dir);
|
|
return dir;
|
|
}
|
|
afterEach(() => {
|
|
for (const dir of temps.splice(0)) fs.rmSync(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 500 });
|
|
});
|
|
|
|
function write(file: string, content: string, mode?: number): void {
|
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
fs.writeFileSync(file, content, { mode });
|
|
}
|
|
|
|
function freePort(): Promise<number> {
|
|
return new Promise((resolve, reject) => {
|
|
const server = net.createServer();
|
|
server.once('error', reject);
|
|
server.listen(0, '127.0.0.1', () => {
|
|
const address = server.address() as net.AddressInfo;
|
|
server.close(() => resolve(address.port));
|
|
});
|
|
});
|
|
}
|
|
|
|
function runSmoke(args: string[]) {
|
|
return spawnSync(process.execPath, [SMOKE, ...args], { encoding: 'utf8', timeout: 120_000, windowsHide: true });
|
|
}
|
|
|
|
describe('release smoke tests', () => {
|
|
it.skipIf(!target || !fs.existsSync(LAUNCHER))(
|
|
'installs, checks, runs and uninstalls a server archive',
|
|
() => {
|
|
const work = tempDir('waggle-smoke-archive-');
|
|
const resources = path.join(work, 'resources');
|
|
const runtime = path.join(resources, process.platform === 'win32' ? 'node.exe' : 'node');
|
|
fs.mkdirSync(resources, { recursive: true });
|
|
// The payload runs on its own Node; this test's Node stands in for it.
|
|
if (process.platform === 'win32') fs.copyFileSync(process.execPath, runtime);
|
|
else fs.symlinkSync(process.execPath, runtime);
|
|
write(path.join(resources, 'service.js'), healthServer('process.env.WAGGLE_PORT'));
|
|
write(path.join(resources, 'LICENSE'), 'MIT License\n');
|
|
write(path.join(resources, 'THIRD_PARTY_NOTICES.md'), '# Third-party notices\n');
|
|
write(
|
|
path.join(resources, 'node_modules', 'better-sqlite3', 'index.js'),
|
|
'module.exports = class { prepare() { return { get: () => ({ 1: 1 }) }; } };\n',
|
|
);
|
|
write(path.join(work, 'web', 'index.html'), '<!doctype html>');
|
|
const out = path.join(work, 'out');
|
|
const pack = spawnSync(
|
|
process.execPath,
|
|
[
|
|
path.join(ROOT, 'scripts', 'build-server-archive.mjs'),
|
|
'--resources', resources, '--web', path.join(work, 'web'), '--out', out,
|
|
],
|
|
{ encoding: 'utf8' },
|
|
);
|
|
expect(pack.status, pack.stderr).toBe(0);
|
|
const archive = path.join(out, fs.readdirSync(out).find((name) => name.endsWith('.tar.gz'))!);
|
|
|
|
const result = runSmoke(['installer', '--archive', archive, '--timeout', '60']);
|
|
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
|
|
expect(result.stdout).toContain('The installed server answers /health');
|
|
expect(result.stdout).toContain('Installer smoke test passed');
|
|
},
|
|
150_000,
|
|
);
|
|
|
|
it.skipIf(process.platform === 'win32')(
|
|
'starts a desktop app bundle and stops it together with its sidecar',
|
|
async () => {
|
|
const port = await freePort();
|
|
const work = tempDir('waggle-smoke-desktop-');
|
|
const contents = path.join(work, 'Stand-in.app', 'Contents');
|
|
write(
|
|
path.join(contents, 'Info.plist'),
|
|
'<plist><dict><key>CFBundleExecutable</key>\n <string>stand-in</string></dict></plist>\n',
|
|
);
|
|
write(path.join(work, 'sidecar.js'), healthServer(String(port)));
|
|
// The app stays alive and owns a child process that serves /health.
|
|
write(
|
|
path.join(work, 'app.js'),
|
|
`require('node:child_process').spawn(process.execPath, [${JSON.stringify(path.join(work, 'sidecar.js'))}], { stdio: 'inherit' });\n`
|
|
+ 'setInterval(() => {}, 1000);\n',
|
|
);
|
|
write(
|
|
path.join(contents, 'MacOS', 'stand-in'),
|
|
`#!/bin/sh\nexec ${JSON.stringify(process.execPath)} ${JSON.stringify(path.join(work, 'app.js'))}\n`,
|
|
0o755,
|
|
);
|
|
|
|
const result = runSmoke(['desktop', '--app', path.join(work, 'Stand-in.app'), '--port', String(port), '--timeout', '30']);
|
|
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
|
|
expect(result.stdout).toContain(`answers /health on 127.0.0.1:${port}`);
|
|
expect(result.stdout).toContain('Desktop smoke test passed');
|
|
|
|
const probe = net.connect(port, '127.0.0.1');
|
|
const connected = await new Promise<boolean>((resolve) => {
|
|
probe.once('connect', () => resolve(true));
|
|
probe.once('error', () => resolve(false));
|
|
});
|
|
probe.destroy();
|
|
expect(connected).toBe(false);
|
|
},
|
|
90_000,
|
|
);
|
|
|
|
it('rejects a desktop run without an app and unknown options', () => {
|
|
expect(runSmoke(['desktop']).stderr).toContain('desktop needs --app');
|
|
expect(runSmoke(['installer', '--fast', '1']).stderr).toContain('Unknown option: --fast');
|
|
expect(runSmoke(['publish']).status).toBe(1);
|
|
});
|
|
});
|