@@ -5,34 +5,93 @@ import { NEXT_PLUGIN_NAME } from '../packages/runtime/src/constants'
5
5
import { writeFunctionConfiguration } from '../packages/runtime/src/helpers/utilities/functions'
6
6
7
7
describe ( 'writeFunctionConfiguration' , ( ) => {
8
- const nextRuntimeVersion = '29.3.4'
8
+ afterEach ( ( ) => {
9
+ mock . restore ( )
10
+ } )
11
+
12
+ it ( 'should write the configuration for a function using node modules version of @netlify/plugin-nextjs' , async ( ) => {
13
+ const nextRuntimeVersion = '23.4.5'
9
14
10
- beforeEach ( ( ) => {
11
15
mock ( {
12
16
'.netlify/plugins/package.json' : JSON . stringify ( {
13
17
name : 'test' ,
14
18
version : '1.0.0' ,
15
19
dependencies : {
16
- '@netlify/plugin-nextjs' : nextRuntimeVersion ,
20
+ '@netlify/plugin-nextjs' : '29.3.4' ,
17
21
} ,
18
22
} ) ,
23
+ 'node_modules/@netlify/plugin-nextjs/package.json' : JSON . stringify ( {
24
+ name : '@netlify/plugin-nextjs' ,
25
+ version : nextRuntimeVersion ,
26
+ } ) ,
19
27
'.netlify/functions/some-folder/someFunctionName/someFunctionName.json' : '' ,
20
28
} )
29
+
30
+ const functionName = 'someFunctionName'
31
+ const functionTitle = 'some function title'
32
+ const functionsDir = '.netlify/functions/some-folder'
33
+
34
+ const expected = {
35
+ config : {
36
+ name : functionTitle ,
37
+ generator : `${ NEXT_PLUGIN_NAME } @${ nextRuntimeVersion } ` ,
38
+ } ,
39
+ version : 1 ,
40
+ }
41
+
42
+ const filePathToSaveTo = join ( functionsDir , functionName , `${ functionName } .json` )
43
+ await writeFunctionConfiguration ( functionName , functionTitle , functionsDir )
44
+ const actual = await readJSON ( filePathToSaveTo )
45
+
46
+ expect ( actual ) . toEqual ( expected )
21
47
} )
22
48
23
- afterEach ( ( ) => {
24
- mock . restore ( )
49
+ it ( 'should write the configuration for a function using version of @netlify/plugin-nextjs in package.json' , async ( ) => {
50
+ const nextRuntimeVersion = '23.4.5'
51
+
52
+ mock ( {
53
+ '.netlify/plugins/package.json' : JSON . stringify ( {
54
+ name : 'test' ,
55
+ version : '1.0.0' ,
56
+ dependencies : {
57
+ '@netlify/plugin-nextjs' : nextRuntimeVersion ,
58
+ } ,
59
+ } ) ,
60
+ '.netlify/functions/some-folder/someFunctionName/someFunctionName.json' : '' ,
61
+ } )
62
+
63
+ const functionName = 'someFunctionName'
64
+ const functionTitle = 'some function title'
65
+ const functionsDir = '.netlify/functions/some-folder'
66
+
67
+ const expected = {
68
+ config : {
69
+ name : functionTitle ,
70
+ generator : `${ NEXT_PLUGIN_NAME } @${ nextRuntimeVersion } ` ,
71
+ } ,
72
+ version : 1 ,
73
+ }
74
+
75
+ const filePathToSaveTo = join ( functionsDir , functionName , `${ functionName } .json` )
76
+ await writeFunctionConfiguration ( functionName , functionTitle , functionsDir )
77
+ const actual = await readJSON ( filePathToSaveTo )
78
+
79
+ expect ( actual ) . toEqual ( expected )
25
80
} )
26
81
27
- it ( 'should write the configuration for a function' , async ( ) => {
82
+ it ( 'should write the configuration for a function with runtime version not found' , async ( ) => {
83
+ mock ( {
84
+ '.netlify/functions/some-folder/someFunctionName/someFunctionName.json' : '' ,
85
+ } )
86
+
28
87
const functionName = 'someFunctionName'
29
88
const functionTitle = 'some function title'
30
89
const functionsDir = '.netlify/functions/some-folder'
31
90
32
91
const expected = {
33
92
config : {
34
93
name : functionTitle ,
35
- generator : nextRuntimeVersion ? ` ${ NEXT_PLUGIN_NAME } @ ${ nextRuntimeVersion } ` : 'Next Runtime Version Not Found' ,
94
+ generator : 'Next Runtime Version Not Found' ,
36
95
} ,
37
96
version : 1 ,
38
97
}
0 commit comments