Skip to content

Commit 6a57201

Browse files
committed
test: added a test for writeFunctionConfiguration
1 parent dc61d8a commit 6a57201

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/functions.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
})

0 commit comments

Comments
 (0)