This commit is contained in:
√(noham)²
2026-06-19 15:48:32 +02:00
parent 58c210ec45
commit 13c9bcbcd2
8 changed files with 325 additions and 321 deletions

View File

@@ -1,70 +1,70 @@
import { execSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import { execSync } from 'node:child_process'
import fs from 'node:fs'
import path from 'node:path'
const TEST_DIR = path.dirname(new URL(import.meta.url).pathname);
const TEST_FILE = path.join(TEST_DIR, "test.txt");
const OUTPUT_DIR = "output/test";
const TEST_DIR = path.dirname(new URL(import.meta.url).pathname)
const TEST_FILE = path.join(TEST_DIR, 'test.txt')
const OUTPUT_DIR = 'output/test'
const TESTS = [
{ label: "default (no theme/css)", args: "" },
{ label: "dark theme", args: "--theme dark" },
{ label: "sepia theme", args: "--theme sepia" },
{ label: "custom CSS", args: "--css config/rules.css" },
{ label: 'default (no theme/css)', args: '' },
{ label: 'dark theme', args: '--theme dark' },
{ label: 'sepia theme', args: '--theme sepia' },
{ label: 'custom CSS', args: '--css config/rules.css' },
{
label: "dark theme + custom CSS",
args: "--theme dark --css config/rules.css",
},
];
label: 'dark theme + custom CSS',
args: '--theme dark --css config/rules.css'
}
]
if (!fs.existsSync(TEST_FILE)) {
console.error(`Test file not found: ${TEST_FILE}`);
process.exit(1);
console.error(`Test file not found: ${TEST_FILE}`)
process.exit(1)
}
const urls = fs
.readFileSync(TEST_FILE, "utf-8")
.split("\n")
.readFileSync(TEST_FILE, 'utf-8')
.split('\n')
.map((l) => l.trim())
.filter((l) => l && !l.startsWith("#"));
.filter((l) => l && !l.startsWith('#'))
if (urls.length === 0) {
console.error("No URLs found in test.txt");
process.exit(1);
console.error('No URLs found in test.txt')
process.exit(1)
}
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
fs.mkdirSync(OUTPUT_DIR, { recursive: true })
let passed = 0;
let failed = 0;
let passed = 0
let failed = 0
console.log(
`Running ${TESTS.length} test scenario(s) across ${urls.length} URL(s)...\n`,
);
`Running ${TESTS.length} test scenario(s) across ${urls.length} URL(s)...\n`
)
for (const url of urls) {
for (const { label, args } of TESTS) {
const slug = label.replace(/[^a-z0-9]+/gi, "-").replace(/(^-|-$)/g, "");
const outputPath = path.join(OUTPUT_DIR, `${slug}.pdf`);
const testName = `[${label}] ${url}`;
console.log(`\n=== ${testName} ===`);
const slug = label.replace(/[^a-z0-9]+/gi, '-').replace(/(^-|-$)/g, '')
const outputPath = path.join(OUTPUT_DIR, `${slug}.pdf`)
const testName = `[${label}] ${url}`
console.log(`\n=== ${testName} ===`)
try {
execSync(`node src/index.js "${url}" ${args} --output "${outputPath}"`, {
stdio: "inherit",
timeout: 120000,
});
console.log(` PASS: ${testName}`);
passed++;
stdio: 'inherit',
timeout: 120000
})
console.log(` PASS: ${testName}`)
passed++
} catch (err) {
console.error(` FAIL: ${testName}`);
failed++;
console.error(` FAIL: ${testName}`)
failed++
}
}
}
console.log(`\n${"=".repeat(50)}`);
console.log(`\n${'='.repeat(50)}`)
console.log(
`Results: ${passed} passed, ${failed} failed out of ${passed + failed} tests`,
);
process.exit(failed > 0 ? 1 : 0);
`Results: ${passed} passed, ${failed} failed out of ${passed + failed} tests`
)
process.exit(failed > 0 ? 1 : 0)