
In the case of an HTTP Server it stays running waiting to accept new requests. This works by running the scripts sequentially and it also means that the first script has to complete before the 2nd script will run. This means that If I had 2 scripts the following script would work.

I was already aware that I could run 2 scripts one after another using the & operator.
Npm run parallel travis how to#
The point of this exercise was not how to run multiple scripts it was to just run the tests to make sure the code they wrote was correct. This isn't a huge deal but when you're introducing new concepts to someone you want to remove as much friction as possible. This meant that in Visual Studio Code you need to open up a terminal, run npm run start and then open up a new terminal instance and run npm run test:e2e. In the first iteration of the exercise I asked the students to run both of them. Now that you have both of scripts created you need to find a way to run them both. node_modules/.bin/http-server " Running your npm scripts in parallel Now that you have it installed you can add a new script to start your http server.
Npm run parallel travis install#
You can install this globally but for this demo we will just install it as a dev dependency by running the following command: npm install -D http-server You can do some searching and find one that fits your needs but for us http-server was tiny and fast, 2 qualities we were looking for. Http ServerĪn easy solution to the problem of asking everyone to run the project manually is to install a small http server. This is the preferred workflow and something we will try and mimic. When the tests are finished you get the test results and the application is shut down. This will start the application up and then run the cypress integration tests. You can write end to end tests using Cypress and when you're ready to test you just run the command npm run test:e2e When working in a framework like VueJS the framework solves this problem for us. With that we can add a new test to our scripts section in our package.json " test:e2e " : ". Installing Cypress gives you access to some command line tools like the ability to run a headless version of the tests or to open them up in chrome./node_modules/.bin/cypress open You can install cypress using the following command: npm install -D cypress We won't be getting into what Cypress is but if you haven't heard of it or had a chance to play around with it I highly suggest checking it out. To get started create a new folder and create a new package.json by running the command npm -y. This article will assume you have some experience building modern web applications. If you want to follow along you can create your own project but it isn't necessary. We would also want this automated in case we run everything through some continuous integration build. This is a very a very tedious workflow and something we want to avoid. Second, what happens we want to grade our students exercises? This would mean that our instructors would have to start each project, run the test and record their score.

I could probably stick this in some configuration but again it doesn't feel right to me.

This works for development but about when it comes time to test? I suppose the instructions for the exercise could state "make sure your project is running before running the tests" but this introduces a couple of problems.įirst, if we do it this way I'm not sure we can always assume that the project will be running at That might be the case for most but I never like to just assume it. In some of our vanilla JavaScript examples you can run the them right from Visual Studio Code using the Live Server Extension. The problem is that I needed to run some end to end tests using Cypress but before doing so I needed the project to be running. We also use these tests as a way to grade certain exercises. When our students finish their exercises they are asked to run some tests to validate that their solution works. I was working on an exercise for our students and In the process I learned something new. How to run multiple npm scripts in parallel
