Skip to content

Commit

Permalink
Make optional options optional in typings and add type tests (#622)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jdforsythe committed Nov 22, 2023
1 parent fa5a733 commit 68a4100
Show file tree
Hide file tree
Showing 4 changed files with 414 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .publishrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"confirm": true,
"publishCommand": "npm publish",
"publishTag": "latest",
"prePublishScript": "npm test",
"prePublishScript": "npm test && npm test-types",
"postPublishScript": false
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "./src/fxp.js",
"scripts": {
"test": "nyc --reporter=lcov --reporter=text jasmine spec/*spec.js",
"test-types": "tsc --noEmit spec/typings/typings-test.ts",
"unit": "jasmine",
"coverage": "nyc report --reporter html --reporter text -t .nyc_output --report-dir .nyc_output/summary",
"perf": "node ./benchmark/perfTest3.js",
Expand Down Expand Up @@ -46,6 +47,7 @@
"@babel/plugin-transform-runtime": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@babel/register": "^7.13.8",
"@types/node": "20",
"babel-loader": "^8.2.2",
"cytorus": "^0.2.9",
"eslint": "^8.3.0",
Expand All @@ -54,6 +56,7 @@
"nyc": "^15.1.0",
"prettier": "^1.19.1",
"publish-please": "^5.5.2",
"typescript": "5",
"webpack": "^5.64.4",
"webpack-cli": "^4.9.1"
},
Expand Down
47 changes: 47 additions & 0 deletions spec/typings/typings-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
XMLParser,
XMLBuilder,
XMLValidator,
type X2jOptions,
type XmlBuilderOptions,
type validationOptions,
} from '../../src/fxp';

const parseOpts: X2jOptions = {};

const XML = `
<?xml version="1.0"?>
<SomeElement name="parent">
<SomeNestedElement name="child"></SomeNestedElement>
</SomeElement>
`;

const parser = new XMLParser(parseOpts);
const parsed = parser.parse(XML);

console.log(!!parsed);

const buildOpts: XmlBuilderOptions = {};

const builder = new XMLBuilder(buildOpts);

const built = builder.build({
any_name: {
person: {
phone: [
15555551313,
15555551212
]
}
}
});

console.log(!!built);

const validateOpts: validationOptions = {};

const isValid = XMLValidator.validate(built, validateOpts);

console.log(!!isValid);


0 comments on commit 68a4100

Please sign in to comment.