How to silently kill wiremock after Cypress test are executed? - npm

I have an all-in-one npm script that:
Starts a React application
Starts Wiremock server in playback mode
Executes Cypress tests silently
For that I'm using concurrently:
"cypress:runner:one-shot": "concurrently npm:wiremock:playback npm:start:mock npm:cypress:execution:recorded",
After tests are executed I have to shut down the application and WireMock server.
For that, I added the following parameters to concurrently command:
--kill-others --success !command-0,!command-1
I need the all-in-one command to finish with an exit code 0.
For some reason is still finishing with a 1 (given that WireMock server is killed)
Is there any way to ignore the exit codes of any of those commands?
Just in case:
wiremock:playback is something like
"wiremock:playback": "npx wiremock --proxy-all '...' --verbose --port 3001 --enable-stub-cors --root-dir wiremock",

You can shut down WireMock by making a POST request to /__admin/shutdown (on the main host/port you configured WireMock to run on).

Related

How to force exit an vue cli thread on completion in a deploy script (e.g. ctrl c equivelant)

I'm using Laravel Forge to run a simple deploy script. npm run build calls 'vue-cli-service build'.
Script below. The script 'ends' on
DONE Build complete. The dist directory is ready to be deployed.
INFO Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html
but the thread does not quit, which causes issues in forge (e.g. thinks it's timed out or failed when it hasn't).
How do I do the equivelant of ctrl-c in a terminal once this has finished, in the deploy script? I've seen threads on trap SIGINT / trap etc. but I'm still not really sure how to implement it.
It may be that I just include the exit callback fix noted here: Vue-cli-service serve build completion callback?
git pull origin $FORGE_SITE_BRANCH;
npm run build;
( flock -w 10 9 || exit 1
echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock
if [ -f artisan ]; then
$FORGE_PHP artisan migrate --force
fi```
Try out to add Daemon termination command to the end of your deployment script
$FORGE_PHP artisan horizon:terminate

Selenium side runner + chromedriver tests with docker not running

I am trying to get selenium side runner to run some tests using docker, to include in our CI.
I am able to run the tests locally in my machine by running:
selenium-side-runner C:\path-to-tests\tests-selenium.side
This is windows host.
I am trying to do the same using docker locally, so afterwards I will migrate this to our Teamcity.
First I am running the selenium server container:
docker run -d -p 4444:4444 --name chromedriver selenium/standalone-chrome:3.4.0
Afterwards I run the selenium side runner container:
docker run -v C:\path-to-tests:/sides --link chromedriver:chromedriver nixel2007/docker-selenium-side-runner
I have to link the containers otherwise I get an error saying that the container can't connect to chromedriver:4444
I also have to mount the volume where my tests are.
When I do this and run, I get the following error:
Test suite failed to run
WebDriverError: Unable to parse new session response
What am I missing here?
UPDATE:
I also tried different versions of the selenium/standalone-chrome container, selenium/standalone-chrome:3.4.0, selenium/standalone-chrome:3.141.59-xenon and selenium/standalone-chrome:latest
All fail with different errors.
SECOND UPDATE:
I have been able to get the tests to run, both locally and in teamcity. One of the issues that I am facing right now is that docker-compose seems to hang. Not sure if this is container related, or docker-compose related.
When I run the tests, the selenium side runner container exits with code 1 and I do not get back to the host console prompt, it stays forever waiting for something to happen.
The error is this:
selenium_selenium-side-runner_1 exited with code 1
I have gotten the docker-compose file from here:
https://github.com/nixel2007/docker-selenium-side-runner/blob/master/docker-compose.yml
Any clues on what I might be missing?

Collecting Coverage Reports in Jest with Integration Tests

I have a bunch of tests setup with Jest that test Express server endpoints in the same repo. In order to accomplish this testing, I have Jest spinning up an Express server in the beforeAll() method. When I run Jest with the --coverage flag, I get coverage information for just the scripts that were run in order to start Jest and no reporting on the scripts that were triggered by hitting the endpoints. That makes sense, but is there a way to get coverage information on the endpoint code?
Snippet of test code:
const rp = require('request-promise')
describe('testFunctions', () => {
beforeAll(done => {
app.listen(config.PORT, async () => {
done()
})
})
it('hit endpoint', async () => {
const response = await rp({ uri: '/testFunctions', method: 'POST' })
expect(response).toEqual('response)
})
})
I'm trying to get a coverage report for all of the server code hit with the /testFunctions request.
This is the solution that worked for me. It required a bit of refactoring, but I think it was cleaner in the end. In my ecosystem, we are running a Parse Server as middleware with an Express server, but this could apply to anyone who needs to run a separate server with the tests.
So to get my server in a place that nyc (the coverage reporting tool I'm using) could monitor, I abstracted the server initialization completely out of the jest test suite and created a special npm script to run it in an entirely separate process.
NPM Script (package.json):
"scripts": {
"coverage": "nyc --silent npm start & ./listen_on_port_5000.sh && jest test/cloud/integration && kill $(lsof -t -i tcp:5000) && nyc report --reporter=html",
}
listen_on_port_5000.sh
while ! nc -z localhost 5000
do
sleep 0.5
done
So how does this work?
nyc --silent npm start runs which is the normal command we would run to start our server with Express and Parse but with the prepended nyc part with the --silent flag so that nyc can run in the background and watch the server code.
Because we know that the server always starts on port 5000, we run the start script in the background and start a separate process running a shell script (listen_on_port_5000.sh) to wait for the server to boot up.
Once the listener script detects anything running on port 5000, the npm script moves onto the jest command (all while the Express server is up and running).
When Jest finishes running, the final script runs a kill script to close the server running on port 5000.
We then run a second nyc script to generate the report that it collected in the first script. The generated report can be found in your project's directory under /coverage/lcov-report/ (or you can use a different coverage reporter.

Detox UI Testing - Tests time out when running on CI

I'm running react-native android integration tests headlessly using the detox framework on Ubuntu 18.04.
The line that I use to run my test suite as a whole is:
detox test -c android.emu.ci --headless --cleanup --take-screenshots failing --detectOpenHandles. This runs 7 tests.
When I run the tests like this the first test runs successfully, and then the second test fails, as it seems like the emulator is offline.
If I run the tests individually with a 15 second gap between them eg:
- detox test post.spec.js -c android.emu.ci --headless --cleanup --take-screenshots failing --detectOpenHandles
- sleep 15s
- detox test post.report.spec.js -c android.emu.ci --headless --cleanup --take-screenshots failing --detectOpenHandles
- sleep 15s
They all complete without failing, so the tests are not the culprit.
I have tried adding a sleep in the afterEach for each test, and as the last action in each test, but neither of these have been successful.
I'm looking for suggestions/direction on what to do to get the tests to wait for the emulator to be ready before executing.

How to run ember-cli test in jenkins

How can i run Ember-cli test in jenkins?
Currently to run the tests i added a build step "Execute shell" with the following in it:
ember test --silent --config-file ${WORKSPACE}/testem.json > ${WORKSPACE}/xunit-ember-dev.xml;
But it doesn't work, this is the output
<testsuite name="Testem Tests" tests="0" failures="0" timestamp="Thu Feb 12 2015 14:20:24 GMT+0100 (CET)" time="0">
</testsuite>
If I do the same manually in the workspace as jenkins user I got the expected results.
<testsuite name="Testem Tests" tests="70" failures="0" timestamp="Thu Feb 12 2015 15:06:40 GMT+0100 (CET)" time="15">
<testcase name="PhantomJS 1.9 Integration - Homepage: Should display the homepage"/>
<testcase name="PhantomJS 1.9 Integration - Profile: Should display the profile sections"/>
...
Every time I make Jenkins run the tests, he find no tests.
Thanks
Just add an Execute Shell step that runs:
npm run test > results.tap
This command tells npm to run a script called test and redirect the output to a file called results.tap. (The purpose of redirecting to results.tap is so you can take this file and hand it to Publish TAP Results post-build step and get pretty charts of test runs.)
In your package.json, you should have a block that looks like this:
"scripts": {
"start": "ember server",
"build": "ember build",
"test": "ember test"
},
(This is the default from ember-cli 1.13.8 and likely a few versions earlier than that.)
Using this approach, you don't need to have ember-cli globally installed on your build system: it will simply pick it up from the project's node_modules folder.
Caveat emptor: you'll likely find some blogs/forum posts that tell you to run npm run test | tee results.tap. This will run the tests, however, it will eat the return code. (If the test run fails, the npm process exits with a return value of 1, but since you're piping output to a second command (tee), the return code of that command is what jenkins sees. The net result is that jenkins will interpret test failures as success and keep on running build steps.)