tjw-lint / jest-serializer-vue-tjw

Jest Serializer for Vue components
MIT License
33 stars 7 forks source link

Support "diffable html" #85

Open TheJaredWilcurt opened 2 months ago

TheJaredWilcurt commented 2 months ago

There is a library called diffable-html:

It is essentially just some hard coded settings passed in to htmlparser2. We already use htmlparser2 in this library, so no need to pull in diffable-html. Instead, we can reference their hardcoded settings and create our own settings and allow some more user-friendly worded options for users to be able to customize their snapshots.

Example:

<!--v-if-->
<!--v-if-->
<!--v-if-->
<span class="x">(<a href="https://github.com" class="y" data-whatever="true">Text</a>)</span>
<i class="fa fa-question"></i>
<th></th>
<!--v-if-->
<span class="x">
  (
  <a
    href="https://github.com"
    class="y"
    data-whatever="true"
  >
    Text
  </a>
  )
</span>
<i class="fa fa-question">
</i>
<th>
</th>

I think some people would be willing to give up correctness for the convenience of having all markup on separate lines.

TheJaredWilcurt commented 2 months ago

It's like night and day, huge improvements: <date-picker-stub appendtobody="true" clearable="true" confirmtext="OK" dateformat="M/D/YYYY" defaultvalue="Sat Aug 10 2019 00:00:00 GMT-0400 (Eastern Daylight Time)" disabled="true" disabledcalendarchanger="[Function]" disableddate="[Function]" disabledtime="[Function]" editable="true" format="M/D/YYYY" getclasses="[Function]" hourstep="1" inputattr="[object Object]" lang="en" minutestep="1" placeholder popupstyle="[object Object]" prefixclass="mx" scrollduration="100" secondstep="1" shortcuts timetitleformat="YYYY-MM-DD" titleformat="YYYY-MM-DD" type="date" valuetype="date"></date-picker-stub>

<date-picker-stub
  appendtobody="true"
  clearable="true"
  confirmtext="OK"
  dateformat="M/D/YYYY"
  defaultvalue="Sat Aug 10 2019 00:00:00 GMT-0400 (Eastern Daylight Time)"
  disabled="true"
  disabledcalendarchanger="[Function]"
  disableddate="[Function]"
  disabledtime="[Function]"
  editable="true"
  format="M/D/YYYY"
  getclasses="[Function]"
  hourstep="1"
  inputattr="[object Object]"
  lang="en"
  minutestep="1"
  placeholder
  popupstyle="[object Object]"
  prefixclass="mx"
  scrollduration="100"
  secondstep="1"
  shortcuts
  timetitleformat="YYYY-MM-DD"
  titleformat="YYYY-MM-DD"
  type="date"
  valuetype="date"
>
</date-picker-stub>
TheJaredWilcurt commented 3 days ago

Ultimately ended up completely writing my own diffable formatter from scratch, as all the pre-made options lacked configurability.