Skip to content

Commit 7cde5b2

Browse files
committed
Add test for CLI exiting with error
1 parent b5b82ac commit 7cde5b2

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

test/main.tests.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,34 @@ test("--output-format=markdown option generate markdown output", function() {
6767
});
6868
});
6969

70+
test("when input file does not exist then process exits with error", function() {
71+
return tryRunMammoth(testPath("non-existent.docx")).then(function(result) {
72+
assert.strictEqual(result.error.code, 2);
73+
assert.strictEqual(result.stdout, "");
74+
assert.ok(result.stderr.startsWith("Fatal Error: ENOENT"));
75+
});
76+
});
7077

7178
function runMammoth() {
7279
var args = Array.prototype.slice.call(arguments, 0);
80+
return tryRunMammoth(args).then(function(result) {
81+
console.log(result.stderr); // eslint-disable-line no-console
82+
assert.equal(result.error, null);
83+
return {output: result.stdout, stderrOutput: result.stderr};
84+
});
85+
}
86+
87+
88+
function tryRunMammoth(args) {
7389
var deferred = promises.defer();
74-
90+
7591
var processArgs = ["node", "bin/mammoth"].concat(args);
7692
// TODO: proper escaping of args
7793
var command = processArgs.join(" ");
7894
child_process.exec(command, function(error, stdout, stderr) { // eslint-disable-line camelcase
79-
console.log(stderr); // eslint-disable-line no-console
80-
assert.equal(error, null);
81-
deferred.resolve({output: stdout, stderrOutput: stderr});
95+
deferred.resolve({error: error, stdout: stdout, stderr: stderr});
8296
});
83-
97+
8498
return deferred.promise;
8599
}
86100

0 commit comments

Comments
 (0)