Skip to content

Commit

Permalink
fix(command-dev): pass full lambda-local result functions server (#2901)
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah authored Jul 11, 2021
1 parent bbb78bd commit c68efb2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/functions/runtimes/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ const invokeFunction = async ({ context, event, func, timeout }) => {
// If a function builder has defined a `buildPath` property, we use it.
// Otherwise, we'll invoke the function's main file.
const lambdaPath = (func.buildData && func.buildData.buildPath) || func.mainFile
const { body, statusCode } = await lambdaLocal.execute({
const result = await lambdaLocal.execute({
clientContext: context,
event,
lambdaPath,
timeoutMs: timeout * SECONDS_TO_MILLISECONDS,
verboseLevel: 3,
})

return { body, statusCode }
return result
}

const onDirectoryScan = async () => {
Expand Down
23 changes: 23 additions & 0 deletions tests/command.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1780,5 +1780,28 @@ export const handler = async function () {
})
})
})

test(testName(`returns headers set by function`, args), async (t) => {
await withSiteBuilder('site-with-function-with-custom-headers', async (builder) => {
await builder
.withFunction({
pathPrefix: 'netlify/functions',
path: 'custom-headers.js',
handler: async () => ({
statusCode: 200,
body: '',
headers: { 'single-value-header': 'custom-value' },
multiValueHeaders: { 'multi-value-header': ['custom-value1', 'custom-value2'] },
}),
})
.buildAsync()

await withDevServer({ cwd: builder.directory, args }, async (server) => {
const response = await got(`${server.url}/.netlify/functions/custom-headers`)
t.is(response.headers['single-value-header'], 'custom-value')
t.is(response.headers['multi-value-header'], 'custom-value1, custom-value2')
})
})
})
})
/* eslint-enable require-await */

1 comment on commit c68efb2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 330 MB

Please sign in to comment.