@@ -59,30 +59,45 @@ test('page-loader', async () => {
5959 expect ( downloadedScript ) . toBe ( 'js {}' )
6060} )
6161
62- test ( 'page-loader: network errors' , async ( ) => {
63- nock ( 'https://ru.hexlet.io' )
64- . get ( '/courses' )
65- . reply ( 404 )
66- nock ( 'https://ru.hexlet.io' )
67- . get ( '/assets/professions/nodejs.png' )
68- . reply ( 500 )
62+ const networkErrors = [
63+ {
64+ url : 'https://ru.hexlet.io/courses' ,
65+ status : 404 ,
66+ expected : 'Cant get https://ru.hexlet.io/courses - Request failed with status code 404' ,
67+ } ,
68+ {
69+ url : 'https://ru.hexlet.io/assets/professions/nodejs.png' ,
70+ status : 500 ,
71+ expected : 'Cant get https://ru.hexlet.io/assets/professions/nodejs.png - Request failed with status code 500' ,
72+ } ,
73+ ]
6974
70- await expect ( downloadPage ( 'https://ru.hexlet.io/courses' , tempDir ) )
71- . rejects
72- . toThrow ( 'Cant get https://ru.hexlet.io/courses - Request failed with status code 404' )
73- await expect ( downloadPage ( 'https://ru.hexlet.io/assets/professions/nodejs.png' , tempDir ) )
74- . rejects
75- . toThrow ( 'Cant get https://ru.hexlet.io/assets/professions/nodejs.png - Request failed with status code 500' )
76- } )
75+ test . each ( networkErrors ) ( 'page-loader: network error $status' ,
76+ async ( { url, status, expected } ) => {
77+ nock ( 'https://ru.hexlet.io' )
78+ . get ( new URL ( url ) . pathname )
79+ . reply ( status )
7780
78- test ( 'page-loader: file operation errors' , async ( ) => {
79- nock ( 'https://ru.hexlet.io' )
80- . get ( '/courses' )
81- . times ( 2 )
82- . reply ( 200 , html )
81+ await expect ( downloadPage ( url , tempDir ) ) . rejects . toThrow ( expected )
82+ } )
8383
84- await expect ( downloadPage ( 'https://ru.hexlet.io/courses' , '/unexisting' ) )
85- . rejects . toThrow ( 'ERROR: No such output directory - /unexisting' )
86- await expect ( downloadPage ( 'https://ru.hexlet.io/courses' , '/root' ) )
87- . rejects . toThrow ( 'ERROR: No access to output directory - /root' )
88- } )
84+ const fileErrors = [
85+ {
86+ path : '/unexisting' ,
87+ expected : 'ERROR: No such output directory - /unexisting' ,
88+ } ,
89+ {
90+ path : '/root' ,
91+ expected : 'ERROR: No access to output directory - /root' ,
92+ } ,
93+ ]
94+
95+ test . each ( fileErrors ) ( 'page-loader: file operation error on path $path' ,
96+ async ( { path, expected } ) => {
97+ nock ( 'https://ru.hexlet.io' )
98+ . get ( '/courses' )
99+ . reply ( 200 , html )
100+
101+ await expect ( downloadPage ( 'https://ru.hexlet.io/courses' , path ) )
102+ . rejects . toThrow ( expected )
103+ } )
0 commit comments