Skip to content

Commit

Permalink
Add support to validate the XML
Browse files Browse the repository at this point in the history
  • Loading branch information
amitguptagwl committed Mar 2, 2017
1 parent 2a90a82 commit 34ddbec
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ function validateSyntax(fileName) {
} else if (fileName.endsWith(".yaml") || fileName.endsWith(".yml")) {
require('yamljs').parseFile(fileName);
console.log("Validated successfully");
}
/*else if(fileName.endsWith(".xml"))
require('xmlchecker').check(fileName);*/
}else if(fileName.endsWith(".xml"))
var result = require('fast-xml-parser').validate(fs.readFileSync(fileName, {
encoding: 'utf-8'
}));
if(result === true) console.log("Validated successfully");
else {
console.log("Unsupported file");
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"author": "Amit Gupta (https://github.com/amitguptagwl)",
"dependencies": {
"fast-lorem-ipsum": "^1.0.2",
"fast-xml-parser": "^2.3.0",
"hashes": "^0.1.3",
"http-proxy": "^1.16.2",
"js-joda": "^1.1.11",
Expand Down
1 change: 1 addition & 0 deletions spec/test_assets/files/invalid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<auth_id>##token##<auth_id>
1 change: 1 addition & 0 deletions spec/test_assets/files/valid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<auth_id>##token##</auth_id>
11 changes: 9 additions & 2 deletions spec/validator_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ describe('validator', function () {
expect(console.log.calls.argsFor(1)[0]).toEqual(jasmine.any(String));
});

// it('should log error when invalid XML file', function () {
it('should validate XML file', function () {
validate(path.join(__dirname, "test_assets/files/valid.xml"));
expect(console.log).toHaveBeenCalledWith("Validated successfully");
});

// });
it('should log error when invalid XML file', function () {
validate(path.join(__dirname, "test_assets/files/invalid.xml"));
expect(console.log.calls.count()).toEqual(2);
expect(console.log.calls.argsFor(0)[0]).toEqual( "Validation failed");
});
});
12 changes: 5 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ fast-lorem-ipsum@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/fast-lorem-ipsum/-/fast-lorem-ipsum-1.0.2.tgz#3a1d13dc48d2f005d2dbbeffdb5f7bf901229ad8"

fast-xml-parser@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-2.3.0.tgz#1e606b79cded0210f3aecc92557de66f35bb309d"

forever-agent@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
Expand Down Expand Up @@ -641,13 +645,7 @@ mime@^1.3.4:
version "1.3.4"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.4.tgz#115f9e3b6b3daf2959983cb38f149a2d40eb5d53"

"minimatch@2 || 3", minimatch@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774"
dependencies:
brace-expansion "^1.0.0"

[email protected]:
"minimatch@2 || 3", [email protected], minimatch@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.2.tgz#0f398a7300ea441e9c348c83d98ab8c9dbf9c40a"
dependencies:
Expand Down

0 comments on commit 34ddbec

Please sign in to comment.