Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for invoke local #258

Merged
merged 5 commits into from
Jun 1, 2021

Conversation

CorentinDoue
Copy link
Contributor

@CorentinDoue CorentinDoue commented May 17, 2021

This pull request adds the implementation of the command invoke local for the google provider. It's inspired by the AWS implementation to keep the behaviors as close as possible.

The command is available for the nodejs runtimes and events of type event

Tests

Next steps

  • Add support for http events

@CorentinDoue
Copy link
Contributor Author

Screenshot from 2021-05-17 14-11-21
Screenshot from 2021-05-17 14-14-26

The failing test is caused by an unsupported for await by node 8. But node 8 is no more supported since https://github.com/serverless/serverless-google-cloudfunctions/releases/tag/v4.0.0

@pgrzesik could you remove the test with node8?

@CorentinDoue CorentinDoue marked this pull request as ready for review May 17, 2021 13:13
@CorentinDoue
Copy link
Contributor Author

@pgrzesik can you review it?

@pgrzesik
Copy link
Contributor

Hello @CorentinDoue - sorry for the delay here - I'm a bit swamped with other prorities and I'm not that familiar with this plugin's codebase, but I'll try to review it as soon as possible. Thanks for your patience 🙇

Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

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

Thanks a lot @CorentinDoue and sorry for delayed review. I'm not an expert when it comes to conventions in this repository, but overall the changes look good 👍 I only have a few minor questions/suggestions but we should be good to go soon, please let me know what do you think 🙇

.travis.yml Outdated
@@ -101,9 +101,6 @@ jobs:
- name: 'Unit Tests - Node.js v10'
node_js: 10

- name: 'Unit Tests - Node.js v8'
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove that change from this PR, I'll merge it as a separate PR 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I'll drop the commit

getDataAndContextStub = sinon
.stub(googleInvokeLocal, 'getDataAndContext')
.returns(Promise.resolve());
invokeLocalStub = sinon.stub(googleInvokeLocal, 'invokeLocal').returns(Promise.resolve());
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you can just use .resolves() instead of returns(Promise.resolve()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

let getDataAndContextStub;
let invokeLocalStub;

beforeEach(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

As the behavior does not change across tests, you can stub it once in before and only reset history after each test with .resetHistory() on stubs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

this.options[optionKey] = require(absolutePath);
return;
}
this.options[optionKey] = await this.serverless.utils.readFile(absolutePath);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it depend on the parsing functionality of readFile here? If not, then I would suggest to not use utils.readFile and use native fs to read it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to make it as iso as possible with the AWS implementation and it loads the files with this util: https://github.com/serverless/serverless/blob/d5e2baf714958c5718610659887f485f9bd161e4/lib/plugins/aws/invokeLocal/index.js#L62

provider/googleProvider.js Show resolved Hide resolved
@@ -7,7 +7,7 @@ module.exports = {
setDefaults() {
this.options.stage =
_.get(this, 'options.stage') || _.get(this, 'serverless.service.provider.stage') || 'dev';
this.options.runtime = _.get(this, 'options.runtime') || 'nodejs8';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that a safe change or it can potentially break for users that are still somehow using nodejs8?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this should have been changed in #244 which drop support for nodejs8. So a nodejs8 user who upgrades this package to 4.0.0 has to explicitly set runtime to 'nodejs8'.

So yes it's another breaking change but it is attached to the breaking change of 4.0.0

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @CorentinDoue - during release of new version I'll make sure to add that to documentation for 4.0.0 release 👍

@CorentinDoue CorentinDoue force-pushed the feat/add-invoke-local branch from 95f284d to 4ee7b24 Compare May 31, 2021 15:42
@CorentinDoue CorentinDoue requested a review from pgrzesik May 31, 2021 15:43
@CorentinDoue
Copy link
Contributor Author

CorentinDoue commented May 31, 2021

@pgrzesik I corrected or answered your remarks. It's ready for a new review

Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

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

Thank you @CorentinDoue - it looks good 👍

@pgrzesik pgrzesik changed the title Feat: add invoke local feat: Add support for invoke local Jun 1, 2021
@pgrzesik pgrzesik merged commit 9e07fed into serverless:master Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants