Skip to content

Commit 1fd0c2c

Browse files
renovate[bot]renovate-botnetlify-team-account-1Skn0tttoken-generator-app[bot]
authored
fix(deps): update dependency lambda-local to v2.0.2 (#4443)
* 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 <[email protected]> Co-authored-by: renovate[bot] <renovate[bot]@users.noreply.github.com> Co-authored-by: Netlify Team Account 1 <[email protected]> Co-authored-by: Skn0tt <[email protected]> Co-authored-by: token-generator-app[bot] <token-generator-app[bot]@users.noreply.github.com> Co-authored-by: Simon Knott <[email protected]> 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 <[email protected]>
1 parent 84fa9f6 commit 1fd0c2c

File tree

7 files changed

+45
-47
lines changed

7 files changed

+45
-47
lines changed

npm-shrinkwrap.json

Lines changed: 13 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"Sergii Zinkevych",
111111
"Shawn Erquhart <[email protected]>",
112112
"Shawn Makinson (http://smakinson.github.io)",
113+
"Simon Knott <[email protected]> (https://twitter.com/skn0tt)",
113114
"Souma Suzuki <[email protected]>",
114115
"Sébastien Chopin <[email protected]> (https://twitter.com/Atinux)",
115116
"Takumi Hirunuma <[email protected]> (https://twitter.com/mg111_)",

src/lib/functions/synchronous.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ const validateLambdaResponse = (lambdaResponse) => {
7979
if (lambdaResponse === undefined) {
8080
return { error: 'lambda response was undefined. check your function code again' }
8181
}
82+
if (lambdaResponse === null) {
83+
return {
84+
error: 'no lambda response. check your function code again. make sure to return a promise or use the callback.',
85+
}
86+
}
8287
if (!Number(lambdaResponse.statusCode)) {
8388
return {
8489
error: `Your function response must have a numerical statusCode. You gave: $ ${lambdaResponse.statusCode}`,

tests/integration/20.command.functions.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ test('should serve helpful tips and tricks', async (t) => {
625625
content: `
626626
const { schedule } = require('@netlify/functions')
627627
628-
module.exports.handler = schedule('@daily', () => {
628+
module.exports.handler = schedule('@daily', async () => {
629629
return {
630630
statusCode: 200,
631631
body: "hello world"
@@ -684,7 +684,7 @@ test('should emulate next_run for scheduled functions', async (t) => {
684684
path: 'functions/hello-world.js',
685685
content: `
686686
const { schedule } = require('@netlify/functions')
687-
module.exports.handler = schedule("@daily", (event) => {
687+
module.exports.handler = schedule("@daily", async (event) => {
688688
const { next_run } = JSON.parse(event.body)
689689
return {
690690
statusCode: !!next_run ? 200 : 400,
@@ -748,7 +748,7 @@ test('should detect file changes to scheduled function', async (t) => {
748748
.withContentFile({
749749
path: 'functions/hello-world.js',
750750
content: `
751-
module.exports.handler = () => {
751+
module.exports.handler = async () => {
752752
return {
753753
statusCode: 200
754754
}
@@ -772,7 +772,7 @@ test('should detect file changes to scheduled function', async (t) => {
772772
content: `
773773
const { schedule } = require('@netlify/functions')
774774
775-
module.exports.handler = schedule("@daily", () => {
775+
module.exports.handler = schedule("@daily", async () => {
776776
return {
777777
statusCode: 200,
778778
body: "test"

tests/integration/330.serving-functions.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ testMatrix.forEach(({ args }) => {
510510
path: 'functions/hello/index.js',
511511
content: `
512512
const response = require("./dist")
513-
exports.handler = () => ({
513+
exports.handler = async () => ({
514514
statusCode: 200,
515515
body: response
516516
})`,

tests/integration/400.command.dev.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,26 @@ testMatrix.forEach(({ args }) => {
137137
})
138138
})
139139

140+
test(testName('should replicate Lambda behaviour for synchronous return values', args), async (t) => {
141+
await withSiteBuilder('site-replicate-aws-sync-behaviour', async (builder) => {
142+
builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withFunction({
143+
path: 'env.js',
144+
handler: () => ({
145+
statusCode: 200,
146+
}),
147+
})
148+
149+
await builder.buildAsync()
150+
151+
await withDevServer({ cwd: builder.directory, args }, async (server) => {
152+
const response = await got(`${server.url}/.netlify/functions/env`, {
153+
throwHttpErrors: false,
154+
})
155+
t.true(response.body.startsWith('no lambda response.'))
156+
})
157+
})
158+
})
159+
140160
test(testName('should redirect using a wildcard when set in netlify.toml', args), async (t) => {
141161
await withSiteBuilder('site-with-redirect-function', async (builder) => {
142162
builder

tests/unit/lib/functions/server.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test.before(async () => {
1818
mkdirSync(functionsDirectory)
1919

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

2323
const functionsRegistry = new FunctionsRegistry({
2424
projectRoot,

0 commit comments

Comments
 (0)