salesforce / lwc-test

LWC plugins and utilities for testing
MIT License
43 stars 29 forks source link

fix: fix excessive __lwc_scope_token__ replacement #241

Closed nolanlawson closed 3 months ago

nolanlawson commented 3 months ago

BREAKING CHANGE: Snapshots may change.

For reasons I don't understand yet, it's possible for us to end up with a serialized DOM like this:

__lwc_scope_token__[__lwc_scope_token__p__lwc_scope_token__a__lwc_scope_token__r
__lwc_scope_token__t__lwc_scope_token__=__lwc_scope_token__'__lwc_scope_token__
b__lwc_scope_token__u__lwc_scope_token__t__lwc_scope_token__t__lwc_scope_token__
o__lwc_scope_token__n[...]

The proximate cause is this code:

https://github.com/salesforce/lwc-test/blob/c78dca8b39c691c8eb9af1b840e84f076449e55b/packages/%40lwc/jest-serializer/src/clean-style-element.js#L11

The problem is that the regex ends up being (?:) because there are no known scope tokens.

I can't figure out how it's possible for us not to have any known scope tokens, but in any case, it's much more catastraphic to over-replace than to just skip the replacement.

So even in the absence of a reproducible test case, I propose we just skip the replacement for now if there are no known scope tokens.