Skip to content

Commit e108d4d

Browse files
committed
fix(cli): print the JSON report even when --silent is enabled
Fixes #112
1 parent f4f9d3a commit e108d4d

File tree

3 files changed

+70
-57
lines changed

3 files changed

+70
-57
lines changed

packages/ace-core/src/core/ace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module.exports = function ace(epubPath, options) {
5959
// Process the Results
6060
.then((report) => {
6161
if (options.outdir === undefined) {
62-
return winston.info(JSON.stringify(report.json, null, ' '));
62+
return process.stdout.write(JSON.stringify(report.json, null, ' '));
6363
}
6464
return Promise.all([
6565
report.copyData(options.outdir),

tests/__tests__/__snapshots__/cli.test.js.snap

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`test existing output 1`] = `
3+
exports[`Running the CLI on an unexisting document should fail 1`] = `
4+
"info: Closing logs.
5+
Re-run Ace using the --verbose option to enable full debug logging."
6+
`;
7+
8+
exports[`Running the CLI on an unexisting document should fail 2`] = `
9+
"error: Couldn’t find EPUB file 'unexisting.epub'
10+
"
11+
`;
12+
13+
exports[`Running the CLI with -o pointing to an existing directory should fail 1`] = `
414
"warn: Output directory is not empty.
515
616
Running Ace would override the following files or directories:
@@ -14,7 +24,9 @@ exports[`test existing output 1`] = `
1424
"
1525
`;
1626

17-
exports[`test help 1`] = `
27+
exports[`Running the CLI with no input should fail 1`] = `"error: Input required"`;
28+
29+
exports[`Running the CLI with no input should fail 2`] = `
1830
"
1931
Ace by DAISY, an Accessibility Checker for EPUB
2032
@@ -38,9 +50,7 @@ exports[`test help 1`] = `
3850
"
3951
`;
4052
41-
exports[`test no input 1`] = `"error: Input required"`;
42-
43-
exports[`test no input 2`] = `
53+
exports[`Running the CLI with the -h option should print help 1`] = `
4454
"
4555
Ace by DAISY, an Accessibility Checker for EPUB
4656
@@ -63,13 +73,3 @@ exports[`test no input 2`] = `
6373
$ ace -o out ~/Documents/book.epub
6474
"
6575
`;
66-
67-
exports[`test unexisting input 1`] = `
68-
"info: Closing logs.
69-
Re-run Ace using the --verbose option to enable full debug logging."
70-
`;
71-
72-
exports[`test unexisting input 2`] = `
73-
"error: Couldn’t find EPUB file 'unexisting.epub'
74-
"
75-
`;

tests/__tests__/cli.test.js

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,60 @@ const pkg = require('../../packages/ace-core/package');
55

66
const path = require('path');
77

8+
describe('Running the CLI', () => {
9+
test('with no input should fail', () => {
10+
const { stdout, stderr, status } = ace([]);
11+
expect(status).toBe(1);
12+
expect(stderr.trim()).toMatchSnapshot();
13+
expect(stdout).toMatchSnapshot();
14+
});
15+
16+
test('with the -h option should print help', () => {
17+
const { stdout, stderr, status } = ace(['-h']);
18+
expect(status).toBe(0);
19+
expect(stderr).toBe('');
20+
expect(stdout).toMatchSnapshot();
21+
});
22+
23+
test('with the -v option should print the version number', () => {
24+
const { stdout, stderr, status } = ace(['-v']);
25+
expect(status).toBe(0);
26+
expect(stderr).toBe('');
27+
expect(stdout.trim()).toBe(pkg.version);
28+
});
29+
30+
test('with the --version option should print the version number', () => {
31+
const { stdout, stderr, status } = ace(['--version']);
32+
expect(status).toBe(0);
33+
expect(stderr).toBe('');
34+
expect(stdout.trim()).toBe(pkg.version);
35+
});
36+
37+
test('on an unexisting document should fail', () => {
38+
const { stdout, stderr, status } = ace(['unexisting.epub']);
39+
expect(status).toBe(1);
40+
expect(stdout.trim()).toMatchSnapshot();
41+
expect(stderr).toMatchSnapshot();
42+
});
43+
44+
test('with -o pointing to an existing directory should fail', () => {
45+
const { stdout, stderr, status } = ace(['-o', 'report', 'foo'], {
46+
cwd: path.resolve(__dirname, '../data'),
47+
});
48+
expect(status).toBe(1);
49+
expect(stderr).toBe('');
50+
expect(stdout).toMatchSnapshot();
51+
});
852

9-
test('test no input', () => {
10-
const { stdout, stderr, status } = ace([]);
11-
expect(status).toBe(1);
12-
expect(stderr.trim()).toMatchSnapshot();
13-
expect(stdout).toMatchSnapshot();
14-
});
15-
16-
test('test help', () => {
17-
const { stdout, stderr, status } = ace(['-h']);
18-
expect(status).toBe(0);
19-
expect(stderr).toBe('');
20-
expect(stdout).toMatchSnapshot();
21-
});
22-
23-
test('test version -v', () => {
24-
const { stdout, stderr, status } = ace(['-v']);
25-
expect(status).toBe(0);
26-
expect(stderr).toBe('');
27-
expect(stdout.trim()).toBe(pkg.version);
28-
});
29-
30-
test('test version --version', () => {
31-
const { stdout, stderr, status } = ace(['--version']);
32-
expect(status).toBe(0);
33-
expect(stderr).toBe('');
34-
expect(stdout.trim()).toBe(pkg.version);
35-
});
36-
37-
test('test unexisting input', () => {
38-
const { stdout, stderr, status } = ace(['unexisting.epub']);
39-
expect(status).toBe(1);
40-
expect(stdout.trim()).toMatchSnapshot();
41-
expect(stderr).toMatchSnapshot();
42-
});
43-
44-
test('test existing output', () => {
45-
const { stdout, stderr, status } = ace(['-o', 'report', 'foo'], {
46-
cwd: path.resolve(__dirname, '../data'),
53+
test('with --silent and no --outdir should print the JSON report to standard output', () => {
54+
const { stdout, stderr, status } = ace(['-s', 'base-epub-30'], {
55+
cwd: path.resolve(__dirname, '../data'),
56+
});
57+
expect(status).toBe(0);
58+
expect(stderr).toBe('');
59+
expect(() => JSON.parse(stdout)).not.toThrow(SyntaxError);
60+
const res = JSON.parse(stdout);
61+
expect(res).toMatchObject({ '@type': 'earl:report' });
4762
});
48-
expect(status).toBe(1);
49-
expect(stderr).toBe('');
50-
expect(stdout).toMatchSnapshot();
5163
});
64+

0 commit comments

Comments
 (0)