How do a run the servers I need as well as the e2e tests in a teamcity build step(s)?
I have protractor e2e test for my angular 2 application. (I have a funny mix of angular-cli and gulp, but bear with me.)
Here's how I run my tests locally. I need three console windows (w1,w2,w3).
w1) First thing I need to do is start my application:
npm start
-> Which I have defined in package.json as ng serve -prod
w2) Then start the fake back-end, an express webserver
npm run gulp e2e-server
-> I've defined "gulp": "gulp"
in my package config, because gulp
won't be recognised on teamcity.
3w) And then finally I can run my e2e tests
npm run e2e -- e2e/protractor-teamcity.conf.js
I've defined "pree2e": "webdriver-manager update"
and "e2e": "protractor"
in my package config
Then...
I need to manually stop the two servers I started.
Something like this hack will work:
npm run gulp e2e-clean && start "MyWindow" cmd /c "start npm start && npm run gulp e2e-server" && ping -n 31 127.0.0.1 >nul && npm run e2e -- e2e/protractor-teamcity.conf.js
But start
creates console windows that will never stop. I'm not sure what the consequences of this are (I doubt this will run successfully twice). The ping is a sleep hack, which isn't ideal either.
Has anyone found a solution for running a command "in the background" during the test run and then killing it afterwards?
So, this is a terrible hack. The sort of hack that suggests something is deeply wrong, but ho-hum:
When ng serve runs it will change the console window title to "angular-cli", when gulp runs it which change it to "gulp" (or "select gulp"). I don't expect anything else will be running with these titles. This is enough to write
__kill-running-windows
to go and kill these windows.Package.json:
The code (the interesting parts anyway, I'll leave what eg gulp serve to the readers imagination):
For some reason, moving more code into gulp seemed to make the builds never finish on teamcity. But here's the e2e I use locally, which is more gulp based: