Skip to content
Merged
1 change: 1 addition & 0 deletions .github/workflows/nodejs-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
- 20
- 22
- 24
- 26
- "lts/*"

steps:
Expand Down
18 changes: 18 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default defineConfig([
{
rules: {
"n/no-unpublished-import": 0,
// Use the Number namespace required by the Biome configuration.
"unicorn/prefer-global-number-constants": 0,

"unicorn/filename-case": [
2,
Expand Down Expand Up @@ -54,4 +56,20 @@ export default defineConfig([
"n/no-unsupported-features/node-builtins": 0,
},
},
// Retain the conventional fixture directory while checking other names.
{
files: ["src/__fixtures__/**"],
rules: {
"unicorn/filename-case": [
"error",
{
cases: {
camelCase: true,
pascalCase: true,
},
checkDirectories: false,
},
],
},
},
]);
416 changes: 222 additions & 194 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
},
"devDependencies": {
"@biomejs/biome": "^2.5.15",
"@feedic/eslint-config": "^0.4.1",
"@feedic/eslint-config": "^0.5.0",
Comment thread
fb55 marked this conversation as resolved.
Resolved
"@types/node": "^26.6.4",
"eslint": "^10.12.0",
"eslint-config-biome": "^2.1.3",
Expand Down
37 changes: 8 additions & 29 deletions src/FeedHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,12 @@ import { parseFeed } from "./index.js";
const documents = new URL("__fixtures__/Documents/", import.meta.url);

describe("parseFeed", () => {
it("(rssFeed)", async () =>
expect(
parseFeed(
await fs.readFile(
new URL("RSS_Example.xml", documents),
"utf8",
),
),
).toMatchSnapshot());

it("(atomFeed)", async () =>
expect(
parseFeed(
await fs.readFile(
new URL("Atom_Example.xml", documents),
"utf8",
),
),
).toMatchSnapshot());

it("(rdfFeed)", async () =>
expect(
parseFeed(
await fs.readFile(
new URL("RDF_Example.xml", documents),
"utf8",
),
),
).toMatchSnapshot());
it.each([
["rssFeed", "RSS_Example.xml"],
["atomFeed", "Atom_Example.xml"],
["rdfFeed", "RDF_Example.xml"],
])("(%s)", async (_name, file) => {
const content = await fs.readFile(new URL(file, documents), "utf8");
expect(parseFeed(content)).toMatchSnapshot();
});
});
17 changes: 17 additions & 0 deletions src/Parser.events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ function runTest(input: string, options?: ParserOptions) {
}

describe("Events", () => {
it.each([
[Number.NaN, 0],
[0, Number.NaN],
[2, 1],
])("should reject invalid event indices %s, %s", (startIndex, endIndex) => {
const handler = helper.getEventCollector(() => {});
const parser = new Parser(handler);
parser.startIndex = startIndex;
parser.endIndex = endIndex;

expect(() => handler.ontext?.("test")).toThrow(
"Invalid start/end index",
);
});

it("simple", () => runTest("<h1 class=test>adsf</h1>"));

it("Template script tags", () =>
Expand Down Expand Up @@ -90,6 +105,7 @@ describe("Events", () => {
runTest("<img src=gif.com/123/><p>Hold the line."));

it("end slash: as part of attrib value of non-void element", () =>
// eslint-disable-next-line unicorn/prefer-https -- Match the original HTTP fixture exactly.
runTest("<a href=http://test.com/>Foo</a><p>Hold the line."));

it("Implicit close tags", () =>
Expand Down Expand Up @@ -137,6 +153,7 @@ describe("Events", () => {

it("entity in attribute", () =>
runTest(
// eslint-disable-next-line unicorn/prefer-https -- Match the original HTTP fixture exactly.
"<a href='http://example.com/p&#x61;#x61ge?param=value&param2&param3=&lt;val&; & &'>",
));

Expand Down
36 changes: 19 additions & 17 deletions src/Parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ describe("API", () => {
});

it("should update the position when a single tag is spread across multiple chunks", () => {
let called = false;
let isCalled = false;
const p = new Parser({
onopentag() {
called = true;
isCalled = true;
expect(p.startIndex).toBe(0);
expect(p.endIndex).toBe(12);
},
Expand All @@ -173,21 +173,21 @@ describe("API", () => {
p.write("<div ");
p.write("foo=bar>");

expect(called).toBe(true);
expect(isCalled).toBe(true);
});

it("should have the correct position for implied opening tags", () => {
let called = false;
let isCalled = false;
const p = new Parser({
onopentag() {
called = true;
isCalled = true;
expect(p.startIndex).toBe(0);
expect(p.endIndex).toBe(3);
},
});

p.write("</p>");
expect(called).toBe(true);
expect(isCalled).toBe(true);
});

it("should parse <__proto__> (#387)", () => {
Expand Down Expand Up @@ -253,17 +253,19 @@ describe("API", () => {
expect(tdClose).toBeLessThan(thOpen);
});

it.each([
"div",
"svg",
"a",
])("should do linear stack work for nested %s elements", (name) => {
const depth = 500;
const parser = new Parser({}, { xmlMode: name === "a" });
const input = `<${name}>`.repeat(depth) + `</${name}>`.repeat(depth);
const reads = countArrayReads(parser, "stack", () => parser.end(input));
expect(reads).toBeLessThan(depth * 10);
});
it.each(["div", "svg", "a"])(
"should do linear stack work for nested %s elements",
(name) => {
const depth = 500;
const parser = new Parser({}, { xmlMode: name === "a" });
const input =
`<${name}>`.repeat(depth) + `</${name}>`.repeat(depth);
const reads = countArrayReads(parser, "stack", () =>
parser.end(input),
);
expect(reads).toBeLessThan(depth * 10);
},
);

it("should do linear work on the foreign context stack", () => {
const depth = 500;
Expand Down
Loading
Loading