Fail/terminate node.js process if Mithril Ospec tests fail - node.js

When I run unit tests via Ospec for Mithril, I can see if tests fail locally in the console.
What I'm looking for is a solution that will not allow a following Node.js build script to execute if one or more of the tests fail.
I don't want code to be pushed up to another environment/lane if the unit tests aren't passing.
I don't see how to accomplish this in the docs.
In Node, I'm running ospec && someBuildProcess.
The answer might be a Node.js thing, but I'm at a loss for what to look for now.

ospec calls process.exit(1) if any tests fail, and the command string you posted should work. I just verified it locally with the following setup:
https://gist.github.com/tivac/d90c07592e70395639c63dd5100b50a6
ospec runs, fails, and the echo command never gets called.
Can you post some more details about your setup?

Related

Test execution randomly aborted by an issue originated in the request-pipeline of Hammerhead (Testcafe e2e tests)

thank you for looking into this!
We are running a quite comprehensive testsuite (some hunderds of test) with the goal to make sure that our tracking implemantation works as expected. We are executing this tests via CI 4x a day. Since a few weeks we have random test aborts, which are unfortunately extremely hard to track and reproduce.
What is the Current behavior?
Errors: Unhandled promise rejection:
Error [ERR_HTTP2_INVALID_SESSION]: The session has been destroyed
at new NodeError (node:internal/errors:371:5)
at ClientHttp2Session.request (node:internal/http2/core:1702:13)
at DestinationRequest._sendRealThroughHttp2 (/home/ec2-user/actions-runner/_work/ds_cerberus/ds_cerberus/node_modules/testcafe-hammerhead/lib/request-pipeline/destination-request/index.js:51:32)
at DestinationRequest._send (/home/ec2-user/actions-runner/_work/ds_cerberus/ds_cerberus/node_modules/testcafe-hammerhead/lib/request-pipeline/destination-request/index.js:110:18)
at runMicrotasks (:null:null)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
For us it looks like a racing condition inside the hammerhead-lib which is used as a proxy for testcafe. But we have no idea how to fix this - or least make sure that not the whole suite of tests is aborted by it.
This is the stacktrace if the tests are aborted. Unfortunately this means that the execution of all tests is aborted and does not only affect a single test, which renders the whole suite for us pretty useless...
Steps to Reproduce
There seems to be more aborts if the tests are executed in the suite and not solely - but even there it is quite hard to identify a pattern.
TestCafe version
"testcafe": "^1.17.1",
Node.js version
node-version: '16.x'
Command-line arguments
testcafe --config-file .testcaferc-dev.json tests
The issue may be related to HTTP/2 requests. So, you can disable it using the following option: disableHttp2. Check if the issue is reproduced after that.
You can also try to increase timeouts, e.g. ajaxRequestTimeout and testExecutionTimeout.
If this does not help, please create a simple project where the issue is reproducible and share it here. We will research it on our side.

Mock test case get failed unexpectedly

When I locally execute my mock test in c# then my test case gets passed but when I queue my build to azure then some of the random test cases fail which was getting passed locally? Any solution on this?
I got to know this was getting failed because my mock object was static. Check my another question Why my few test case get failed after "Running all" controller and pass individually?

What is this error code in my tests? I didn't change any code

I have a NodeJS module that uses express and sequelize basically.
I have automated tests for it that use mocha, mock-require, supertest and nyc
This test suite used to run fine, and suddenly on a CI pipeline run, the suite started failing, and I only see this in the logs:
Process finished with exit code -1066598273 (0xC06D007F)
Anyone have any idea what this could be? I made no changes in the code whatsoever

MongoError: Cannot create collection users - database is in the process of being dropped

I have a REST API and I'm writing TDD for this project. My TDD is consisted of two parts: route and service. I chose to use Jest. I have a MongoDB database that I use for testing. When each test is completed, I reset my database using the afterAll() method. In this method, I run the mongoose.connection.dropDatabase function.
There is no error when I ran only one test file but when I run multiple test files, I get an error. The error message:
MongoError: Cannot create collection auth-db.users - database is in
the process of being dropped.
I share sample codes with you:
users.route.test.ts:
https://gist.github.com/mksglu/8c4c4a3ddcb0e56782725d6457d97a0e
users.service.test.ts:
https://gist.github.com/mksglu/837202c1048687ad33b4d1dee01bd29c
When all my tests run, "sometimes" gives errors. I wrote the above error message. The reason for this error is that the reset process still continues. I can't solve this problem. I'd appreciate it if you could help.
Thanks.
https://jestjs.io/docs/en/cli.html#runinband
What you are looking for is --runInBand command. Which makes jest to run serially instead of creating a worker pool of child processes that run tests

Jest async test timing out in docker

I need a little help with Jest testing running in a docker container. Please find my repo here (this is the only branch with existing tests). I am running two tests, the first of which works fine, the second has a jasmine timeout error after 2 seconds. Now if I go through the motions, call the API and hit the function that I'm testing all is dandy, the user gets created and a user Object is returned - however the test just seems to fail as soon as it hits the below.
await internals.checkUserIsUnique(data.email)
I have tried returning true above this, which causes the test to fail (which makes sense) but as soon as we hit async code it will end up timing out.
FAIL src/services/tests/users.test.js
✓ Tests running (2ms)
✕ Creates user (2007ms)
● Creates user
Timeout - Async callback was not invoked within the 2000ms timeout specified by jest.setTimeout.
at node_modules/jest-jasmine2/build/queue_runner.js:72:21
at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:633:19)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 passed, 2 total
Snapshots: 0 total
Time: 3.462s
Ran all test suites.
Now I'm not sure if this issue is caused by something idiotic I've done in my actual node functionality (which wouldn't surprise me, only it seems to work outside of tests) or if I've botched the Jest setup somehow (seems most plausible) or this issue is actually coming from the fact that the code is running in Docker. Any help would be much appreciated.
Any further info needed please ask!
Edit
As per the below suggestion (thanks stijndepestel) I've tried this outside of docker, same issue so evidently not that. Had to point this at a remote DB so not that connection either.

Resources