Skip to content

Commit

Permalink
fix(deps): update dependency lambda-local to v2.0.2 (#4443)
Browse files Browse the repository at this point in the history
* fix(deps): update dependency lambda-local to v2.0.2

* chore: update contributors field

* feat: update to correctly mirror synchronous execution (closes #4304)

* chore: update contributors field

* chore: update contributors field

* fix: format

* chore: update contributors field

* chore: update contributors field

* fix: tests

* chore: update contributors field

* chore: update contributors field

* fix: another test

* chore: update contributors field

* fix: another test

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: renovate[bot] <renovate[bot]@users.noreply.github.com>
Co-authored-by: Netlify Team Account 1 <netlify-team-account-1@users.noreply.github.com>
Co-authored-by: Skn0tt <Skn0tt@users.noreply.github.com>
Co-authored-by: token-generator-app[bot] <token-generator-app[bot]@users.noreply.github.com>
Co-authored-by: Simon Knott <info@simonknott.de>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
  • Loading branch information
10 people authored Apr 8, 2022
1 parent 84fa9f6 commit 1fd0c2c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 47 deletions.
54 changes: 13 additions & 41 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"Sergii Zinkevych",
"Shawn Erquhart <shawn@erquh.art>",
"Shawn Makinson (http://smakinson.github.io)",
"Simon Knott <info@simonknott.de> (https://twitter.com/skn0tt)",
"Souma Suzuki <subayai.kobashiri@gmail.com>",
"Sébastien Chopin <seb@nuxtjs.com> (https://twitter.com/Atinux)",
"Takumi Hirunuma <m.111_t.1230_nittc@outlook.com> (https://twitter.com/mg111_)",
Expand Down
5 changes: 5 additions & 0 deletions src/lib/functions/synchronous.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ const validateLambdaResponse = (lambdaResponse) => {
if (lambdaResponse === undefined) {
return { error: 'lambda response was undefined. check your function code again' }
}
if (lambdaResponse === null) {
return {
error: 'no lambda response. check your function code again. make sure to return a promise or use the callback.',
}
}
if (!Number(lambdaResponse.statusCode)) {
return {
error: `Your function response must have a numerical statusCode. You gave: $ ${lambdaResponse.statusCode}`,
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/20.command.functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ test('should serve helpful tips and tricks', async (t) => {
content: `
const { schedule } = require('@netlify/functions')
module.exports.handler = schedule('@daily', () => {
module.exports.handler = schedule('@daily', async () => {
return {
statusCode: 200,
body: "hello world"
Expand Down Expand Up @@ -684,7 +684,7 @@ test('should emulate next_run for scheduled functions', async (t) => {
path: 'functions/hello-world.js',
content: `
const { schedule } = require('@netlify/functions')
module.exports.handler = schedule("@daily", (event) => {
module.exports.handler = schedule("@daily", async (event) => {
const { next_run } = JSON.parse(event.body)
return {
statusCode: !!next_run ? 200 : 400,
Expand Down Expand Up @@ -748,7 +748,7 @@ test('should detect file changes to scheduled function', async (t) => {
.withContentFile({
path: 'functions/hello-world.js',
content: `
module.exports.handler = () => {
module.exports.handler = async () => {
return {
statusCode: 200
}
Expand All @@ -772,7 +772,7 @@ test('should detect file changes to scheduled function', async (t) => {
content: `
const { schedule } = require('@netlify/functions')
module.exports.handler = schedule("@daily", () => {
module.exports.handler = schedule("@daily", async () => {
return {
statusCode: 200,
body: "test"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/330.serving-functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ testMatrix.forEach(({ args }) => {
path: 'functions/hello/index.js',
content: `
const response = require("./dist")
exports.handler = () => ({
exports.handler = async () => ({
statusCode: 200,
body: response
})`,
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/400.command.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ testMatrix.forEach(({ args }) => {
})
})

test(testName('should replicate Lambda behaviour for synchronous return values', args), async (t) => {
await withSiteBuilder('site-replicate-aws-sync-behaviour', async (builder) => {
builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withFunction({
path: 'env.js',
handler: () => ({
statusCode: 200,
}),
})

await builder.buildAsync()

await withDevServer({ cwd: builder.directory, args }, async (server) => {
const response = await got(`${server.url}/.netlify/functions/env`, {
throwHttpErrors: false,
})
t.true(response.body.startsWith('no lambda response.'))
})
})
})

test(testName('should redirect using a wildcard when set in netlify.toml', args), async (t) => {
await withSiteBuilder('site-with-redirect-function', async (builder) => {
builder
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/functions/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test.before(async () => {
mkdirSync(functionsDirectory)

const mainFile = join(functionsDirectory, 'hello.js')
writeFileSync(mainFile, `exports.handler = (event) => ({ statusCode: 200, body: event.rawUrl })`)
writeFileSync(mainFile, `exports.handler = async (event) => ({ statusCode: 200, body: event.rawUrl })`)

const functionsRegistry = new FunctionsRegistry({
projectRoot,
Expand Down

1 comment on commit 1fd0c2c

@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: 380 MB

Please sign in to comment.