diff --git a/bin/main.js b/bin/main.js index 97ac522c..758ef56a 100644 --- a/bin/main.js +++ b/bin/main.js @@ -222,8 +222,7 @@ export async function main(nodeProcess) { if (output) { if (noclobber && await fileExists(output)) { - nodeProcess.stderr.write('marked: output file \'' + output + '\' already exists, disable the \'-n\' / \'--no-clobber\' flag to overwrite\n'); - nodeProcess.exit(1); + throw Error('marked: output file \'' + output + '\' already exists, disable the \'-n\' / \'--no-clobber\' flag to overwrite\n'); } return await writeFile(output, html); } @@ -271,9 +270,10 @@ export async function main(nodeProcess) { nodeProcess.exit(0); } catch (err) { if (err.code === 'ENOENT') { - nodeProcess.stderr.write('marked: output to ' + err.path + ': No such directory'); + nodeProcess.stderr.write('marked: ' + err.path + ': No such file or directory'); + } else { + nodeProcess.stderr.write(err.message); } - nodeProcess.stderr.write(err); return nodeProcess.exit(1); } } diff --git a/test/unit/bin.test.js b/test/unit/bin.test.js index e9e0bcbb..00c3fa06 100644 --- a/test/unit/bin.test.js +++ b/test/unit/bin.test.js @@ -32,7 +32,7 @@ function createMocks() { on: mock.fn((method, func) => { mocks.stdin[method] = func; }), - resume: mock.fn + resume: mock.fn() }, exit: mock.fn((code) => { mocks.code = code; }) } @@ -44,7 +44,7 @@ function createMocks() { function testInput({ args = [], stdin = '', stdinError = '', stdout = '', stderr = '', code = 0 } = {}) { return async() => { const mocks = createMocks(); - mocks.process.argv = args; + mocks.process.argv = ['node', 'marked', ...args]; const mainPromise = main(mocks.process); if (typeof mocks.stdin.end === 'function') { if (stdin) { @@ -91,9 +91,23 @@ describe('bin/marked', () => { stdout: '
line1
line2