test(perf): add production renderer benchmark build

This commit is contained in:
4gray committed 2026-07-26 22:37:52 +02:00
1 parent 08b868d6c1
commit 28ed38906d
5 files changed
+245 -1

No files matched your search

@@ -0,0 +1,173 @@
/* eslint-disable playwright/expect-expect -- These are Node assertion-based configuration contract tests. */
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import test from 'node:test';
import { join } from 'node:path';
interface TargetConfiguration {
configurations?: Record<string, Record<string, unknown>>;
dependsOn?: unknown;
executor?: unknown;
options?: Record<string, unknown>;
}
interface ProjectConfiguration {
targets: Record<string, TargetConfiguration>;
}
const workspaceRoot = fileURLToPath(new URL('../../../../', import.meta.url));
function readProject(relativePath: string): ProjectConfiguration {
return JSON.parse(
readFileSync(join(workspaceRoot, relativePath), 'utf8')
) as ProjectConfiguration;
}
const e2eProject = readProject('apps/electron-backend-e2e/project.json');
const electronProject = readProject('apps/electron-backend/project.json');
const remoteControlProject = readProject(
'apps/remote-control-web/project.json'
);
const webProject = readProject('apps/web/project.json');
test('the performance harness target runs only Node performance specs', () => {
const target = e2eProject.targets['test-performance-harness'];
assert.ok(
target,
'electron-backend-e2e must define test-performance-harness'
);
assert.equal(target.executor, 'nx:run-commands');
assert.equal(target.options?.['cwd'], 'apps/electron-backend-e2e');
assert.equal(
target.options?.['command'],
'pnpm exec tsx --test src/performance/*.spec.ts'
);
});
test('the web performance build keeps production renderer behavior with profiling source maps', () => {
const build = webProject.targets['build'];
const production = build.configurations?.['production'];
const performance = build.configurations?.['electron-performance'];
assert.ok(production, 'web:build must define production');
assert.ok(performance, 'web:build must define electron-performance');
assert.equal(performance['baseHref'], './');
assert.equal(performance['serviceWorker'], false);
assert.deepEqual(performance['optimization'], production['optimization']);
assert.equal(performance['outputHashing'], production['outputHashing']);
assert.deepEqual(
performance['fileReplacements'],
production['fileReplacements']
);
assert.equal(performance['sourceMap'], true);
});
test('the remote-control performance build keeps optimized hashed output with profiling source maps', () => {
const build = remoteControlProject.targets['build'];
const production = build.configurations?.['production'];
const performance = build.configurations?.['electron-performance'];
assert.ok(production, 'remote-control-web:build must define production');
assert.ok(
performance,
'remote-control-web:build must define electron-performance'
);
assert.equal(performance['optimization'], true);
assert.equal(performance['outputHashing'], production['outputHashing']);
assert.equal(performance['sourceMap'], true);
});
test('the Electron performance build keeps production main-process behavior with profiling source maps', () => {
const build = electronProject.targets['build'];
const production = build.configurations?.['production'];
const performance = build.configurations?.['electron-performance'];
assert.ok(production, 'electron-backend:build must define production');
assert.ok(
performance,
'electron-backend:build must define electron-performance'
);
assert.equal(performance['optimization'], production['optimization']);
assert.equal(performance['inspect'], production['inspect']);
assert.deepEqual(
performance['fileReplacements'],
production['fileReplacements']
);
assert.equal(performance['sourceMap'], true);
});
test('the regular Electron build keeps its existing renderer dependency contract', () => {
const build = electronProject.targets['build'];
const dependencies = build.dependsOn as Array<
Record<string, unknown> | string
>;
const rendererBuild = dependencies.find(
(dependency): dependency is Record<string, unknown> =>
typeof dependency === 'object' &&
dependency !== null &&
dependency['target'] === 'build'
);
assert.deepEqual(rendererBuild, {
projects: ['web', 'remote-control-web'],
target: 'build',
});
});
test('the web performance wrapper selects the profiling configuration', () => {
const target = webProject.targets['build-performance'];
assert.ok(target, 'web must define build-performance');
assert.equal(target.executor, 'nx:run-commands');
assert.equal(
target.options?.['command'],
'pnpm nx run web:build:electron-performance'
);
});
test('the remote-control performance wrapper selects the profiling configuration', () => {
const target = remoteControlProject.targets['build-performance'];
assert.ok(target, 'remote-control-web must define build-performance');
assert.equal(target.executor, 'nx:run-commands');
assert.equal(
target.options?.['command'],
'pnpm nx run remote-control-web:build:electron-performance'
);
});
test('the Electron performance wrapper owns build dependencies before its profiled build', () => {
const target = electronProject.targets['build-performance'];
assert.ok(target, 'electron-backend must define build-performance');
assert.equal(target.executor, 'nx:run-commands');
assert.deepEqual(target.dependsOn, [
'electron-backend:build-worker',
'electron-backend:build-embedded-mpv',
{
projects: ['web', 'remote-control-web'],
target: 'build-performance',
},
]);
assert.equal(
target.options?.['command'],
'pnpm nx run electron-backend:build:electron-performance --excludeTaskDependencies'
);
});
test('the cancellation benchmark keeps its existing E2E build dependency', () => {
const target = e2eProject.targets['benchmark-m3u-refresh-cancellation'];
assert.deepEqual(target.dependsOn, ['electron-backend:build-e2e']);
});
test('the cancellation benchmark command is pinned to its Playwright test file', () => {
const target = e2eProject.targets['benchmark-m3u-refresh-cancellation'];
assert.equal(
target.options?.['command'],
'pnpm exec playwright test --config=playwright.performance.config.ts src/m3u-refresh-cancellation.performance.ts'
);
});