nordcloud / serverless-mocha-plugin

Plugin for Serverless Framework which adds support for test-driven development using Mocha
MIT License
159 stars 50 forks source link

TypeError: Cannot read property 'handler' of undefined #143

Open thg303 opened 3 years ago

thg303 commented 3 years ago

I install the plugin using: serverless plugin install --name serverless-mocha when I try to create a function like this: sls create function -f testFunction --handler src/functions/testFunction.testFunction -p src/tests/

I get the following result:

Serverless: Deprecation warning: CLI options definitions were upgraded with "type" property (which could be one of "string", "boolean", "multiple"). Below listed plugins do not predefine type for introduced options:
             - mochaPlugin for "function", "path", "handler", "httpEvent", "reporter", "reporter-options", "grep", "live", "root", "compilers", "timeout", "exit"
            Please report this issue in plugin issue tracker.
            Starting with next major release, this will be communicated with a thrown error.
            More Info: https://www.serverless.com/framework/docs/deprecations/#CLI_OPTIONS_SCHEMA
Serverless: Generating function...
Serverless: Created function file "/Users/ali/projects/serverless-crm/src/functions/testFunction.js"

 Type Error ----------------------------------------------

  TypeError: Cannot read property 'handler' of undefined
      at mochaPlugin.createTest (/Users/ali/projects/serverless-crm/node_modules/serverless-mocha/index.js:367:31)
      at PluginManager.invoke (/Users/ali/.nvm/versions/node/v14.16.1/lib/node_modules/serverless/lib/classes/PluginManager.js:551:20)

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              14.16.1
     Framework Version:         2.35.0
     Plugin Version:            4.5.3
     SDK Version:               4.2.2
     Components Version:        3.8.3

It creates the function file at src/functions/testFunction.testFunction.js but the serverless.yaml file changes are:

  undefined:
    handler: src/functions/testFunction.testFunction

and no test file is generated.

mjoey commented 3 years ago

Hi, Use the 1.83.0 serverless version. npm install -g serverless@1.83.0 Best

thg303 commented 3 years ago

It's Strange, but I managed to make it work by using --function instead of -f like this:

sls create function --function testFunction --handler src/functions/testFunction.testFunction -p src/tests/
mjoey commented 3 years ago

Yes it works :) Great!

medikoo commented 3 years ago

Should be fixed with https://github.com/nordcloud/serverless-mocha-plugin/pull/151

@tdi this plugin seems to miss types for CLI options it defines, such functionality was at some point added with v2 of Serverless Framework, and is scheduled to be mandatory in v3. Is there any chance to have mentioned PR merged and published?

ashen780dimo commented 3 years ago

I'm having the same issue when using -f but sls create function --function testFunction --handler src/functions/testFunction.testFunction -p src/tests/ works.

Your Environment Information --------------------------- Operating System: win32 Node Version: 14.15.4 Framework Version: 2.55.0 Plugin Version: 5.4.3 SDK Version: 4.2.6 Components Version: 3.15.1