import { expect, it } from "vitest";
import { htmlArtifactReferences } from "./htmlArtifactReferences.js";
it.each([
['', []],
['', []],
[``, []],
["", ["actual.js"]],
['', ["actual.js"]],
['', ["actual.js"]],
["", ["actual.js"]],
['', ["actual.js"]],
['', ["actual.js"]],
['', []],
['', ["actual.js"]],
['', []],
['', []],
['', []],
[``, []],
[
'',
[],
],
['', []],
[
'',
["actual.js"],
],
// The existing extraction contract does not classify script MIME types.
['', ["actual.js"]],
])("extracts document references from %s", (text, expected) => {
expect(
htmlArtifactReferences(text).scripts.map(({ scriptPath }) => scriptPath),
).toEqual(expected);
});
it("retains exact opening-tag offsets rather than the script body", () => {
const opening = '`;
expect(htmlArtifactReferences(text)).toEqual({
baseHref: null,
scripts: [
{
scriptPath: "actual.js",
startOffset: prefix.length,
endOffset: prefix.length + opening.length,
},
],
});
});
it.each([
['', "actual/"],
['', "actual/"],
['', ""],
['', "actual/"],
['', "actual/"],
])("selects the first real base href from %s", (text, expected) => {
expect(htmlArtifactReferences(text).baseHref).toBe(expected);
});
it("traverses deep valid document content without recursive stack growth", () => {
const depth = 12_000;
const text = `${"
".repeat(depth)}${"
".repeat(depth)}`;
expect(
htmlArtifactReferences(text).scripts.map(({ scriptPath }) => scriptPath),
).toEqual(["actual.js"]);
});