diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-05-31 11:11:50 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-09-16 22:51:22 +0100 |
| commit | 4ad7de79ffbb89f99e25268a810387a473ad41f3 (patch) | |
| tree | 6e99e93a8be8ae32c1243cd0bd92d6f42f23d44e | |
| parent | 71fe5daa50f85939efc9ea546ac588c4dba56d4c (diff) | |
Add test for CLI exiting with error
| -rw-r--r-- | test/main.tests.js | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/test/main.tests.js b/test/main.tests.js index 505c31f..06824f0 100644 --- a/test/main.tests.js +++ b/test/main.tests.js @@ -67,20 +67,34 @@ test("--output-format=markdown option generate markdown output", function() { }); }); +test("when input file does not exist then process exits with error", function() { + return tryRunMammoth(testPath("non-existent.docx")).then(function(result) { + assert.strictEqual(result.error.code, 2); + assert.strictEqual(result.stdout, ""); + assert.ok(result.stderr.startsWith("Fatal Error: ENOENT")); + }); +}); function runMammoth() { var args = Array.prototype.slice.call(arguments, 0); + return tryRunMammoth(args).then(function(result) { + console.log(result.stderr); // eslint-disable-line no-console + assert.equal(result.error, null); + return {output: result.stdout, stderrOutput: result.stderr}; + }); +} + + +function tryRunMammoth(args) { var deferred = promises.defer(); - + var processArgs = ["node", "bin/mammoth"].concat(args); // TODO: proper escaping of args var command = processArgs.join(" "); child_process.exec(command, function(error, stdout, stderr) { // eslint-disable-line camelcase - console.log(stderr); // eslint-disable-line no-console - assert.equal(error, null); - deferred.resolve({output: stdout, stderrOutput: stderr}); + deferred.resolve({error: error, stdout: stdout, stderr: stderr}); }); - + return deferred.promise; } |
