fix(traversing): return prevAll/prevUntil results in reverse document order

EN
1mo ago
+40-11

Fixes #5676

When .prevAll() or .prevUntil() is called on more than one element, the results were only de-duplicated, not ordered. They ended up in neither document order nor reverse document order:

const $ = load('<ul><li id=a></li><li id=b></li><li id=c></li><li id=d></li></ul>');
$('#c, #d').prevAll();        // cheerio: b, a, c   jQuery: c, b, a
$('#c, #d').prevUntil('#a');  // cheerio: b, c      jQuery: c, b

For parents* and prev*, jQuery sorts the results of a multi-element selection and then reverses them ("in order beginning with the closest sibling"). Cheerio already does this for parents and parentsUntil. This PR applies the same post-processing to prevAll and prevUntil. Single-element calls are unaffected and skip the sort.

The existing prevUntil test "(function) : should reset the index for each starting element" asserted the old order (orange, carrot). It now expects carrot, orange, which is what jQuery returns for the same selection. The index-reset behaviour it covers is unchanged.

Tests: added ordering tests for prevAll (same parent and different parents) and prevUntil. They fail on main and pass with the change. I checked the outputs against jQuery 4.0.0 on jsdom. npm run test:vi passes (838 tests), as do npm run lint:ts and npm run lint:biome.