File tree Expand file tree Collapse file tree 3 files changed +27
-16
lines changed Expand file tree Collapse file tree 3 files changed +27
-16
lines changed Original file line number Diff line number Diff line change @@ -24,15 +24,12 @@ module.exports = async () => {
24
24
} catch ( err ) {
25
25
await fs . remove ( tempDir ) ;
26
26
if ( err . code === 'ETARGET' ) {
27
- spinner . fail ( chalk . red ( `version '${ err . wanted } ' not found in npm registry\navailable versions:` ) ) ;
28
- console . log ( err . versions . reverse ( ) . join ( ' | ' ) ) ;
29
- process . exit ( 1 ) ;
30
- } /* istanbul ignore next */ else {
31
- spinner . fail ( 'Unexpected error' ) ;
32
- console . error ( err ) ;
33
- process . exit ( - 1 ) ;
34
- } ;
35
- return ;
27
+ const msg = chalk . red ( `version '${ err . wanted } ' not found in npm registry\navailable versions:\n` )
28
+ spinner . fail ( msg + err . versions . reverse ( ) . join ( ' | ' ) ) ;
29
+ throw err . code ;
30
+ }
31
+ spinner . fail ( 'Unexpected error' ) ;
32
+ throw new Error ( err ) ;
36
33
}
37
34
await fs . copy ( tempDir + '/dist' , targetDir ) ;
38
35
await fs . remove ( tempDir ) ;
Original file line number Diff line number Diff line change 1
- require ( './cli' ) ( ) ;
1
+ require ( './cli' ) ( ) . catch ( console . error ) ;
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ const all_versions = [
24
24
const cases = [
25
25
null ,
26
26
"-r=latest" ,
27
+ "-r=7" ,
27
28
"-r=7.2.0" ,
28
29
"-r=v7.2.0" ,
29
30
"-r=v7.2" ,
@@ -112,13 +113,26 @@ describe.each(cases)("Downloading %s", (version) => {
112
113
113
114
describe ( "Errors" , ( ) => {
114
115
test ( "Wrong version 6..2.3" , async ( ) => { //maybe create test.each() for more errors scenarios
115
- const mockExit = jest . spyOn ( process , "exit" ) . mockImplementation ( ( ) => { } ) ;
116
116
const version = "-r=6..2.3" ;
117
+ try {
118
+ await runCli ( version ) ;
119
+ } catch ( err ) {
120
+ expect ( err ) . toBe ( 'ETARGET' ) ;
121
+ } finally {
122
+ await fs . remove ( versionFolder ( version ) ) ;
123
+ }
124
+ } ) ;
125
+ } ) ;
117
126
118
- await runCli ( version ) ;
119
-
120
- await fs . remove ( versionFolder ( version ) ) ;
121
- expect ( mockExit ) . toHaveBeenCalledWith ( 1 ) ;
122
- mockExit . mockRestore ( ) ;
127
+ describe ( "Unexpected errors" , ( ) => {
128
+ test ( "Unexpected error 6..2.3,7.2.3" , async ( ) => { //maybe create test.each() for more errors scenarios
129
+ const version = "-r=6..2.3,7.2.3" ;
130
+ try {
131
+ await runCli ( version ) ;
132
+ } catch ( err ) {
133
+ expect ( err ) . not . toBe ( 'ETARGET' ) ;
134
+ } finally {
135
+ await fs . remove ( versionFolder ( version ) ) ;
136
+ }
123
137
} ) ;
124
138
} ) ;
You can’t perform that action at this time.
0 commit comments