amazon-web-servicesnpmserverless-frameworkserverlessserverless-plugins

Serverless command "invoke test" not found. Run "serverless help" for a list of all available commands


I have my serverless.yml like below

service: omy-api

provider:
  name: aws
  runtime: nodejs14.x
  region: ${opt:region, 'us-east-1'}
  stage: ${opt:stage, 'devint'}
  memorySize: 128 
  timeout: 15 

custom:
  jest: 
    collectCoverage: true
    
functions:
  - ${file(config/Customer/delete.yml)}

plugins:
  - serverless-jest-plugin

in my package.json I have

{
  "name": "omy-api",
  "version": "1.0.0",
  "scripts": {
    "deploy": "sls deploy",
    "test": "jest"
  },
  "jest": {
    "collectCoverage": true,
    "coverageReporters": ["text-summary"],
    "coverageThreshold": {
      "global": {
        "branches": 90,
        "functions": 90,
        "lines": 90,
        "statements": -10
      }
    }
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "serverless": "^1.83.3",
    "serverless-jest-plugin": "^0.3.0",
  },
  "dependencies": {
    "jest": "^27.0.6"
  }
}

am following the https://github.com/nordcloud/serverless-jest-plugin documentation. when i run sls invoke test, I get the error

Serverless Error ---------------------------------------- Serverless command "invoke test" not found. Run "serverless help" for a list of all available commands.

I tried sls invoke test --help, but I get the same error.


Solution

  • If you want to run it by entering a command like below, you must first install serverless and the serverless plugins you use globally, for example

    npm install -g serverless
    
    npm install -g serverless-jest-plugin
    

    and run

    sls invoke test