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

Reference Variables in Javascript Files, Cannot find module #43

Open
timfulmer opened this issue Nov 19, 2020 · 0 comments
Open

Reference Variables in Javascript Files, Cannot find module #43

timfulmer opened this issue Nov 19, 2020 · 0 comments

Comments

@timfulmer
Copy link

Hello,

First off, thank you very much for this plugin. Makes TS serverless development with Jest very much easier. I may have an interesting corner case to bring up, though hopefully this is something simple I am doing wrong.

This all started with trying to hook a programmatic infrastructure update into the CloudFormation stack update on serverless deploy using a CFN custom resource. Worked great for the initial custom resource creation, but I wanted the update to run on subsequent deploys as well. Which lead me here:

serverless/serverless#4483

Following the excellent suggestion here:

serverless/serverless#4483 (comment)

Using serverless file variables:

https://www.serverless.com/framework/docs/providers/aws/guide/variables#reference-variables-in-javascript-files

I was able to get the updates running on every serverless deploy, which works well for the continuous development environment we are setting up with this new project. Architecture validated, time to cover with testing!

I setup a Jest test like so:

import jestPlugin from 'serverless-jest-plugin';
import * as mod from '../myCustomResource';

const { lambdaWrapper } = jestPlugin;
const wrapped = lambdaWrapper.wrap(mod, { handler: 'handler' });
...
    const response = await wrapped.run({});

However, when running in the serverless-jest-plugin environment, I am getting an error:

 ● Test suite failed to run

    Cannot find module 'uuid/v4'

    > 1 | module.exports = () => require('uuid/v4')();

Which seems to be caused by this line in the serverless.yml:

        UUID: ${file(./uuid.js)}

This error seems to be isolated to the serverless-jest-plugin environment, since it is working w/o error when running serverless deploy.

Please advise,

-- Tim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant