Skip to content

Commit

Permalink
fix: only add cache to manifest if set
Browse files Browse the repository at this point in the history
also add a new test for the order of internal functions
  • Loading branch information
danez committed Mar 21, 2023
1 parent fc5091a commit 2871a93
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
38 changes: 38 additions & 0 deletions node/__snapshots__/declaration.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Deploy config takes precedence over user config 1`] = `
[
{
"function": "user-a",
"path": "/path1",
},
{
"function": "user-b",
"path": "/path2",
},
{
"function": "framework-a",
"path": "/path1",
},
{
"function": "framework-b",
"path": "/path2",
},
{
"function": "user-c",
"path": "/path1",
},
{
"function": "user-c",
"path": "/path2",
},
{
"function": "framework-c",
"path": "/path1",
},
{
"function": "framework-c",
"path": "/path2",
},
]
`;
20 changes: 19 additions & 1 deletion node/declaration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@ import { test, expect } from 'vitest'
import { FunctionConfig } from './config.js'
import { Declaration, mergeDeclarations } from './declaration.js'

// TODO: Add tests with the deploy config.
const deployConfigDeclarations: Declaration[] = []

test('Deploy config takes precedence over user config', () => {
const deployConfigDeclarations: Declaration[] = [
{ function: 'framework-a', path: '/path1' },
{ function: 'framework-b', path: '/path2' },
]

const tomlConfig: Declaration[] = [
{ function: 'user-a', path: '/path1' },
{ function: 'user-b', path: '/path2' },
]

const funcConfig = {
'user-c': { path: ['/path1', '/path2'] },
'framework-c': { path: ['/path1', '/path2'] },
} as Record<string, FunctionConfig>

expect(mergeDeclarations(tomlConfig, funcConfig, deployConfigDeclarations)).toMatchSnapshot()
})

test('In-source config takes precedence over netlify.toml config', () => {
const tomlConfig: Declaration[] = [
{ function: 'geolocation', path: '/geo', cache: 'off' },
Expand Down
6 changes: 5 additions & 1 deletion node/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ export const mergeDeclarations = (
const paths = Array.isArray(path) ? path : [path]

paths.forEach((singlePath) => {
declarations.push({ cache, function: name, path: singlePath })
const declaration: Declaration = { function: name, path: singlePath }
if (cache) {
declaration.cache = cache
}
declarations.push(declaration)
})
}
}
Expand Down

0 comments on commit 2871a93

Please sign in to comment.