@@ -9,25 +9,33 @@ const tempDir = os.tmpdir()+`/${packageName}-staging`;
99// const { packument } = require('pacote');
1010// const versions = await packument(packageName);
1111// 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+ ] ;
1724const 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+ }
1834describe . each ( cases ) (
1935 "Downloading %s" ,
2036 ( version ) => {
2137 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 ) ;
3139 } ) ;
3240 afterAll ( async ( ) => {
3341 await fs . remove ( `./out/${ version } ` ) ;
@@ -62,11 +70,16 @@ describe.each(cases)(
6270 } ) ;
6371 }
6472 ) ;
65- // test('Attempt 1', async() => {
66- // const spy = jest.spyOn(console, 'log');
6773
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