Skip to content

Commit 0d2828e

Browse files
committed
migrate tests to ava
1 parent 87939fc commit 0d2828e

File tree

2 files changed

+55
-75
lines changed

2 files changed

+55
-75
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Super small library to retrieve values and attributes from the XML AST generated by xml-reader",
55
"main": "build/index.js",
66
"scripts": {
7-
"test": "node test/test.js",
7+
"test": "ava test/test.js",
88
"pretest": "tsc",
99
"prepublish": "npm test"
1010
},
@@ -23,7 +23,7 @@
2323
"author": "Pedro Ladaria <[email protected]>",
2424
"license": "MIT",
2525
"devDependencies": {
26-
"tape": "^4.5.1",
26+
"ava": "^0.15.2",
2727
"xml-reader": "0.0.6"
2828
},
2929
"directories": {

test/test.js

Lines changed: 53 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require('tape');
1+
const test = require('ava');
22
const xmlReader = require('xml-reader');
33
const xQuery = require('..');
44

@@ -27,150 +27,130 @@ const xmlMessages =
2727
${xmlMessage2}
2828
</collection>`;
2929

30-
test('constructor from ast', t => {
30+
test.cb('constructor from ast', t => {
3131
const reader = xmlReader.create();
3232
reader.on('done', ast => {
3333
const xq = xQuery(ast);
34-
t.equal(xq.length, 1, 'length is 1');
35-
t.equal(xq.get(0), ast, 'item 0 is the same ast');
34+
t.is(xq.length, 1, 'length is 1');
35+
t.is(xq.get(0), ast, 'item 0 is the same ast');
3636
t.end();
3737
});
3838
reader.parse(xmlMessage1);
3939
});
4040

41-
test('constructor from ast array', t => {
41+
test.cb('constructor from ast array', t => {
4242
const reader = xmlReader.create();
4343
reader.on('done', ast => {
4444
const xq = xQuery([ast, ast]);
45-
t.equal(xq.length, 2, 'length is 2');
46-
t.equal(xq.get(0), ast, 'item 0 is ok');
47-
t.equal(xq.get(1), ast, 'item 1 is ok');
45+
t.is(xq.length, 2, 'length is 2');
46+
t.is(xq.get(0), ast, 'item 0 is ok');
47+
t.is(xq.get(1), ast, 'item 1 is ok');
4848
t.end();
4949
});
5050
reader.parse(xmlMessage1);
5151
});
5252

53-
test('constructor from falsy values', t => {
53+
test.cb('constructor from falsy values', t => {
5454
const values = [null, false, undefined, 0, [], ''];
5555
values.forEach(value => {
5656
const xq = xQuery(value);
57-
t.equal(xq.length, 0, 'length is 0');
58-
t.equal(xq.get(0), undefined, 'item 0 is undefined');
57+
t.is(xq.length, 0, 'length is 0');
58+
t.is(xq.get(0), undefined, 'item 0 is undefined');
5959
});
6060
t.end();
6161
});
6262

63-
test('find root element', t => {
63+
test.cb('find root element', t => {
6464
const reader = xmlReader.create();
6565
reader.on('done', ast => {
6666
const xq = xQuery(ast);
6767
const result = xq.find('message');
68-
t.equal(result.length, 1, 'one element found');
69-
t.equal(result.get(0).name, 'message', 'element name is message');
68+
t.is(result.length, 1, 'one element found');
69+
t.is(result.get(0).name, 'message', 'element name is message');
7070
t.end();
7171
});
7272
reader.parse(xmlMessage1);
7373
});
7474

75-
test('find root elements from array', t => {
75+
test.cb('find root elements from array', t => {
7676
const reader = xmlReader.create();
7777
reader.on('done', ast => {
7878
const xq = xQuery([ast, ast]);
7979
const result = xq.find('message');
80-
t.equal(result.length, 2, 'two elements found');
81-
t.equal(result.get(0).name, 'message', 'element #0 name is message');
82-
t.equal(result.get(1).name, 'message', 'element #1 name is message');
80+
t.is(result.length, 2, 'two elements found');
81+
t.is(result.get(0).name, 'message', 'element #0 name is message');
82+
t.is(result.get(1).name, 'message', 'element #1 name is message');
8383
t.end();
8484
});
8585
reader.parse(xmlMessage1);
8686
});
8787

88-
test('find deep', t => {
88+
test.cb('find deep', t => {
8989
const reader = xmlReader.create();
9090
reader.on('done', ast => {
9191
const xq = xQuery(ast);
9292
const result = xq.find('to');
93-
t.equal(result.length, 3, 'three elements found');
94-
t.equal(result.get(0).children[0].value, 'Alice');
95-
t.equal(result.get(1).children[0].value, 'Carl');
96-
t.equal(result.get(2).children[0].value, 'Alice');
93+
t.is(result.length, 3, 'three elements found');
94+
t.is(result.get(0).children[0].value, 'Alice');
95+
t.is(result.get(1).children[0].value, 'Carl');
96+
t.is(result.get(2).children[0].value, 'Alice');
9797
t.end();
9898
});
9999
reader.parse(xmlMessages);
100100
});
101101

102-
test('attr', t => {
102+
test.cb('attr', t => {
103103
const reader = xmlReader.create();
104104
reader.on('done', ast => {
105+
let result, attr1, attr2;
105106

106-
t.test('attr from ast - get all', t => {
107-
const result = xQuery(ast).find('message').attr();
108-
t.deepEqual(result, {id: '1001', type: 'letter'}, 'got all attributes');
109-
t.end();
110-
});
111-
112-
t.test('attr from ast - get by name', t => {
113-
const attr1 = xQuery(ast).find('message').attr('id');
114-
const attr2 = xQuery(ast).find('message').attr('type');
115-
t.equal(attr1, '1001', 'attr value is correct');
116-
t.equal(attr2, 'letter', 'attr value is correct');
117-
t.end();
118-
});
119-
120-
t.test('attr from ast - get by name miss', t => {
121-
const result = xQuery(ast).find('message').attr('miss');
122-
t.equal(result, undefined, 'returns undefined');
123-
t.end();
124-
});
125-
126-
t.test('attr from ast array - get all', t => {
127-
const result = xQuery([ast, ast]).find('message').attr();
128-
t.deepEqual(result, {id: '1001', type: 'letter'}, 'got all attributes');
129-
t.end();
130-
});
131-
132-
t.test('attr from ast array - get by name', t => {
133-
const attr1 = xQuery(ast).find('message').attr('id');
134-
const attr2 = xQuery(ast).find('message').attr('type');
135-
t.equal(attr1, '1001', 'attr value is correct');
136-
t.equal(attr2, 'letter', 'attr value is correct');
137-
t.end();
138-
});
139-
140-
t.test('attr from empty array - get all', t => {
141-
const result = xQuery([]).attr();
142-
t.deepEqual(result, undefined, 'returns undefined');
143-
t.end();
144-
});
145-
146-
t.test('attr from empty array - get by name', t => {
147-
const result = xQuery([]).attr('miss');
148-
t.deepEqual(result, undefined, 'returns undefined');
149-
t.end();
150-
});
107+
result = xQuery(ast).find('message').attr();
108+
t.deepEqual(result, {id: '1001', type: 'letter'}, 'attr from ast - get all');
109+
110+
attr1 = xQuery(ast).find('message').attr('id');
111+
attr2 = xQuery(ast).find('message').attr('type');
112+
t.is(attr1, '1001', 'attr from ast - get by name');
113+
t.is(attr2, 'letter', 'attr from ast - get by name');
114+
115+
result = xQuery(ast).find('message').attr('miss');
116+
t.is(result, undefined, 'attr from ast - get by name miss');
117+
118+
result = xQuery([ast, ast]).find('message').attr();
119+
t.deepEqual(result, {id: '1001', type: 'letter'}, 'attr from ast array - get all');
120+
121+
attr1 = xQuery(ast).find('message').attr('id');
122+
attr2 = xQuery(ast).find('message').attr('type');
123+
t.is(attr1, '1001', 'attr from ast array - get by name');
124+
t.is(attr2, 'letter', 'attr from ast array - get by name');
125+
126+
result = xQuery([]).attr();
127+
t.deepEqual(result, undefined, 'attr from empty array - get all');
128+
129+
result = xQuery([]).attr('miss');
130+
t.deepEqual(result, undefined, 'attr from empty array - get by name');
151131

152132
t.end();
153133
});
154134
reader.parse(xmlMessage1);
155135
});
156136

157-
test('children', t => {
137+
test.cb('children', t => {
158138
const reader = xmlReader.create();
159139
reader.on('done', ast => {
160140
const xq = xQuery(ast).children();
161-
t.equal(xq.length, 4, 'length is 4');
141+
t.is(xq.length, 4, 'length is 4');
162142
t.deepEqual(xq.map(node => node.name), ['to', 'from', 'subject', 'body'], 'children names ok');
163143
t.end();
164144
});
165145
reader.parse(xmlMessage1);
166146
});
167147

168-
test('text', t => {
148+
test.cb('text', t => {
169149
const reader = xmlReader.create();
170150
reader.on('done', ast => {
171151
const expected = 'AliceBobHelloThis is a demo!';
172152
const result = xQuery(ast).text();
173-
t.equal(result, expected, 'text is correct');
153+
t.is(result, expected, 'text is correct');
174154
t.end();
175155
});
176156
reader.parse(xmlMessage1);

0 commit comments

Comments
 (0)