Skip to content

Commit

Permalink
fix(cli): print the JSON report even when --silent is enabled
Browse files Browse the repository at this point in the history
Fixes #112
  • Loading branch information
rdeltour committed Dec 21, 2017
1 parent f4f9d3a commit e108d4d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 57 deletions.
2 changes: 1 addition & 1 deletion packages/ace-core/src/core/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
30 changes: 15 additions & 15 deletions tests/__tests__/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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'
"
`;
95 changes: 54 additions & 41 deletions tests/__tests__/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit e108d4d

Please sign in to comment.