@@ -9,25 +9,33 @@ const tempDir = os.tmpdir()+`/${packageName}-staging`;
9
9
// const { packument } = require('pacote');
10
10
// const versions = await packument(packageName);
11
11
// cases = ['', 'latest', '-r=7.3.0', ...Object.keys(versions)];
12
- const all_versions = [ '0.0.1' , '5.3.0' ,
13
- '6.0.0' , '6.0.1' ,
14
- '6.1.0' , '7.0.0' ,
15
- '7.0.1' , '7.1.0' ,
16
- '7.2.0' , '7.3.0' ] ;
12
+ const all_versions = [
13
+ '0.0.1' ,
14
+ '5.3.0' ,
15
+ '6.0.0' ,
16
+ '6.0.1' ,
17
+ '6.1.0' ,
18
+ '7.0.0' ,
19
+ '7.0.1' ,
20
+ '7.1.0' ,
21
+ '7.2.0' ,
22
+ '7.3.0'
23
+ ] ;
17
24
const cases = [ '-r=7.2.0' , '-r=v7.2.0' , '-r=v7.2' , '--release=7.3.0' , ...all_versions . map ( v => '-r=' + v ) ] ;
25
+
26
+ const runCli = async ( version ) => { //TODO: blank output
27
+ process . argv . push ( `./out/${ version } ` ) ;
28
+ if ( version ) {
29
+ process . argv . push ( version )
30
+ }
31
+ await cli ( ) ;
32
+ process . argv = process . argv . filter ( v => v !== version && v !== `./out/${ version } ` ) ; //revert process args
33
+ }
18
34
describe . each ( cases ) (
19
35
"Downloading %s" ,
20
36
( version ) => {
21
37
beforeAll ( async ( ) => {
22
- jest . spyOn ( process , 'exit' ) . mockImplementationOnce ( ( ) => {
23
- throw new Error ( 'process.exit() was called.' + version )
24
- } ) ;
25
- process . argv . push ( `./out/${ version } ` ) ;
26
- if ( version ) {
27
- process . argv . push ( version )
28
- }
29
- await cli ( ) ;
30
- process . argv = process . argv . filter ( v => v !== version && v !== `./out/${ version } ` ) ; //revert process args
38
+ await runCli ( version ) ;
31
39
} ) ;
32
40
afterAll ( async ( ) => {
33
41
await fs . remove ( `./out/${ version } ` ) ;
@@ -62,11 +70,16 @@ describe.each(cases)(
62
70
} ) ;
63
71
}
64
72
) ;
65
- // test('Attempt 1', async() => {
66
- // const spy = jest.spyOn(console, 'log');
67
73
68
- // expect(() => {
69
- // }).toThrow('process.exit() was called.');
70
- // expect(spy.mock.calls).toEqual([['Testing...']]);
71
- // expect(process.exit).toHaveBeenCalledWith(0);
72
- // });
74
+ describe ( "Errors" , ( ) => {
75
+ test ( "wrong version 6..2.3" , async ( ) => {
76
+ const mockExit = jest . spyOn ( process , 'exit' ) . mockImplementation ( ( ) => { } ) ;
77
+ const version = '-r=6..2.3' ;
78
+
79
+ await runCli ( version ) ;
80
+
81
+ await fs . remove ( `./out/${ version } ` ) ;
82
+ expect ( mockExit ) . toHaveBeenCalledWith ( 1 ) ;
83
+ mockExit . mockRestore ( ) ;
84
+ } )
85
+ } ) ;
0 commit comments