UNPKG

1.64 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', function testCase() {
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 xmlContent = XMLLite.uglify(xmlContent, true);
17 // console.log(XMLLite.parse(xmlContent).lastChild);
18 $.get(`./fixtures/${fixture}.json`, (jsonContent) => {
19 const t1 = Date.now();
20 const obj = XMLLite.xml2js(xmlContent);
21 const time = Date.now() - t1;
22 const count = countElements(obj);
23 console.log(
24 `%cxml2js: %c%sms %cto parse %c%s %celements in fixture ${fixture}.`,
25 'font-weight: bold; color: blue;',
26 'font-weight: bold; color: green;',
27 leftPad(time, 3),
28 'font-weight: normal; color: black;',
29 'font-weight: bold; color: red;',
30 leftPad(count, 5),
31 'font-weight: normal; color: black;'
32 );
33 assert.deepEqual(
34 XMLLite.xml2js(xmlContent),
35 jsonContent,
36 `test case by fixture ${fixture} not passed`
37 );
38 done();
39 });
40 }, 'text');
41 });
42 nextFixture(fixtues);
43 }
44 }
45
46 $.get('./fixtures/files.json', (files) => {
47 nextFixture(files);
48 });
49});
50
\No newline at end of file