Skip to content

⚗️ basic reconciler tests#325

Merged
hayleigh-dot-dev merged 2 commits intomainfrom
reconciler-tests
May 21, 2025
Merged

⚗️ basic reconciler tests#325
hayleigh-dot-dev merged 2 commits intomainfrom
reconciler-tests

Conversation

@yoshi-monster
Copy link
Contributor

Most of the tests are diff tests that I "automatically" converted.

happy-dom.ffi.mjs is the compiled output of running npm run build in the happy-dom directory. It's a 1.7mb bundle. I didn't minify it because I think it makes testing easier.


export const document = () => globalThis?.document;

export const document = /* @__PURE__ */ globalThis?.document;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this a function now?

Copy link
Contributor Author

@yoshi-monster yoshi-monster May 19, 2025

Choose a reason for hiding this comment

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

previously this value was captured when the module graph was loaded - which is before any (non-top-level) code has had a chance to execute.

This means that in the test environment, where by default we do not have a global window object, our own document was always undefined. We also want to reset the document in between tests, so that's another reason why we can't have a stable reference here.

Initially I pulled out this constant as a server runtime size optimisation, since it avoids repeating the string document all over the bundle

mount(reconciler, prev)
push(reconciler, diff.diff(events.new(), prev, next).patch)

should.equal(get_html(), element.to_string(next))
Copy link
Collaborator

Choose a reason for hiding this comment

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

would it be possible to get the virtualised domain instead of this, im not so comfortable comparing strings and hoping for the best.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I think we can also call virtualise again. I did the string because I felt like it was more focused, but it already relies on some details for it to pass currently (i.e. attribute order)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok so we can't just use == because of fragments, and keys, and mappers --- these are all either completely or partially missing from the vdom we can recover using virtualise. I added a custom comparison function that handles these cases, but it's a tiny bit complicated itself.

@hayleigh-dot-dev hayleigh-dot-dev merged commit 1a78350 into main May 21, 2025
1 check passed
@yoshi-monster yoshi-monster deleted the reconciler-tests branch May 24, 2025 14:11
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.

2 participants