@@ -4,6 +4,7 @@ const process = require('process')
44const os = require ( 'os' )
55const cpy = require ( 'cpy' )
66const { dir : getTmpDir } = require ( 'tmp-promise' )
7+ const { downloadFile } = require ( '../src/templates/handlerUtils' )
78
89const plugin = require ( '../src' )
910
@@ -186,8 +187,10 @@ describe('onBuild()', () => {
186187
187188 expect ( existsSync ( `.netlify/internal-functions/___netlify-handler/___netlify-handler.js` ) ) . toBeTruthy ( )
188189 expect ( existsSync ( `.netlify/internal-functions/___netlify-handler/bridge.js` ) ) . toBeTruthy ( )
190+ expect ( existsSync ( `.netlify/internal-functions/___netlify-handler/handlerUtils.js` ) ) . toBeTruthy ( )
189191 expect ( existsSync ( `.netlify/internal-functions/___netlify-odb-handler/___netlify-odb-handler.js` ) ) . toBeTruthy ( )
190192 expect ( existsSync ( `.netlify/internal-functions/___netlify-odb-handler/bridge.js` ) ) . toBeTruthy ( )
193+ expect ( existsSync ( `.netlify/internal-functions/___netlify-odb-handler/handlerUtils.js` ) ) . toBeTruthy ( )
191194 } )
192195
193196 test ( 'writes correct redirects to netlifyConfig' , async ( ) => {
@@ -448,3 +451,37 @@ describe('utility functions', () => {
448451 }
449452 } )
450453} )
454+
455+ describe ( 'function helpers' , ( ) => {
456+ it ( 'downloadFile can download a file' , async ( ) => {
457+ const url =
458+ 'https://raw.githubusercontent.com/netlify/netlify-plugin-nextjs/c2668af24a78eb69b33222913f44c1900a3bce23/manifest.yml'
459+ const tmpFile = join ( os . tmpdir ( ) , 'next-test' , 'downloadfile.txt' )
460+ await ensureDir ( path . dirname ( tmpFile ) )
461+ await downloadFile ( url , tmpFile )
462+ expect ( existsSync ( tmpFile ) ) . toBeTruthy ( )
463+ expect ( readFileSync ( tmpFile , 'utf8' ) ) . toMatchInlineSnapshot ( `
464+ "name: netlify-plugin-nextjs-experimental
465+ "
466+ ` )
467+ await unlink ( tmpFile )
468+ } )
469+
470+ it ( 'downloadFile throws on bad domain' , async ( ) => {
471+ const url = 'https://nonexistentdomain.example'
472+ const tmpFile = join ( os . tmpdir ( ) , 'next-test' , 'downloadfile.txt' )
473+ await ensureDir ( path . dirname ( tmpFile ) )
474+ await expect ( downloadFile ( url , tmpFile ) ) . rejects . toThrowErrorMatchingInlineSnapshot (
475+ `"getaddrinfo ENOTFOUND nonexistentdomain.example"` ,
476+ )
477+ } )
478+
479+ it ( 'downloadFile throws on 404' , async ( ) => {
480+ const url = 'https://example.com/nonexistentfile'
481+ const tmpFile = join ( os . tmpdir ( ) , 'next-test' , 'downloadfile.txt' )
482+ await ensureDir ( path . dirname ( tmpFile ) )
483+ await expect ( downloadFile ( url , tmpFile ) ) . rejects . toThrowError (
484+ 'Failed to download https://example.com/nonexistentfile: 404 Not Found' ,
485+ )
486+ } )
487+ } )
0 commit comments