diff --git a/dummy.txt b/dummy.txt deleted file mode 100644 index d2e5808..0000000 --- a/dummy.txt +++ /dev/null @@ -1,2 +0,0 @@ -testing travis builds -2) second check diff --git a/package.json b/package.json index 3885046..140795d 100644 --- a/package.json +++ b/package.json @@ -39,5 +39,8 @@ "name": "Sai Teja", "email": "saitejas464@gmail.com" } - ] + ], + "standard": { + "globals": [ "describe", "it" ] + } } diff --git a/test/TestFiles/randomText.xml b/test/TestFiles/randomText.xml new file mode 100644 index 0000000..aaf776d --- /dev/null +++ b/test/TestFiles/randomText.xml @@ -0,0 +1,12 @@ + + + item + one one + two two + + item + onethree two + four three + fourfive + + diff --git a/test/test.js b/test/test.js index 986c9b8..6fdd084 100644 --- a/test/test.js +++ b/test/test.js @@ -80,5 +80,36 @@ describe('Tests', function () { }) xmlStream.pipe(parser) }) + + it('should properly parse a xml simple file in which nodes contain text values randomly.', function (done) { + var xmlStream = fs.createReadStream('./test/TestFiles/randomText.xml') + var parser = new ParserFactory(xmlStream, {resourcePath: '/items/item'}) + var expectedData = [ { '$': { 'id': '1', 'test': 'hello' }, '_': ' item one two', + 'subitem': [ { '$': { 'sub': 'TESTING SUB' }, '_': 'one' }, + { '$': { 'sub': '2' }, '_': 'two' } ] }, + { '$': { 'id': '2' }, '_': ' item one two three four', + 'subitem': [ { '_': 'three' }, { '_': 'four' }, { '_': 'five' } ] } + ] + var actualData = [] + var dataEventCount = 0 + + parser.on('data', function (data) { + actualData.push(data) + dataEventCount++ + }) + + parser.on('error', function (err) { + done(err) + }) + + parser.on('end', function () { + // console.log('actualData=', JSON.stringify(actualData, null, 1)) + // console.log('dataEventCount=', dataEventCount) + actualData.should.deepEqual(expectedData) + dataEventCount.should.equal(2) + done() + }) + xmlStream.pipe(parser) + }) }) })