diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-03-18 14:43:00 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-03-18 14:43:00 +0000 |
| commit | 1c815bea595037b9255bf1f11b4b3f90dbe7c1c2 (patch) | |
| tree | daa329078c14ff155ded2b4f5178c212a53ceaa5 | |
| parent | 800b14eed0c909c93a3271191ac93ad5a2d2057f (diff) | |
Fix and test CLI
| -rw-r--r-- | lib/main.js | 5 | ||||
| -rw-r--r-- | tests/main.tests.js | 31 | ||||
| -rw-r--r-- | tests/testing.js | 7 |
3 files changed, 39 insertions, 4 deletions
diff --git a/lib/main.js b/lib/main.js index 2bffccb..39ebf43 100644 --- a/lib/main.js +++ b/lib/main.js @@ -4,10 +4,9 @@ var mammoth = require("./"); var argv = optimist.argv; -var converter = new mammoth.Converter(); -converter.convertToHtml(argv._[0]) +mammoth.convertToHtml({path: argv._[0]}) .then(function(result) { - console.log(result); + process.stdout.write(result.value); }) .done(); diff --git a/tests/main.tests.js b/tests/main.tests.js new file mode 100644 index 0000000..1093027 --- /dev/null +++ b/tests/main.tests.js @@ -0,0 +1,31 @@ +var assert = require("assert"); +var child_process = require("child_process"); + +var promises = require("../lib/promises"); +var test = require("./testing").test; +var testPath = require("./testing").testPath; + +describe("CLI", function() { + test("HTML is printed to stdout if output file is not set", function() { + return runMammoth(testPath("single-paragraph.docx")).then(function(result) { + assert.equal(result.stderrOutput, "") + assert.equal(result.output, "<p>Walking on imported air</p>") + }); + }); +}); + +function runMammoth() { + var args = Array.prototype.slice.call(arguments, 0); + var deferred = promises.defer(); + + var processArgs = ["node", "lib/main.js"].concat(args); + // TODO: proper escaping of args + var command = processArgs.join(" "); + child_process.exec(command, function(error, stdout, stderr) { + console.log(stderr); + assert.equal(error, null); + deferred.resolve({output: stdout, stderrOutput: stderr}); + }); + + return deferred.promise; +} diff --git a/tests/testing.js b/tests/testing.js index 57bcb7e..9e64ca6 100644 --- a/tests/testing.js +++ b/tests/testing.js @@ -4,6 +4,7 @@ var promises = require("../lib/promises"); var _ = require("underscore"); exports.test = test; +exports.testPath = testPath; exports.testData = testData; exports.createFakeDocxFile = createFakeDocxFile; @@ -17,8 +18,12 @@ function test(name, func) { }); } +function testPath(filename) { + return path.join(__dirname, "test-data", filename); +} + function testData(testDataPath) { - var fullPath = path.join(__dirname, "test-data", testDataPath); + var fullPath = testPath(testDataPath); return promises.nfcall(fs.readFile, fullPath, "utf-8"); } |
