Reputation: 4360
I have a basic Angular 6 app with e2e tests setup by default.
We make CRUD operations on a test database (the backend with the test environment should be running before starting the e2e tests).
The idea is to request a specific endpoint that returns true if the test environment is running. (backend in an express server)
In the very first spec I can make that request but throw new Error() doesn't stop the tests.
I've found some npm packages forcing the tests to exit on the first failure (jasmine fail whale and jasmine fail fast) but I don't want my tests to stop on any other exception than the wrong environment.
I tried making this test in protractor.conf.js in the onPrepare() method. I can throw new Error() there but I cannot make an http request (even basic XmlHTTPRequest is not defined)
What are my solutions to make sure the tests are run only when the right environment is running?
Upvotes: 1
Views: 909
Reputation: 10447
process.exit()
seems to be a good enough solution for your use case.
Upvotes: 1
Reputation: 2814
You can use the jasmine done function for your case.
it('should do something', (done) => {
try {
// doing something and an error happend
throw Error('failure');
} catch (error) {
done.fail(error);
}
});
Test will fail and be marked as failed and will abort future testing in the current suite "describe"
Upvotes: 0