File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { readJSON } from 'fs-extra'
2
+ import mock from 'mock-fs'
3
+ import { join } from 'pathe'
4
+ import { NEXT_PLUGIN_NAME } from '../packages/runtime/src/constants'
5
+ import { writeFunctionConfiguration } from '../packages/runtime/src/helpers/utilities/functions'
6
+
7
+ describe ( 'writeFunctionConfiguration' , ( ) => {
8
+ beforeEach ( ( ) => {
9
+ mock ( {
10
+ '.netlify/plugins/package.json' : JSON . stringify ( {
11
+ name : 'test' ,
12
+ version : '1.0.0' ,
13
+ dependencies : {
14
+ '@netlify/plugin-nextjs' : '1.0.0' ,
15
+ } ,
16
+ } ) ,
17
+ '.netlify/functions/some-folder/someFunctionName/someFunctionName.json' : '' ,
18
+ } )
19
+ } )
20
+
21
+ afterEach ( ( ) => {
22
+ mock . restore ( )
23
+ } )
24
+
25
+ it ( 'should write the configuration for a function' , async ( ) => {
26
+ const functionName = 'someFunctionName'
27
+ const functionTitle = 'some function title'
28
+ const functionsDir = '.netlify/functions/some-folder'
29
+ const nextPluginVersion = '1.0.0'
30
+
31
+ const expected = {
32
+ config : {
33
+ name : functionTitle ,
34
+ generator : nextPluginVersion ? `${ NEXT_PLUGIN_NAME } @${ nextPluginVersion } ` : 'Next Runtime Version Not Found' ,
35
+ } ,
36
+ version : 1 ,
37
+ }
38
+
39
+ const filePathToSaveTo = join ( functionsDir , functionName , `${ functionName } .json` )
40
+ await writeFunctionConfiguration ( functionName , functionTitle , functionsDir )
41
+ const actual = await readJSON ( filePathToSaveTo )
42
+
43
+ expect ( actual ) . toEqual ( expected )
44
+ } )
45
+ } )
You can’t perform that action at this time.
0 commit comments