Is it possible to start serverless-offline by Javascript?

Asked

Viewed 224 times

5

The plugin serverless-offline is used to start a framework-based application Serverless. To start, the command is used serverless offline [options] or sls offline [options]

Is it possible to start it through Javascript? Something like:

const slsOffline = require('serverless-offline');

slsOffline.start(options)
    .then(() => {/* ... */});

Reason: testing the code. In the documentation it is suggested to test handlers directly, but this may pass errors in the serverless.yml, how to write the route name, parameter or method incorrectly, or even forget to create the route after creating Handler

I tried to run the command that starts the application and runs the tests together:

npm run start && npm run test

However, as the start If it keeps running until it is stopped and the application stops, the tests are never run or run after the application has stopped. Running scripts on different terminals is complicated to automate development and deployment processes, such as using Bitbucket Pipeline to run build, test and deploy

  • It is in English but I believe this site can help https://serverless-stack.com/chapters/serverless-nodejs-starter.html

  • This might help you: https://github.com/dherault/serverless-offline#Usage-with-invoke

1 answer

-2

The easiest way for you, is to do unit tests so you don’t have to start your entire application to be able to do your non-unit tests.

But if you still want to do this, you should look for how to execute command line commands via Avascript. This link can be useful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.