Skip to content

Commit

Permalink
fix: use correct parameters in callback syntax (#4)
Browse files Browse the repository at this point in the history
* fix: use correct parameters in callback syntax

* chore: fix eslint paths
  • Loading branch information
eduardoboucas authored Feb 22, 2021
1 parent 9cc96c3 commit b4154d7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test:ci:ava": "nyc -r lcovonly -r text -r json ava"
},
"config": {
"eslint": "--ignore-pattern 'README.md' --ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,scripts,.github}/**/*.{js,md,html}\" \"*.{js,md,html}\" \".*.{js,md,html}\"",
"eslint": "--ignore-pattern README.md --ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,scripts,.github}/**/*.{js,md,html}\" \"*.{js,md,html}\" \".*.{js,md,html}\"",
"prettier": "--ignore-path .gitignore --loglevel=warn \"{src,scripts,.github}/**/*.{js,md,yml,json,html}\" \"*.{js,yml,json,html}\" \".*.{js,yml,json,html}\" \"!**/package-lock.json\" \"!package-lock.json\""
},
"ava": {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/builder_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const wrapHandler = (handler) => async (event, context, callback) => {
}

// eslint-disable-next-line promise/prefer-await-to-callbacks
const wrappedCallback = (response) => callback(augmentResponse(response))
const wrappedCallback = (error, response) => callback(error, augmentResponse(response))
const response = await handler(event, context, wrappedCallback)

return augmentResponse(response)
Expand Down
2 changes: 1 addition & 1 deletion test/builder_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test('Injects the metadata object into a synchronous handler', async (t) => {
statusCode: 200,
}
const myHandler = (event, context, callback) => {
callback(originalResponse)
callback(null, originalResponse)
}
const response = await invokeLambda(builderFunction(myHandler))

Expand Down
12 changes: 10 additions & 2 deletions test/helpers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ const invokeLambda = (handler, { method = 'GET' } = {}) => {
httpMethod: method,
}

return new Promise((resolve) => {
resolve(handler(event, {}, resolve))
return new Promise((resolve, reject) => {
const callback = (error, response) => {
if (error) {
reject(error)
} else {
resolve(response)
}
}

resolve(handler(event, {}, callback))
})
}

Expand Down

0 comments on commit b4154d7

Please sign in to comment.