Well, since you didn’t take the time to update the question information with the NPM "scripts" object, then I will try to take a picture in the dark.
First of all, due to your wording, I can interpret your question in two ways:
- a.) you want to run E2E tests separately, without your server (which runs through
npm start ); - b.) , you want to run E2E tests through
npm start without starting your server;
a.) If you want to run your scripts separately, then, seeing that you are using Mocha , you can run them through: ./node_modules/.bin/mocha <pathToTests>/<testFile> .
Now, since you stated in your question that you are using the npm test script, then this should be the best switch for linking the execution of E2E tests to:
package.json (Scripts object):
"scripts": { "test": "mocha --reporter spec <pathToTests>/<testFile>", "start": "node <yourServerName>.js" },
Note that mocha <pathToTests>/<testFile> equivalent to ./node_modules/.bin/mocha <pathToTests>/<testFile> because NPM searches for binaries inside node_modules/.bin and when Mocha was installed, it set it to this directory.
Note. . Many packages have a bin or .bin section that declares scripts that can be called from NPM, similar to Mocha. If you want to know what other binaries you can run this way, just type ls node_modules/.bin .
b.) . In this care, I think your problem may be related to the fact that NPM did not execute some script values based on the contents of the package. In particular, if you have a server.js file in the root directory of your package, then npm will start the server.js command by server.js .
So, if you start E2E tests via npm start , having this ( "start": "mocha <pathToTests>/<testFile>" ) in package.json is the server.js in the root folder of your package, then npm will start the command by default node server.js .
In this case, you can either move the script server to another location in the project, or change the switch you use to run the E2E tests ( see section b.) ).
Hope this solves your problem, and if not, we look forward to this package.json "scripts" object so that we can really see what is happening. :)
Hooray!