UNPKG

1.53 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 description() {
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 assert.equal(
33 XMLLite.js2xml(jsonContent),
34 XMLLite.uglify(xmlContent),
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