Skip to content

Conversation

@seanmcguire12
Copy link
Member

@seanmcguire12 seanmcguire12 commented Dec 19, 2025

why

  • to add tests for xpath utilities and tree formatting utilities

what changed

  • added tests/snapshot-xpath-utils.test.ts to cover all pure xpath helpers (prefixXPath(), normalizeXPath(), relativizeXPath(), buildChildXPathSegments(), joinXPath())
  • added tests/snapshot-tree-format-utils.test.ts which tests formatting helpers (formatTreeLine(), injectSubtrees(), indentBlock(), diffCombinedTrees(), cleanText(), normaliseSpaces())

test plan

  • this is it

Summary by cubic

Add unit tests for XPath utilities and tree formatting utilities to validate edge cases and prevent regressions. Tests cover path prefixing/normalization/joining, relative path derivation, positional selector building, subtree injection, diffing, indentation, and whitespace cleanup.

Written for commit df6ee84. Summary will update automatically on new commits.

@changeset-bot
Copy link

changeset-bot bot commented Dec 19, 2025

⚠️ No Changeset found

Latest commit: df6ee84

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

});
});

describe("diffCombinedTrees", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-crucial but could add a test for checking that the trimming works (i.e. if prevtree has different indentation vs nextree) since it's got a bunch of logic for that?

});
});

describe("injectSubtrees", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add a test for what happens when the same id appears twice, and if no ids found in the map I think?


describe("prefixXPath", () => {
it("treats root prefixes as no-op", () => {
expect(prefixXPath("/", "/div[1]")).toBe("/div[1]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just fyi, you can use http://vitest.dev/api/#test-for this syntax in the future if you like it - is nice for parameterized testing - the syntax you currently have isn't too long so it doesn't matter, but it can be nice when there's more setup / LOC for each expect

@seanmcguire12 seanmcguire12 merged commit ddd7464 into main Dec 19, 2025
16 checks passed
@seanmcguire12 seanmcguire12 changed the title [chore]: add unit tests for xpath utils & tree format utils [test]: add unit tests for xpath utils & tree format utils Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants