UNPKG

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