Merge pull request #1 from Sai1919/travisBuildCheck

testing Travis build and one test case added
This commit is contained in:
Sai1919
2016-11-07 14:08:19 +05:30
committed by GitHub
4 changed files with 49 additions and 2 deletions

View File

@@ -1,7 +1,8 @@
sudo: false
language: node_js
node_js:
- 6.1.x
- '0.10'
- '0.12'
script: npm test
notifications:
email:

View File

@@ -39,5 +39,8 @@
"name": "Sai Teja",
"email": "saitejas464@gmail.com"
}
]
],
"standard": {
"globals": [ "describe", "it" ]
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<items>
<item id="1" test= 'hello'> item
one <subitem sub= "TESTING SUB">one</subitem>
<subitem sub= "2">two</subitem> two
</item>
<item id="2"> item
one<subitem>three</subitem> two
<subitem>four</subitem> three
four<subitem>five</subitem>
</item>
</items>

View File

@@ -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)
})
})
})