@@ -5,47 +5,60 @@ const pkg = require('../../packages/ace-core/package');
5
5
6
6
const path = require ( 'path' ) ;
7
7
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
+ } ) ;
8
52
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' } ) ;
47
62
} ) ;
48
- expect ( status ) . toBe ( 1 ) ;
49
- expect ( stderr ) . toBe ( '' ) ;
50
- expect ( stdout ) . toMatchSnapshot ( ) ;
51
63
} ) ;
64
+
0 commit comments