import { readFileSync, createReadStream, readdirSync } from 'node:fs'; import Benchmark from 'benchmark'; import { loadTreeConstructionTestData } from 'parse5-test-utils/dist/generate-parsing-tests.js'; import { loadSAXParserTestData } from 'parse5-test-utils/dist/load-sax-parser-test-data.js'; import { treeAdapters, WritableStreamStub, finished } from 'parse5-test-utils/dist/common.js'; import * as parse5 from '../../packages/parse5/dist/index.js'; import { ParserStream as parse5Stream } from '../../packages/parse5-parser-stream/dist/index.js'; import * as parse5Upstream from 'parse5'; const hugePagePath = new URL('../../test/data/huge-page/huge-page.html', import.meta.url); const treeConstructionPath = new URL('../../test/data/html5lib-tests/tree-construction', import.meta.url); const saxPath = new URL('../../test/data/sax/', import.meta.url); //HACK: https://github.com/bestiejs/benchmark.js/issues/51 /* global workingCopy, WorkingCopyParserStream, upstreamParser, hugePage, microTests, runMicro, runPages, files */ global.workingCopy = parse5; global.WorkingCopyParserStream = parse5Stream; global.upstreamParser = parse5Upstream; // Huge page data global.hugePage = readFileSync(hugePagePath).toString(); // Micro data global.microTests = loadTreeConstructionTestData(treeConstructionPath, treeAdapters.default) .filter( (test) => //NOTE: this test caused a stack overflow in parse5 v1.x test.input !== '