UNPKG

1.56 kBJavaScriptView Raw
1import $ from 'jquery';
2import XMLLite from 'xml-lite';
3import countElements from './count-elements';
4import leftPad from './left-pad';
5
6const assert = chai.assert;
7
8describe('xml2js', () => {
9 this.timeout(10000); // 10 seconds before timeout
10
11 function nextFixture(fixtues) {
12 if (fixtues.length) {
13 const fixture = fixtues.shift();
14 it(`xml2js: spec/fixtures/${fixture}.xml`, (done) => {
15 $.get(`./fixtures/${fixture}.xml`, (xmlContent) => {
16 // console.log(XMLLite.parse(xmlContent).lastChild);
17 $.get(`./fixtures/${fixture}.json`, (jsonContent) => {
18 const t1 = Date.now();
19 const obj = XMLLite.xml2js(xmlContent);
20 const time = Date.now() - t1;
21 const count = countElements(obj);
22 console.log(
23 `%cxml2js: %c%sms %cto parse %c%s %celements in fixture ${fixture}.`,
24 'font-weight: bold; color: blue;',
25 'font-weight: bold; color: green;',
26 leftPad(time, 3),
27 'font-weight: normal; color: black;',
28 'font-weight: bold; color: red;',
29 leftPad(count, 5),
30 'font-weight: normal; color: black;'
31 );
32 assert.deepEqual(
33 XMLLite.xml2js(xmlContent),
34 jsonContent,
35 `test case by fixture ${fixture} not passed`
36 );
37 done();
38 });
39 }, 'text');
40 });
41 nextFixture(fixtues);
42 }
43 }
44
45 $.get('./fixtures/files.json', (files) => {
46 nextFixture(files);
47 });
48});
49
\No newline at end of file