Skip to content

Commit 1d9b748

Browse files
- Formatting tests;
- Adjusting linting rules; - Installing additional plugins for ESLint.
1 parent 9babec9 commit 1d9b748

18 files changed

+959
-960
lines changed

.eslintrc.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ module.exports = {
22
env: {
33
browser: true,
44
es6: true,
5-
node: true
5+
node: true,
6+
"jest/globals": true
67
},
78
extends: ['eslint:recommended'],
89
parser: '@typescript-eslint/parser',
910
parserOptions: {
1011
ecmaVersion: 2018,
1112
sourceType: 'module'
1213
},
13-
plugins: ['@typescript-eslint'],
14+
plugins: [
15+
'jest',
16+
'jsx',
17+
'@typescript-eslint'
18+
],
1419
root: true,
1520
rules: {
1621
'accessor-pairs': 'error',
@@ -59,7 +64,7 @@ module.exports = {
5964
'key-spacing': 'error',
6065
'keyword-spacing': 'off',
6166
'line-comment-position': 'off',
62-
'linebreak-style': ['error', 'unix'],
67+
'linebreak-style': ['warn', 'unix'],
6368
'lines-around-comment': 'error',
6469
'lines-around-directive': 'error',
6570
'lines-between-class-members': ['error', 'always'],
@@ -88,6 +93,7 @@ module.exports = {
8893
'no-caller': 'error',
8994
'no-catch-shadow': 'error',
9095
'no-confusing-arrow': 'error',
96+
'no-console': 'warn',
9197
'no-continue': 'off',
9298
'no-div-regex': 'error',
9399
'no-duplicate-imports': 'error',

.release-it.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
},
1111
"hooks": {
1212
"before:init": ["yarn build"],
13-
"after:bump": "copyfiles -V ./package.json ./dist"
13+
"after:bump": "copyfiles -V ./package.json ./dist && copyfiles -V ./README.md ./dist"
1414
}
1515
}

index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { xsltProcess } from './src/xslt';
2+
export { xmlParse } from './src/dom';
3+
export { ExprContext } from './src/xpath';
4+
export { xpathParse } from './src/xpath/functions';

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
"@typescript-eslint/parser": "^5.60.0",
5050
"babel-jest": "^29.5.0",
5151
"eslint": "^5.12.1",
52+
"eslint-plugin-jest": "^27.2.2",
53+
"eslint-plugin-jsx": "^0.1.0",
5254
"isomorphic-jsx": "^0.3.0",
5355
"jest": "^29.5.0",
5456
"npm-check-updates": "^16.10.13",

src/index.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/dom.test.tsx

Lines changed: 25 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Copyright 2023 Design Liquido
12
// Copyright 2018 Johannes Wilm
23
// Copyright 2005 Google Inc.
34
// All Rights Reserved
@@ -6,29 +7,26 @@
67
// Author: Steffen Meschkat <mesch@google.com>
78
// Junji Takagi <jtakagi@google.com>
89
// Johannes Wilm <johannes@fiduswriter.org>
9-
import he from "he"
10+
import he from 'he';
1011

11-
import {
12-
xmlParse
13-
} from "../src/dom"
14-
import {
15-
xmlText
16-
} from "../src/dom/util"
12+
import { xmlParse } from '../src/dom';
13+
import { xmlText } from '../src/dom/util';
1714

1815
import assert from 'assert';
1916
import { dom } from 'isomorphic-jsx';
2017

2118
// Just touching the `dom`, otherwise Babel prunes the import.
2219
console.log(dom);
2320
describe('dom parsing', () => {
24-
2521
it('can parse xml', () => {
26-
const xml = <page>
27-
<request>
28-
<q id="q">new york</q>
29-
</request>
30-
<location lat="100" lon='200'/>
31-
</page>;
22+
const xml = (
23+
<page>
24+
<request>
25+
<q id="q">new york</q>
26+
</request>
27+
<location lat="100" lon="200" />
28+
</page>
29+
);
3230

3331
const dom1 = xmlParse(`<?xml version="1.0"?>${xml}`);
3432
const dom2 = xmlParse(`<?xml version='1.1'?>${xml}`);
@@ -43,8 +41,7 @@ describe('dom parsing', () => {
4341
const byId = dom1.getElementById(id);
4442
assert.notEqual(byId, null);
4543
assert.equal(id, byId.getAttribute('id'));
46-
47-
})
44+
});
4845

4946
it('can parse weird xml', () => {
5047
const xml = [
@@ -59,7 +56,7 @@ describe('dom parsing', () => {
5956
const dom1 = xmlParse(`<?xml version="1.0"?>${xml}`);
6057
const dom2 = xmlParse(`<?xml version='1.1'?>${xml}`);
6158
doTestXmlParse(dom1, dom2);
62-
})
59+
});
6360

6461
it('can parse Japanese xml', () => {
6562
const xml = [
@@ -75,23 +72,17 @@ describe('dom parsing', () => {
7572
const dom1 = xmlParse(`<?xml version="1.0"?>${xml}`);
7673
const dom2 = xmlParse(`<?xml version='1.1'?>${xml}`);
7774
doTestXmlParse(dom1, dom2);
78-
})
75+
});
7976

8077
it('can resolve entities', () => {
8178
assert.equal('";"', he.decode('&quot;;&quot;'));
82-
})
83-
84-
})
85-
79+
});
80+
});
8681

8782
const doTestXmlParse = (dom1, dom2) => {
8883
assert.equal(xmlText(dom1), xmlText(dom2), 'xmlText');
8984

90-
assert.equal(
91-
dom1.nodeName,
92-
dom2.nodeName,
93-
'#document'
94-
);
85+
assert.equal(dom1.nodeName, dom2.nodeName, '#document');
9586

9687
assert.equal(dom1.documentElement, dom1.firstChild, 'documentElement');
9788
assert.equal(dom2.documentElement, dom2.firstChild, 'documentElement');
@@ -102,40 +93,16 @@ const doTestXmlParse = (dom1, dom2) => {
10293
assert.equal(dom1.documentElement.parentNode, dom1, 'parentNode');
10394
assert.equal(dom2.documentElement.parentNode, dom2, 'parentNode');
10495

105-
assert.equal(
106-
dom1.documentElement.nodeName,
107-
dom2.documentElement.nodeName,
108-
'page'
109-
);
110-
assert.equal(
111-
dom1.childNodes.length,
112-
dom2.childNodes.length,
113-
'dom.childNodes.length'
114-
);
115-
assert.equal(
116-
dom1.childNodes.length,
117-
dom2.childNodes.length,
118-
'dom.childNodes.length'
119-
);
120-
assert.equal(
121-
dom1.firstChild.childNodes.length,
122-
dom2.firstChild.childNodes.length,
123-
'dom.childNodes.length'
124-
);
125-
assert.equal(
126-
dom1.firstChild.childNodes.length,
127-
dom2.firstChild.childNodes.length,
128-
'dom.childNodes.length'
129-
);
96+
assert.equal(dom1.documentElement.nodeName, dom2.documentElement.nodeName, 'page');
97+
assert.equal(dom1.childNodes.length, dom2.childNodes.length, 'dom.childNodes.length');
98+
assert.equal(dom1.childNodes.length, dom2.childNodes.length, 'dom.childNodes.length');
99+
assert.equal(dom1.firstChild.childNodes.length, dom2.firstChild.childNodes.length, 'dom.childNodes.length');
100+
assert.equal(dom1.firstChild.childNodes.length, dom2.firstChild.childNodes.length, 'dom.childNodes.length');
130101

131102
assert.equal(
132103
dom1.firstChild.childNodes[1].attributes.length,
133104
dom2.firstChild.childNodes[1].attributes.length,
134105
'location.attributes.length'
135106
);
136-
assert.equal(
137-
dom1.firstChild.childNodes[1].attributes.length,
138-
2,
139-
'location.attributes.length'
140-
);
141-
}
107+
assert.equal(dom1.firstChild.childNodes[1].attributes.length, 2, 'location.attributes.length');
108+
};

tests/escape.test.tsx

Lines changed: 43 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,68 @@
11
import assert from 'assert';
2-
import { xmlParse } from '../src/dom'
3-
import { xmlText } from '../src/dom/util'
4-
2+
import { xmlParse } from '../src/dom';
3+
import { xmlText } from '../src/dom/util';
54

65
describe('escape', () => {
6+
it('accepts already escaped ampersand', () => {
7+
const xmlString = '<root>Fish&amp;pie</root>';
78

8-
it('accepts already escaped ampersand', () => {
9-
const xmlString = '<root>Fish&amp;pie</root>';
10-
11-
const outXmlString = xmlText(xmlParse(xmlString))
12-
13-
assert.equal(
14-
outXmlString,
15-
xmlString
16-
);
17-
})
18-
19-
it('escapes non-escaped ampersand', () => {
20-
const xmlString = '<root>Fish&pie</root>';
9+
const outXmlString = xmlText(xmlParse(xmlString));
2110

22-
const outXmlString = xmlText(xmlParse(xmlString))
11+
assert.equal(outXmlString, xmlString);
12+
});
2313

24-
assert.equal(
25-
outXmlString,
26-
'<root>Fish&amp;pie</root>'
27-
);
28-
})
14+
it('escapes non-escaped ampersand', () => {
15+
const xmlString = '<root>Fish&pie</root>';
2916

30-
it('accepts non-escaped ">" between elements', () => {
31-
const xmlString = '<root>Fish>pie</root>';
17+
const outXmlString = xmlText(xmlParse(xmlString));
3218

33-
const outXmlString = xmlText(xmlParse(xmlString))
19+
assert.equal(outXmlString, '<root>Fish&amp;pie</root>');
20+
});
3421

35-
assert.equal(
36-
outXmlString,
37-
'<root>Fish&gt;pie</root>'
38-
);
39-
})
22+
it('accepts non-escaped ">" between elements', () => {
23+
const xmlString = '<root>Fish>pie</root>';
4024

41-
it('accepts non-escaped "\'" between elements', () => {
42-
const xmlString = '<root>Fish\'pie</root>';
25+
const outXmlString = xmlText(xmlParse(xmlString));
4326

44-
const outXmlString = xmlText(xmlParse(xmlString))
27+
assert.equal(outXmlString, '<root>Fish&gt;pie</root>');
28+
});
4529

46-
assert.equal(
47-
outXmlString,
48-
'<root>Fish\'pie</root>'
49-
);
50-
})
30+
it('accepts non-escaped "\'" between elements', () => {
31+
const xmlString = "<root>Fish'pie</root>";
5132

52-
it('accepts non-escaped \'"\' between elements', () => {
53-
const xmlString = '<root>Fish"pie</root>';
33+
const outXmlString = xmlText(xmlParse(xmlString));
5434

55-
const outXmlString = xmlText(xmlParse(xmlString))
35+
assert.equal(outXmlString, "<root>Fish'pie</root>");
36+
});
5637

57-
assert.equal(
58-
outXmlString,
59-
'<root>Fish"pie</root>'
60-
);
61-
})
38+
it("accepts non-escaped '\"' between elements", () => {
39+
const xmlString = '<root>Fish"pie</root>';
6240

63-
it('accepts non-escaped ">" in attributes', () => {
64-
const xmlString = '<root dish="eat>hunger">Fish</root>';
41+
const outXmlString = xmlText(xmlParse(xmlString));
6542

66-
const outXmlString = xmlText(xmlParse(xmlString))
43+
assert.equal(outXmlString, '<root>Fish"pie</root>');
44+
});
6745

68-
assert.equal(
69-
outXmlString,
70-
'<root dish="eat&gt;hunger">Fish</root>'
71-
);
72-
})
46+
it('accepts non-escaped ">" in attributes', () => {
47+
const xmlString = '<root dish="eat>hunger">Fish</root>';
7348

74-
it('accepts non-escaped "\'" in attributes', () => {
75-
const xmlString = '<root dish="eat\'hunger">Fish</root>';
49+
const outXmlString = xmlText(xmlParse(xmlString));
7650

77-
const outXmlString = xmlText(xmlParse(xmlString))
51+
assert.equal(outXmlString, '<root dish="eat&gt;hunger">Fish</root>');
52+
});
7853

79-
assert.equal(
80-
outXmlString,
81-
'<root dish="eat\'hunger">Fish</root>'
82-
);
83-
})
54+
it('accepts non-escaped "\'" in attributes', () => {
55+
const xmlString = '<root dish="eat\'hunger">Fish</root>';
8456

85-
it('accepts non-escaped \'"\' in attributes', () => {
86-
const xmlString = "<root dish='eat\"hunger'>Fish</root>";
87-
const outXmlString = xmlText(xmlParse(xmlString))
57+
const outXmlString = xmlText(xmlParse(xmlString));
8858

89-
assert.equal(
90-
outXmlString,
91-
'<root dish="eat&quot;hunger">Fish</root>'
92-
);
93-
})
59+
assert.equal(outXmlString, '<root dish="eat\'hunger">Fish</root>');
60+
});
9461

62+
it("accepts non-escaped '\"' in attributes", () => {
63+
const xmlString = "<root dish='eat\"hunger'>Fish</root>";
64+
const outXmlString = xmlText(xmlParse(xmlString));
9565

96-
})
66+
assert.equal(outXmlString, '<root dish="eat&quot;hunger">Fish</root>');
67+
});
68+
});

tests/local-name.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
/* eslint-disable no-undef */
12
import assert from 'assert';
23
import { dom } from 'isomorphic-jsx';
3-
import { xsltProcess, xmlParse } from '../src'
4+
import { xsltProcess, xmlParse } from '..'
45

56
// Just touching the `dom`, otherwise Babel prunes the import.
67
console.log(dom);

0 commit comments

Comments
 (0)