Skip to content

Commit

Permalink
Added tests and travis config
Browse files Browse the repository at this point in the history
  • Loading branch information
lmammino committed Dec 18, 2016
1 parent bee0c61 commit 0bb1796
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: node_js
node_js:
- "6"
- "5"
- "4"
- "0.12"
- "0.11"
- "0.10"
env:
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
script:
- npm test
install:
- npm install --dev
before_install:
- "npm update -g npm"
after_success:
- bash <(curl -s https://codecov.io/bash)
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"name": "x2j-cli",
"version": "1.0.0",
"description": "Node.js command line script to convert xml input into json output (can be piped easily)",
"engines" : {
"node" : ">=0.12"
"engines": {
"node": ">=0.12"
},
"main": "index.js",
"bin": {
"x2j": "./index.js"
},
"preferGlobal": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "tap test/**.test.js"
},
"repository": {
"type": "git",
Expand All @@ -25,5 +25,8 @@
"homepage": "https://github.com/lmammino/x2j-cli#readme",
"dependencies": {
"xml2js": "^0.4.17"
},
"devDependencies": {
"tap": "^8.0.1"
}
}
31 changes: 31 additions & 0 deletions test/functional.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

var fs = require('fs');
var path = require('path');
var childProcess = require('child_process');
var tap = require('tap');

tap.test(
'It should get an XML string as stdin and return a JSON string as stdout',
function (t) {
var cmd = 'cat test/sample.xml | node index';

childProcess.exec(cmd, function (err, stdout) {
if (err) {
return t.error(err);
}

var output = JSON.parse(stdout);
t.same(output, {
note: {
to: ['Tove'],
from: ['Jani'],
heading: ['Reminder'],
body: ['Don\'t forget me this weekend!']
}
});

t.end();
});
}
);
8 changes: 8 additions & 0 deletions test/sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

0 comments on commit 0bb1796

Please sign in to comment.