1 |
|
2 |
|
3 | var flow = require('../lib/xml-flow')
|
4 | , fs = require('fs')
|
5 | , should = require('chai').should()
|
6 | ;
|
7 |
|
8 | function getFlow(fileName) {
|
9 | return flow(fs.createReadStream(fileName));
|
10 | }
|
11 |
|
12 | describe('xml-flow', function(){
|
13 | describe('invoke', function(){
|
14 | it('should create an emitter when invoked with a stream and options', function(){
|
15 | var simpleStream = getFlow('./test/simple.xml');
|
16 | simpleStream.on.should.be.a('function');
|
17 | });
|
18 | });
|
19 |
|
20 | describe(".on('end')", function(){
|
21 | it('should emit after the file has been read', function(done){
|
22 | var simpleStream = getFlow('./test/simple.xml');
|
23 | simpleStream.on('end', function(){
|
24 | done();
|
25 | });
|
26 | });
|
27 | });
|
28 |
|
29 | describe(".on('tag:...')", function(){
|
30 | it('should emit the right number of nodes', function(done){
|
31 | var simpleStream = getFlow('./test/simple.xml')
|
32 | , count = 0
|
33 | ;
|
34 |
|
35 | simpleStream.on('tag:item', function(){
|
36 | count++;
|
37 | });
|
38 |
|
39 | simpleStream.on('end', function(){
|
40 | count.should.equal(3);
|
41 | done();
|
42 | });
|
43 | });
|
44 |
|
45 | it('should make non-attributed data look really simple', function(done){
|
46 | var simpleStream = getFlow('./test/test.xml')
|
47 | , output = {
|
48 | $name: 'no-attrs',
|
49 | person: [
|
50 | {name: 'Bill', id: '1', age:'27'},
|
51 | {name: 'Joe', id: '2', age:'29'},
|
52 | {name: 'Smitty', id: '3', age:'37'}
|
53 | ]
|
54 | }
|
55 | ;
|
56 |
|
57 | simpleStream.on('tag:no-attrs', function(node){
|
58 | node.should.deep.equal(output);
|
59 | done();
|
60 | });
|
61 | });
|
62 |
|
63 | it('should make all-attributed data look really simple', function(done){
|
64 | var simpleStream = getFlow('./test/test.xml')
|
65 | , output = {
|
66 | $name: 'all-attrs',
|
67 | person: [
|
68 | {name: 'Bill', id: '1', age:'27'},
|
69 | {name: 'Joe', id: '2', age:'29'},
|
70 | {name: 'Smitty', id: '3', age:'37'}
|
71 | ]
|
72 | }
|
73 | ;
|
74 |
|
75 | simpleStream.on('tag:all-attrs', function(node){
|
76 | node.should.deep.equal(output);
|
77 | done();
|
78 | });
|
79 | });
|
80 | });
|
81 | });
|