Skip to content

Commit 68a4100

Browse files
authored
Make optional options optional in typings and add type tests (#622)
* Make optional options optional in typings and add type tests * Run type test on pre-publish * Remove npm lockfile and update Yarn lockfile * Revert lockfile changes * final newline * Use downloaded files from master to prevent whitespace changes
1 parent fa5a733 commit 68a4100

File tree

4 files changed

+414
-70
lines changed

4 files changed

+414
-70
lines changed

.publishrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"confirm": true,
1515
"publishCommand": "npm publish",
1616
"publishTag": "latest",
17-
"prePublishScript": "npm test",
17+
"prePublishScript": "npm test && npm test-types",
1818
"postPublishScript": false
1919
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "./src/fxp.js",
66
"scripts": {
77
"test": "nyc --reporter=lcov --reporter=text jasmine spec/*spec.js",
8+
"test-types": "tsc --noEmit spec/typings/typings-test.ts",
89
"unit": "jasmine",
910
"coverage": "nyc report --reporter html --reporter text -t .nyc_output --report-dir .nyc_output/summary",
1011
"perf": "node ./benchmark/perfTest3.js",
@@ -46,6 +47,7 @@
4647
"@babel/plugin-transform-runtime": "^7.13.10",
4748
"@babel/preset-env": "^7.13.10",
4849
"@babel/register": "^7.13.8",
50+
"@types/node": "20",
4951
"babel-loader": "^8.2.2",
5052
"cytorus": "^0.2.9",
5153
"eslint": "^8.3.0",
@@ -54,6 +56,7 @@
5456
"nyc": "^15.1.0",
5557
"prettier": "^1.19.1",
5658
"publish-please": "^5.5.2",
59+
"typescript": "5",
5760
"webpack": "^5.64.4",
5861
"webpack-cli": "^4.9.1"
5962
},

spec/typings/typings-test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {
2+
XMLParser,
3+
XMLBuilder,
4+
XMLValidator,
5+
type X2jOptions,
6+
type XmlBuilderOptions,
7+
type validationOptions,
8+
} from '../../src/fxp';
9+
10+
const parseOpts: X2jOptions = {};
11+
12+
const XML = `
13+
<?xml version="1.0"?>
14+
<SomeElement name="parent">
15+
<SomeNestedElement name="child"></SomeNestedElement>
16+
</SomeElement>
17+
`;
18+
19+
const parser = new XMLParser(parseOpts);
20+
const parsed = parser.parse(XML);
21+
22+
console.log(!!parsed);
23+
24+
const buildOpts: XmlBuilderOptions = {};
25+
26+
const builder = new XMLBuilder(buildOpts);
27+
28+
const built = builder.build({
29+
any_name: {
30+
person: {
31+
phone: [
32+
15555551313,
33+
15555551212
34+
]
35+
}
36+
}
37+
});
38+
39+
console.log(!!built);
40+
41+
const validateOpts: validationOptions = {};
42+
43+
const isValid = XMLValidator.validate(built, validateOpts);
44+
45+
console.log(!!isValid);
46+
47+

0 commit comments

Comments
 (0)