• Stars
    star
    154
  • Rank 234,039 (Top 5 %)
  • Language
    JavaScript
  • Created almost 10 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A JS Library that compares two DOM Nodes and outputs what changed between the two.

DOM Comparator

DOM Comparator is a library that, simply put, compares two strings of DOM nodes (which are called stringA and stringB), and returns an output containing the minimal number of steps that must be taken (like attribute changes, style changes, text changes and DOM manimpulation) to convert stringA into stringB.

The output returned by DOM Comparator is an array of VWO.Operation objects, which can also be expressed as jQuery code. Here's a simple example:

var stringA = '<ul><li class="active">list item 1</li><li>list item 2</li></ul>';
var stringB = '<ul><li>list item 1</li><li>list item 2</li></ul>';

// Compare the two strings
var result = VWO.DOMComparator.create({
	stringA: stringA,
	stringB: stringB
});

// Expect an array of VWO.Operation objects to be returned.
expect(result).toEqual(jasmine.any(Array));
expect(result[0]).toEqual(jasmine.any(VWO.Operation));

// Expect the first operation to be a 'removeAttr' operation.
expect(result[0].name).toEqual('removeAttr');

// The operation is on an element identified by the following selector path
expect(result[0].selectorPath).toEqual('UL:first-child > LI:first-child');

// With below content
expect(result[0].content).toEqual({class: 'active'});

Setting Up

Installation

  • To install all the dependencies run npm install.
  • Then run bower install for jasmine, jquery and underscore library dependencies.
  • Install grunt globally, which is a Javascript Task Runner npm install -g grunt-cli.

Downloads

Live Demo

A live demo can be found here: http://engineering.wingify.com/dom-comparator/live-demo.html

Running Tests

  • For testing, we use Jasmine.
  • Tests are written in the test/unit folder. Each file in the src directory have different test cases files associataed with them in the test/unit directory. The majority of the test cases that test the library as a black box are in dom-comparator.spec.js.
  • To run tests, run grunt; testem server; (from the root directory of the repository)
  • To see the final outputs open http://localhost:7357/ in the browser, open the JavaScript console and look for the final_results array.

Cases which don't work

  • If there are multiple occurrences of a node in the DOM. For example:

nodeA:

<div style="display: block;">
	<ul class="navigation vwo_1405423029796" style="cursor: auto; display: block;">
	</ul>
	<div class="clr">ORIGINAL TEXT</div>
</div>

nodeB:

<div class="clr">ORIGINAL TEXT</div>
<div style="display: block;">
	<ul class="navigation vwo_1405423029796" style="cursor: auto; display: INLINE;">
	</ul>
	<div class="clr">ORIGINAL TEXT</div>
</div>

Here, since there are 2 occurrences of <div class="clr">ORIGINAL TEXT</div> in nodeB, the exact match of it cannot be found in nodeA, due to which the resulted output is not as expected.

  • When the wrapping of the original node is changed. For example:

nodeA:

<div style="display: block;">
	<div class="clr">ORIGINAL TEXT</div>
</div>

nodeB:

<div>
	<div style="display: block;">
		<div class="clr">ORIGINAL TEXT</div>
	</div>
</div>

Here, since the wrapping of nodeB is changed (wrapped by <div> ... </div>), the whole content in nodeB would be considered as inserted (because matching heirarchy is top to bottom).

Documentation

The general usage documentation can be found on http://engineering.wingify.com/dom-comparator/

Authors

License

The MIT License

Copyright (c) 2014-16 Wingify Software Pvt. Ltd.

More Repositories

1

across-tabs

Easy communication between cross-origin browser tabs. Simplified "CORS"ing!
JavaScript
1,645
star
2

please.js

A simple PostMessage communication library.
JavaScript
311
star
3

lua-resty-rabbitmqstomp

Opinionated Lua RabbitMQ client library for the ngx_lua apps based on the cosocket API
Lua
192
star
4

superelasticsearch

An extended version of the official Elasticsearch Python client.
Python
64
star
5

agentredrabbit

Transport agent that moves data from Redis to RabbitMQ
Python
61
star
6

angularjs-tips

Tips and tricks for doing things in AngularJS framework.
48
star
7

heybot

🤖 A sleek command based Skype chat bot for your team
JavaScript
25
star
8

vwo-node-sdk

VWO Node SDK for server-side testing
JavaScript
22
star
9

q-directives

A faster directive system for Angular.js
JavaScript
19
star
10

vnc

VNC server application for iOS Simulators running on mac machines
C
16
star
11

choti-moti-baaten

Small statements with huge amount of wisdom, knowledge and humour.
SCSS
14
star
12

vwo-python-sdk

VWO Python SDK for server-side A/B Testing
Python
14
star
13

lua-resty-pubsub

Lua Pubsub client driver for the ngx_lua based on the cosocket API
Lua
13
star
14

rest-api-testing-framework

RestAssured based API testing framework
Java
12
star
15

vwo-php-sdk

VWO PHP SDK for server-side A/B Testing
PHP
11
star
16

wingify.github.io

Engineering blog @ Wingify
JavaScript
11
star
17

reconner

A script for automating the reconnaissance process which is the initial phase of a pentesting activity
Shell
10
star
18

vwo-java-sdk

VWO Java SDK for server-side A/B Testing
Java
9
star
19

vwo-android

VWO Android SDK
Java
9
star
20

kroomsa

A search engine for the curious
Python
8
star
21

vwo-react-native

React Native wrapper for VWO A/B testing
Java
7
star
22

cookie-jar.js

A fast and compact micro-cookie manager.
JavaScript
7
star
23

angular-time-picker

🕗 Angular directive for time picker
JavaScript
7
star
24

bayesian-duration-calculator

https://engineering.wingify.com/posts/maths-behind-bayesian-duration-calculator/
JavaScript
6
star
25

vwo-dotnet-sdk

VWO .NET SDK for server-side A/B Testing
C#
5
star
26

vwo-python-sdk-example

Provides a basic demo of how server-side works with VWO Python SDK
Python
4
star
27

marque

Tag Versioning Helper
JavaScript
4
star
28

vwo-ios-sdk

VWO iOS SDK
Objective-C
4
star
29

Oldmonk

Assorted scala utilities - deduplicators, free algebras,
Scala
3
star
30

vwo-dotnet-sdk-example

Provides a basic demo of how server-side works with VWO .NET SDK
C#
3
star
31

bumblebee

Experimental Slack bot for you to interact with your VWO account
Python
3
star
32

vwo-node-sdk-example

Provides a basic demo of how server-side works with VWO NodeJs SDK
JavaScript
3
star
33

vwo-go-sdk

VWO Go SDK for server-side testing
Go
2
star
34

vwo-ruby-sdk

VWO Ruby SDK for server-side A/B Testing
Ruby
2
star
35

vwo-cordova-plugin

VWO Cordova Plugin
Java
2
star
36

vwo-php-sdk-example

Provides a basic demo of how server-side works with VWO PHP SDK
PHP
2
star
37

vwo-react-native-demo

VWO React native app
JavaScript
2
star
38

vwo-java-sdk-example

Provides a basic demo of how server-side works with VWO Java SDK
HTML
2
star
39

kafka-streams-stateful-example

Example to demonstrate aggregation in Kafka Streams
Java
2
star
40

vwo-flutter-sdk

VWO Flutter Wrapper
Dart
2
star
41

vwo-mobile-android

2
star
42

nextjs-vwo-js-sdk

Integrating VWO JavaScript SDK in Next.js
TypeScript
1
star
43

vwo-ruby-sdk-ror-example

Provides a basic demo of ROR app how server-side works with VWO Ruby SDK
Ruby
1
star
44

vwo-tvos-sdk

VWO A/B Testing SDK for tvOS
Objective-C
1
star
45

vwo-ruby-sdk-example

Provides a basic demo of how server-side works with VWO Ruby SDK
HTML
1
star
46

json-minify

1
star
47

vwo-android-snapshot

Snapshot repository for Android VWO SDK.
1
star
48

crypto-js

1
star
49

vwo-prestashop-plugin

PHP
1
star
50

ui-router

angular ui router
JavaScript
1
star
51

vwo-go-sdk-example

Provides a demo of how server-side works with VWO Go SDK
HTML
1
star