diff --git a/packages/ace-core/src/core/ace.js b/packages/ace-core/src/core/ace.js index 78874748..32661692 100644 --- a/packages/ace-core/src/core/ace.js +++ b/packages/ace-core/src/core/ace.js @@ -59,7 +59,7 @@ module.exports = function ace(epubPath, options) { // Process the Results .then((report) => { if (options.outdir === undefined) { - return winston.info(JSON.stringify(report.json, null, ' ')); + return process.stdout.write(JSON.stringify(report.json, null, ' ')); } return Promise.all([ report.copyData(options.outdir), diff --git a/tests/__tests__/__snapshots__/cli.test.js.snap b/tests/__tests__/__snapshots__/cli.test.js.snap index ea765c2d..28072511 100644 --- a/tests/__tests__/__snapshots__/cli.test.js.snap +++ b/tests/__tests__/__snapshots__/cli.test.js.snap @@ -1,6 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`test existing output 1`] = ` +exports[`Running the CLI on an unexisting document should fail 1`] = ` +"info: Closing logs. +Re-run Ace using the --verbose option to enable full debug logging." +`; + +exports[`Running the CLI on an unexisting document should fail 2`] = ` +"error: Couldn’t find EPUB file 'unexisting.epub' +" +`; + +exports[`Running the CLI with -o pointing to an existing directory should fail 1`] = ` "warn: Output directory is not empty. Running Ace would override the following files or directories: @@ -14,7 +24,9 @@ exports[`test existing output 1`] = ` " `; -exports[`test help 1`] = ` +exports[`Running the CLI with no input should fail 1`] = `"error: Input required"`; + +exports[`Running the CLI with no input should fail 2`] = ` " Ace by DAISY, an Accessibility Checker for EPUB @@ -38,9 +50,7 @@ exports[`test help 1`] = ` " `; -exports[`test no input 1`] = `"error: Input required"`; - -exports[`test no input 2`] = ` +exports[`Running the CLI with the -h option should print help 1`] = ` " Ace by DAISY, an Accessibility Checker for EPUB @@ -63,13 +73,3 @@ exports[`test no input 2`] = ` $ ace -o out ~/Documents/book.epub " `; - -exports[`test unexisting input 1`] = ` -"info: Closing logs. -Re-run Ace using the --verbose option to enable full debug logging." -`; - -exports[`test unexisting input 2`] = ` -"error: Couldn’t find EPUB file 'unexisting.epub' -" -`; diff --git a/tests/__tests__/cli.test.js b/tests/__tests__/cli.test.js index 39a8424d..3439a4c8 100644 --- a/tests/__tests__/cli.test.js +++ b/tests/__tests__/cli.test.js @@ -5,47 +5,60 @@ const pkg = require('../../packages/ace-core/package'); const path = require('path'); +describe('Running the CLI', () => { + test('with no input should fail', () => { + const { stdout, stderr, status } = ace([]); + expect(status).toBe(1); + expect(stderr.trim()).toMatchSnapshot(); + expect(stdout).toMatchSnapshot(); + }); + + test('with the -h option should print help', () => { + const { stdout, stderr, status } = ace(['-h']); + expect(status).toBe(0); + expect(stderr).toBe(''); + expect(stdout).toMatchSnapshot(); + }); + + test('with the -v option should print the version number', () => { + const { stdout, stderr, status } = ace(['-v']); + expect(status).toBe(0); + expect(stderr).toBe(''); + expect(stdout.trim()).toBe(pkg.version); + }); + + test('with the --version option should print the version number', () => { + const { stdout, stderr, status } = ace(['--version']); + expect(status).toBe(0); + expect(stderr).toBe(''); + expect(stdout.trim()).toBe(pkg.version); + }); + + test('on an unexisting document should fail', () => { + const { stdout, stderr, status } = ace(['unexisting.epub']); + expect(status).toBe(1); + expect(stdout.trim()).toMatchSnapshot(); + expect(stderr).toMatchSnapshot(); + }); + + test('with -o pointing to an existing directory should fail', () => { + const { stdout, stderr, status } = ace(['-o', 'report', 'foo'], { + cwd: path.resolve(__dirname, '../data'), + }); + expect(status).toBe(1); + expect(stderr).toBe(''); + expect(stdout).toMatchSnapshot(); + }); -test('test no input', () => { - const { stdout, stderr, status } = ace([]); - expect(status).toBe(1); - expect(stderr.trim()).toMatchSnapshot(); - expect(stdout).toMatchSnapshot(); -}); - -test('test help', () => { - const { stdout, stderr, status } = ace(['-h']); - expect(status).toBe(0); - expect(stderr).toBe(''); - expect(stdout).toMatchSnapshot(); -}); - -test('test version -v', () => { - const { stdout, stderr, status } = ace(['-v']); - expect(status).toBe(0); - expect(stderr).toBe(''); - expect(stdout.trim()).toBe(pkg.version); -}); - -test('test version --version', () => { - const { stdout, stderr, status } = ace(['--version']); - expect(status).toBe(0); - expect(stderr).toBe(''); - expect(stdout.trim()).toBe(pkg.version); -}); - -test('test unexisting input', () => { - const { stdout, stderr, status } = ace(['unexisting.epub']); - expect(status).toBe(1); - expect(stdout.trim()).toMatchSnapshot(); - expect(stderr).toMatchSnapshot(); -}); - -test('test existing output', () => { - const { stdout, stderr, status } = ace(['-o', 'report', 'foo'], { - cwd: path.resolve(__dirname, '../data'), + test('with --silent and no --outdir should print the JSON report to standard output', () => { + const { stdout, stderr, status } = ace(['-s', 'base-epub-30'], { + cwd: path.resolve(__dirname, '../data'), + }); + expect(status).toBe(0); + expect(stderr).toBe(''); + expect(() => JSON.parse(stdout)).not.toThrow(SyntaxError); + const res = JSON.parse(stdout); + expect(res).toMatchObject({ '@type': 'earl:report' }); }); - expect(status).toBe(1); - expect(stderr).toBe(''); - expect(stdout).toMatchSnapshot(); }); +