mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-28 04:46:07 -08:00
- validate reference files (absolute regular file, size cap) before reading - redact stream tokens and truncate tool output in failure messages - keep title and lang when re-adding the synced track - ignore an external audio track's ff-index when mapping the video's audio - report discarded stale auto results, bound manual offsets, yield between alignments - update stale subsync docs, fix markdown formatting, discover subtitle tests by lane
100 lines
2.8 KiB
TypeScript
100 lines
2.8 KiB
TypeScript
import { readdirSync } from 'node:fs';
|
|
import { relative, resolve } from 'node:path';
|
|
|
|
export type TestLane = {
|
|
roots: string[];
|
|
include: string[];
|
|
exclude?: string[];
|
|
extraFiles?: string[];
|
|
};
|
|
|
|
// Single source of truth for test-lane membership. Consumed by
|
|
// scripts/run-test-lane.mjs (plain runs) and scripts/run-coverage-lane.ts
|
|
// (per-file coverage shards). Lanes discover files by directory so new test
|
|
// files join their lane automatically.
|
|
export const testLanes: Record<string, TestLane> = {
|
|
'bun-src-full': {
|
|
roots: ['src'],
|
|
include: ['.test.ts', '.type-test.ts'],
|
|
},
|
|
config: {
|
|
roots: ['src/config'],
|
|
include: ['.test.ts'],
|
|
extraFiles: ['src/generate-config-example.test.ts', 'src/verify-config-example.test.ts'],
|
|
},
|
|
launcher: {
|
|
roots: ['launcher'],
|
|
include: ['.test.ts'],
|
|
},
|
|
'bun-launcher-unit': {
|
|
roots: ['launcher'],
|
|
include: ['.test.ts'],
|
|
exclude: ['launcher/smoke.e2e.test.ts'],
|
|
},
|
|
subtitle: {
|
|
roots: ['src/subsync'],
|
|
include: ['.test.ts'],
|
|
extraFiles: ['src/core/services/subsync.test.ts', 'src/renderer/modals/subsync.test.ts'],
|
|
},
|
|
scripts: {
|
|
roots: ['scripts'],
|
|
include: ['.test.ts'],
|
|
},
|
|
// Boots the built app, mpv, and a fake AnkiConnect on an offscreen display.
|
|
// Slow and dependent on mpv/ffmpeg/Xvfb, so it stays out of test:fast.
|
|
e2e: {
|
|
roots: ['e2e'],
|
|
include: ['.e2e.test.ts'],
|
|
},
|
|
stats: {
|
|
roots: ['stats/src'],
|
|
include: ['.test.ts', '.test.tsx'],
|
|
},
|
|
};
|
|
|
|
function collectFiles(
|
|
repoRoot: string,
|
|
rootDir: string,
|
|
includeSuffixes: string[],
|
|
excludeSet: Set<string>,
|
|
): string[] {
|
|
const out: string[] = [];
|
|
const visit = (currentDir: string): void => {
|
|
for (const entry of readdirSync(currentDir, { withFileTypes: true })) {
|
|
const fullPath = resolve(currentDir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
visit(fullPath);
|
|
continue;
|
|
}
|
|
const relPath = relative(repoRoot, fullPath).replaceAll('\\', '/');
|
|
if (excludeSet.has(relPath)) continue;
|
|
if (includeSuffixes.some((suffix) => relPath.endsWith(suffix))) {
|
|
out.push(relPath);
|
|
}
|
|
}
|
|
};
|
|
|
|
visit(resolve(repoRoot, rootDir));
|
|
out.sort();
|
|
return out;
|
|
}
|
|
|
|
export function collectLaneFiles(repoRoot: string, laneName: string): string[] {
|
|
const lane = testLanes[laneName];
|
|
if (!lane) {
|
|
throw new Error(`Unknown test lane: ${laneName}`);
|
|
}
|
|
const excludeSet = new Set(lane.exclude ?? []);
|
|
const files = lane.roots.flatMap((rootDir) =>
|
|
collectFiles(repoRoot, rootDir, lane.include, excludeSet),
|
|
);
|
|
for (const extra of lane.extraFiles ?? []) {
|
|
if (!files.includes(extra)) files.push(extra);
|
|
}
|
|
files.sort();
|
|
if (files.length === 0) {
|
|
throw new Error(`No test files found for lane: ${laneName}`);
|
|
}
|
|
return files;
|
|
}
|