DEV Community

Victor Shelepen
Victor Shelepen

Posted on

Start server and test scripts - NPM script - ready solution.

Summary I have made my alternative finding different pitfalls. Meanwhile We were applying the library start-server-and-test to our solution. Surprisingly start-server-and-test covered all pitfalls. The solution solves the problem.

Image description

It is a simple script and we need to understand it. It does how it is written. It runs the server and then tests it. For details check the documentation page of start-server-and-test

Pitfalls:

  • All processes have to be ordered.
  • Pipes have to be disposable to be finished.
  • Tests need to know when the server starts to start testing.
  • The script has to know when tests are finished to terminate all processes.

It takes only three parameters:

  • The first: To run the server.
  • The second: Server path. Address to wait for its availability.
  • The third: Test commands.

How it works
The script runs the first to start the main development server and waits until it is up. The second parameter is the server path that the script checks if the development server is available. The development server continues running. The script runs tests that are set in the third parameter. The script waits for the finish of the tests. When tests are passed the script terminates the development server and disposes of the main thread.

P.S. It should help you to start using the script faster.

Top comments (0)