-
Notifications
You must be signed in to change notification settings - Fork 412
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
Webpack does not run before tests with serverless-jest-plugin #143
Comments
Can you post the |
Thanks @HyperBrain this is the order of plugins.
|
It's a bit tricky to reproduce this error, since you'd have to compare the jest test run results to that of a deployed function.
The test runner will not catch this error, which implies that webpack is not running before the tests. |
Did you try to reverse the order of the plugins already, so that webpack comes before jest? The reason I ask, is that Serverless executes the plugin integrations exactly in the order how they are specified in the serverless.yml. If a reverse order does not help, I will try to check the sources of the jest plugin and see how exactly it integrates with serverless. |
@HyperBrain Yes I've tried both orders, the results are the same. Webpack seems to not be running before the test suite. Thanks in advance. |
Then this is definitively a bug (although I'm not sure where - in the jest plugin or here) that has to be fixed after a deeper analysis. I'll compare the hooks that are used by both plugins and check if the hooks can be adjusted in one of the plugins to make it work with a well-defined execution order. |
Just thought about easier reproduction steps. It should be reproducible, if you use e.g. Node 4 and include some ES6 code, that is not understood natively by the Node version. Maybe using the "import and export" syntax or destructuring should do the trick (see https://kangax.github.io/compat-table/es6/) |
@hassankhan Yes, you're right. The jest plugin commands do not trigger A possible solution would be to change the jest plugin's lifecycle as follows here. Or in the first event run through with all commands:
Then the test function created here could be built from the function compiled with Webpack I'm not sure if the whole package lifecycle has to be started or the compileFunctions would be sufficient. For an initial test I would go with the package. So this is not anything that can be solved here, but has to be solved in the jest plugin. |
At @EndemolShineGroup, we only have integration tests for our handler functions. We keep the handlers as thin as possible, and shift logic to a To run the tests, we invoke Jest directly. For integration tests, we deploy before (since we need an environment to actually test in). We find that running any sort of integration tests locally tends to mostly be a waste of time because of all the various differences between a Lambda environment and a local developer environment (different Node versions, no Cognito auth support, how to test SNS lambdas etc.). Of course, this does mean a bit of extra setup and some attention-to-detail when setting up the CI/CD pipeline but it can definitely be done 👍 . What I'm trying to say is ... maybe you can give it a go without the plugin, @lpgeiger 😄 |
@HyperBrain thanks for identifying this. Are there ANY serverless test suites that would work out of the box? @hassankhan thanks for the input.
Yes that's what I'm finding. It seems strange that none of the local emulation solutions package the correct target runtime. |
@lpgeiger Maybe mocha-webpack would work for the unit tests - you can specify a webpack config. I did not find nor do I know anything that directly integrates with Serverless. |
I'll remove the bug tag, as it is obviously no bug for this project. I'll close it as soon as the discussion in here has been finalized - feel free to continue discussing even after that 😄 |
@HyperBrain Thanks for looking into it. I'm not familiar with the serverless plugin system. Can you give me a hint about how one might implement a hook into 'serverless-webpack' the test runner I'm using: 'serverless-jest-plugin' ? Thanks in advance, |
@HyperBrain I See that the issues is fixed in serverless-webpack, it seems to work in my tests. Can you confirm that your implementation is working too? Thanks in advance! |
@lpgeiger Just saw that there were fixes done in the SC5 plugins (mocha plugin). I'm not sure if I can double check it in the next days. Good, if it works for you. Maybe someone else can try it too. |
I'll close this one for now. There was no additional feedback for a long time. |
This is a Documentation issue
Description
(I'm assuming this is a documentation issue, but it may be a feature if this case has not been contemplated.)
I'm trying to ensure that webpack runs before the testing plugin. Currently I'm using the https://github.com/SC5/serverless-jest-plugin
It appears tests are running the uncompiled code. This means I'm not catching all the syntax errors lambda runtime does not support.
Reproduction
It's a bit tricky to reproduce this error, since you'd have to compare the jest test run results to that of a deployed function.
You can break the webpack integration by breaking the config file :
The test runner will not catch this error, which implies that webpack is not running before the tests.
The only way to catch this is by running
serverless webpack serve
Additional Data
package.json
serverles.yml
The text was updated successfully, but these errors were encountered: