Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node type undefined comparison is not implemented #34

Closed
lsotov opened this issue Sep 25, 2018 · 9 comments
Closed

Node type undefined comparison is not implemented #34

lsotov opened this issue Sep 25, 2018 · 9 comments

Comments

@lsotov
Copy link

lsotov commented Sep 25, 2018

Hi,
I'm getting the following error:
Node type undefined comparison is not implemented

Error: Node type undefined comparison is not implemented
    at Error (native)
    at Comparator.compareNode (node_modules/dom-compare/lib/compare.js:130:22)

This is the file I'm trying to compare

<?xml version="1.0"?>

<conf>
  <domain>
      <name>name</name>
      <custom>value</custom>
      <custom>value</custom>
      <custom>value</custom>
  </domain>
</conf>

And using the defaults as in the home page

var options = {
       stripSpaces: true,
       compareComments: true
};

Thanks in advanced

@Olegas
Copy link
Owner

Olegas commented Sep 25, 2018

What is the other file you are compare against?

@lsotov
Copy link
Author

lsotov commented Sep 25, 2018

It's basically the same file, as I'm just starting to test this tool

@Olegas
Copy link
Owner

Olegas commented Sep 27, 2018

@lsotov I've created a two files like the one above and used cli version of dom-compare to compare them - no errors. Can you please show the code and attach a test files?

@tiagorvmartins
Copy link

tiagorvmartins commented Feb 7, 2019

Hey @Olegas , I am getting the same error, here is my snippet code in javascript:

var fs = require('fs');

var compare = require('dom-compare').compare,
    reporter = require('dom-compare').GroupingReporter,
    expected = fs.readFileSync("xml_file_2.xml", "utf-8"),
    actual = fs.readFileSync("xml_file_1.xml", "utf-8"),
    result, diff, groupedDiff;

console.log(expected);
console.log(actual);

// compare to DOM trees, get a result object
result = compare(expected, actual);

And here is my xml_file_2.xml:

<document>
    <!-- comment -->
    <element attribute="10" attributeX="100">
        <text>  text content </text>
        <inner>
            <node />
        </inner>
    </element>
    <![CDATA[  cdata node]]>
</document>

And here is my xml_file_1.xml:

<document>
    <element attribute="100">
        <text>text content</text>
        <inner />
        <inner2 />
    </element>
    <![CDATA[cdata node  ]]>
</document>

What I am doing wrong? Thanks!

Here is the error in console:

throw Error("Node type " + left.nodeType + " comparison is not implemented");
               ^
Error: Node type undefined comparison is not implemented
    at Comparator.compareNode (/Users/tiagorvmartins/Documents/get_file_prototype/node_modules/dom-compare/lib/compare.js:130:22)

@tiagorvmartins
Copy link

After using the following of importing the xml files started working:

dom1 = domparser.parseFromString(fs.readFileSync("expected.xml", 'utf-8'), "text/xml");
dom2 = domparser.parseFromString(fs.readFileSync("actual.xml", 'utf-8'), "text/xml");

Thanks anyway!

@tiagorvmartins
Copy link

Although it doesn't return all the differences :/

For the following examples:

actual.xml

<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>I got changed</body>
</note>

expected.xml

<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
  <age>seventeen</age>
  <address>street of freedom</address>
  <anotherelement>
    <message>Hiyo</message>
  </anotherelement>
</note>

It returns only the following differences:

Differences:  [ { node: '/note/body',
    message:
     'Expected text \'Don\'t forget me this weekend!\' instead of \'I got changed\'' },
  { node: '/note', message: 'Element \'age\' is missed' } ]

I was expecting address and anotherelement as well to be included on the differences :/

@Olegas
Copy link
Owner

Olegas commented Feb 7, 2019

@tiagorvmartins Regarding first issue with undefined node type - it is required to parse document from string somehow. It is incorrect to compare strings. Library is designed to compare documents. Anyway, it must be handled correctly, so, I'll add some error checking here.

@Olegas
Copy link
Owner

Olegas commented Feb 7, 2019

@tiagorvmartins for the second case please see #36

@Olegas
Copy link
Owner

Olegas commented Feb 7, 2019

Fixed and published as 0.3.3

@Olegas Olegas closed this as completed Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants