-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: deep merge in source and toml config (#220)
* fix: deep merge in source and toml config
- Loading branch information
1 parent
fb8ca47
commit e2789e3
Showing
2 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { test, expect } from 'vitest' | ||
|
||
import { FunctionConfig } from './config.js' | ||
import { getDeclarationsFromConfig } from './declaration.js' | ||
|
||
test('In source config takes precedence over netlify.toml config', () => { | ||
const tomlConfig = [ | ||
{ function: 'geolocation', path: '/geo', cache: 'off' }, | ||
{ function: 'json', path: '/json', cache: 'manual' }, | ||
] | ||
|
||
const funcConfig = { | ||
geolocation: { path: '/geo-isc', cache: 'manual' }, | ||
json: { path: '/json', cache: 'off' }, | ||
} as Record<string, FunctionConfig> | ||
|
||
const expectedDeclarations = [ | ||
{ function: 'geolocation', path: '/geo-isc', cache: 'manual' }, | ||
{ function: 'json', path: '/json', cache: 'off' }, | ||
] | ||
|
||
const declarations = getDeclarationsFromConfig(tomlConfig, funcConfig) | ||
|
||
expect(declarations).toEqual(expectedDeclarations) | ||
}) | ||
|
||
test("Declarations don't break if no in source config is provided", () => { | ||
const tomlConfig = [ | ||
{ function: 'geolocation', path: '/geo', cache: 'off' }, | ||
{ function: 'json', path: '/json', cache: 'manual' }, | ||
] | ||
|
||
const funcConfig = { | ||
geolocation: { path: '/geo-isc', cache: 'manual' }, | ||
json: {}, | ||
} as Record<string, FunctionConfig> | ||
|
||
const expectedDeclarations = [ | ||
{ function: 'geolocation', path: '/geo-isc', cache: 'manual' }, | ||
{ function: 'json', path: '/json', cache: 'manual' }, | ||
] | ||
|
||
const declarations = getDeclarationsFromConfig(tomlConfig, funcConfig) | ||
|
||
expect(declarations).toEqual(expectedDeclarations) | ||
}) | ||
|
||
test('In source config works independent of the netlify.toml file if a path is defined and otherwise if no path is set', () => { | ||
const tomlConfig = [{ function: 'geolocation', path: '/geo', cache: 'off' }] | ||
|
||
const funcConfigWithPath = { | ||
json: { path: '/json', cache: 'off' }, | ||
} as Record<string, FunctionConfig> | ||
|
||
const funcConfigWithoutPath = { | ||
json: { cache: 'off' }, | ||
} as Record<string, FunctionConfig> | ||
|
||
const expectedDeclarationsWithISCPath = [ | ||
{ function: 'geolocation', path: '/geo', cache: 'off' }, | ||
{ function: 'json', path: '/json', cache: 'off' }, | ||
] | ||
|
||
const expectedDeclarationsWithoutISCPath = [{ function: 'geolocation', path: '/geo', cache: 'off' }] | ||
|
||
const declarationsWithISCPath = getDeclarationsFromConfig(tomlConfig, funcConfigWithPath) | ||
|
||
const declarationsWithoutISCPath = getDeclarationsFromConfig(tomlConfig, funcConfigWithoutPath) | ||
|
||
expect(declarationsWithISCPath).toEqual(expectedDeclarationsWithISCPath) | ||
expect(declarationsWithoutISCPath).toEqual(expectedDeclarationsWithoutISCPath) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters