Skip to content

Commit 082704f

Browse files
committed
test: added more tests for writeFunctionConfiguration
1 parent db3051f commit 082704f

File tree

1 file changed

+66
-7
lines changed

1 file changed

+66
-7
lines changed

test/functions.spec.ts

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,93 @@ import { NEXT_PLUGIN_NAME } from '../packages/runtime/src/constants'
55
import { writeFunctionConfiguration } from '../packages/runtime/src/helpers/utilities/functions'
66

77
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'
914

10-
beforeEach(() => {
1115
mock({
1216
'.netlify/plugins/package.json': JSON.stringify({
1317
name: 'test',
1418
version: '1.0.0',
1519
dependencies: {
16-
'@netlify/plugin-nextjs': nextRuntimeVersion,
20+
'@netlify/plugin-nextjs': '29.3.4',
1721
},
1822
}),
23+
'node_modules/@netlify/plugin-nextjs/package.json': JSON.stringify({
24+
name: '@netlify/plugin-nextjs',
25+
version: nextRuntimeVersion,
26+
}),
1927
'.netlify/functions/some-folder/someFunctionName/someFunctionName.json': '',
2028
})
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)
2147
})
2248

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)
2580
})
2681

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+
2887
const functionName = 'someFunctionName'
2988
const functionTitle = 'some function title'
3089
const functionsDir = '.netlify/functions/some-folder'
3190

3291
const expected = {
3392
config: {
3493
name: functionTitle,
35-
generator: nextRuntimeVersion ? `${NEXT_PLUGIN_NAME}@${nextRuntimeVersion}` : 'Next Runtime Version Not Found',
94+
generator: 'Next Runtime Version Not Found',
3695
},
3796
version: 1,
3897
}

0 commit comments

Comments
 (0)