37 lines
2.1 KiB
JavaScript
37 lines
2.1 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { Worker } from 'node:worker_threads';
|
|
import { htmlTimeoutFixture } from '../importers/html-timeout-fixture.mjs';
|
|
|
|
// Run after npm run build. No HTTP, persistence or real report data involved.
|
|
const text = htmlTimeoutFixture();
|
|
const bytes = new TextEncoder().encode(text);
|
|
const start = performance.now();
|
|
const worker = new Worker(new URL('../../dist-server/import-worker.mjs', import.meta.url), {
|
|
workerData: { source: { metadata: { name: 'ad_hc_synthetic.local.html', sizeBytes: bytes.length, lastModified: 0 }, bytes } },
|
|
resourceLimits: { maxOldGenerationSizeMb: 512, maxYoungGenerationSizeMb: 64, stackSizeMb: 8 }
|
|
});
|
|
try {
|
|
const result = await new Promise((resolve, reject) => {
|
|
const timer = setTimeout(() => reject(new Error('Built HTML parser exceeded the unchanged 30-second budget.')), 30_000);
|
|
const finish = action => value => { clearTimeout(timer); action(value); };
|
|
worker.once('message', finish(resolve));
|
|
worker.once('error', finish(reject));
|
|
worker.once('exit', finish(code => reject(new Error(`Worker exited without a result (${code}).`))));
|
|
});
|
|
assert.equal(result.ok, true, 'Built worker rejected the synthetic report.');
|
|
const dataset = result.dataset;
|
|
assert.equal(dataset.profileId, 'pingcastle');
|
|
assert.equal(dataset.rawText, text);
|
|
assert.equal(dataset.extraction.candidates.length, 40);
|
|
assert.equal(dataset.intermediate.tables.length, 40);
|
|
assert.deepEqual(dataset.extraction.diagnostics, []);
|
|
dataset.extraction.candidates.forEach((candidate, index) => {
|
|
assert.equal(candidate.fields.find(field => field.key === 'risk-id').originalValue, `S-${index}`);
|
|
const sections = candidate.fields.find(field => field.key === 'linked-section').originalValue.sections;
|
|
assert.equal(sections.length, 1);
|
|
assert.equal(sections[0].sectionId, `detail-${index}`);
|
|
assert.deepEqual(sections[0].rows, [[`host-${index}`]]);
|
|
});
|
|
console.log(JSON.stringify({ status: 'complete', bytes: bytes.length, rules: 40, linkedTables: 40, milliseconds: Math.round(performance.now() - start) }));
|
|
} finally { await worker.terminate(); }
|