How to Compare Two DOM Trees?


#1

This seems super simple, but does anyone have a library for comparing two DOM trees that works in CLI? I found a node one that I tried to use browserify on with no luck (but that might be my fault). node.equalTo() didn’t give me what I was looking for. It doesn’t sound hard to build from scratch, but it also feels like this is a solved problem. Can anyone give me a hand?


#2

If you are comparing equality you can use a recursive function over each nodes children and stick the details you want to compare into 2 separate arrays. When the recursion is complete you then just compare the two Arrays.

For a start you can see how I iterated dom trees in my addon (for a different purpose)

https://github.com/QuantumInformation/ember-cli-test-recorder/blob/master/app/components/test-recorder.js#L243


#3

At some point I might rate such a function to compare, unless someone has already done it :slight_smile: