@@ -14,3 +14,54 @@ test("ui5 -v", async (t) => {
14
14
const { stdout} = await ui5 ( [ "-v" ] ) ;
15
15
t . is ( stdout , `${ pkg . version } (from ${ ui5Cli } )` ) ;
16
16
} ) ;
17
+
18
+ test ( "Yargs error handling" , async ( t ) => {
19
+ const err = await t . throwsAsync ( ui5 ( [ "invalidcomands" ] ) ) ;
20
+
21
+ const stdoutLines = err . stdout . split ( "\n" ) ;
22
+ t . deepEqual ( stdoutLines [ 0 ] , "Command Failed:" , "Correct first log line" ) ;
23
+ // Error message itself originates from yargs and is therefore not asserted
24
+ t . deepEqual ( stdoutLines [ stdoutLines . length - 1 ] , `See 'ui5 --help' or 'ui5 build --help' for help` ,
25
+ "Correct last log line" ) ;
26
+
27
+ t . deepEqual ( err . exitCode , 1 , "Process was exited with code 1" ) ;
28
+ } ) ;
29
+
30
+ test ( "Exception error handling" , async ( t ) => {
31
+ // This test depends on the init command throwing on projects that already have a ui5.yaml
32
+
33
+ const err = await t . throwsAsync ( ui5 ( [ "init" ] , {
34
+ cwd : path . join ( __dirname , ".." , ".." , ".." , "fixtures" , "init" , "application" )
35
+ } ) ) ;
36
+
37
+ const stdoutLines = err . stdout . split ( "\n" ) ;
38
+ t . deepEqual ( stdoutLines [ 1 ] , "⚠️ Process Failed With Error" , "Correct error log" ) ;
39
+ t . deepEqual ( stdoutLines [ 3 ] , "Error Message:" , "Correct error log" ) ;
40
+ t . deepEqual ( stdoutLines [ 4 ] , "Initialization not possible: ui5.yaml already exists" , "Correct error log" ) ;
41
+ t . deepEqual ( stdoutLines [ stdoutLines . length - 1 ] ,
42
+ "For details, execute the same command again with an additional '--verbose' parameter" , "Correct error log" ) ;
43
+
44
+ t . deepEqual ( err . exitCode , 1 , "Process was exited with code 1" ) ;
45
+ } ) ;
46
+
47
+
48
+ test ( "Exception error handling with verbose logging" , async ( t ) => {
49
+ // This test depends on the init command throwing on projects that already have a ui5.yaml
50
+
51
+ const err = await t . throwsAsync ( ui5 ( [ "init" , "--verbose" ] , {
52
+ cwd : path . join ( __dirname , ".." , ".." , ".." , "fixtures" , "init" , "application" )
53
+ } ) ) ;
54
+
55
+ const stdoutLines = err . stdout . split ( "\n" ) ;
56
+ t . deepEqual ( stdoutLines [ 1 ] , "⚠️ Process Failed With Error" , "Correct error log" ) ;
57
+ t . deepEqual ( stdoutLines [ 3 ] , "Error Message:" , "Correct error log" ) ;
58
+ t . deepEqual ( stdoutLines [ 4 ] , "Initialization not possible: ui5.yaml already exists" , "Correct error log" ) ;
59
+ t . deepEqual ( stdoutLines [ 6 ] , "Stack Trace:" , "Correct error log" ) ;
60
+ t . deepEqual ( stdoutLines [ 7 ] , "Error: Initialization not possible: ui5.yaml already exists" , "Correct error log" ) ;
61
+
62
+ t . deepEqual ( stdoutLines [ stdoutLines . length - 1 ] , `If you think this is an issue of the UI5 Tooling, you might ` +
63
+ `report it using the following URL: https://github.com/SAP/ui5-cli/issues/new` ,
64
+ "Correct last log line" ) ;
65
+
66
+ t . deepEqual ( err . exitCode , 1 , "Process was exited with code 1" ) ;
67
+ } ) ;
0 commit comments