Mocha tests stop abruptly with: Cannot find module 'pg-native' - node.js

Our mocha tests suddenly stop with this message on the console:
Cannot find module `pg-native`
No stack trace is shown, mocha doesn't render the normal output for the test. The test immediately stops.
If I disable the test in question, all tests run as normal.
Installing pg-native removes the error, but then mocha just hangs at that point instead.

As per this issue the problem is a result of running something that walks sequelize records in depth.
eg
expect(myObject).to.deep.equal(mySequelizeInstance);
changing to
expect(myObject).to.deep.equal(mySequelizeInstance.toJSON());
will solve it
Why?
There's two reasons for the above behaviour
Sequelize records override native getters and so traversing certain properties causes code to be executed. In this case, one of those properties ends up down a rabbit hole that causes require('pg-native') to be executed (and so the error)
The object contains circular references, and so the code hangs traversing the infinite references. Left long enough it will eventually fail when it exhausts the stack.

Related

how to clear JS heap

I have an issue with my project.
I began init git at the beginning of a project, but failed to push my changes to the repo. I was delaying my understanding of git until later, but it appears that the code gods have demanded I figure out how the hell it works.
After I npm run dev my project, I receive a JS stacktrace heap limit allocation failed error.
I tried discarding the whole pending changes file but receive a "you are on a git branch yet to be born". Considering my last name is Born, this project has become very personal. Can anyone direct me from here? My other idea was to can the whole project and begin a new one without source control, but I might as well figure out how to the fix this problem now.
That error indicates that you're basically running out of memory. This isn't surprising, since according to your code screenshot (you should always post your code in a code block, not as an image btw) your Header component is rendering another Header component in itself. Infinite loop, apparently one that caused you to run out of memory before you encountered a stack overflow error. I don't know exactly how the internals of React work, so that might be normal.

how to make a jest test fail at first time even using jest.retryTimes?

in my Jest test suite,
i use
jest.retryTimes(4)
because of the particular and instable architecture of the software. And this works as expected.
There are some test that must to pass at the first time so for these particular test i need to set
jest.retryTimes(1)
at the beginning of the test, restoring
jest.retryTimes(4)
at the end.
There are two problems :
The problem is this configuration is global, and test are executed
in parallel, so when this test start, it put 1 to jest retry for all
the test running at this moment. I would like to make only this
particular test fail the first time.
Jest Circus ignore the update of jest.retryTimes at the beginning and at the end
of the test, it keep considering 4 temptative before of raise the failure.
I read the documentation but I think I cannot obtain this result.
any suggestion?
Thanks

Mocha, go to the next file after timeout

I'm running my test files with script
"test": "node_modules/.bin/mocha *.test.js
but in the first test I'm sending to my Node.js server while(1); and causing it to timeout, simultaneously failing that test. That's the intended behaviour but how do I make mocha run the rest of the files after that?
There is an issue in Mocha's repository for your case.
Infinite loops seem to escape timeouts #1609
TL:DR
This is not possible in mocha(because of how node works).
You can read the interesting discussion about this problem.
The reason it blocks all the code is because of how node works.
The code is executed line by line totally in syncronous way.
The async magic happens with the node event loop .
But when you run infinite loop the event loop will be blocked because only one event can run at a time, and this event will never end:)

Fatal error: stale element reference: element is not attached to the page document in selenium with nodejs

I am facing this issue while running the UI regression test. I have used Typescript for automation in Selenium and I have around 80 test cases. So when executing all at once, it executes some of the test cases smoothly but after sometimes in one of the testcase this error comes up and stops the execution. I am using only one thread for running these tests.
"noOfThreads": "1",
There is no issue with the individual test cases as they work fine when running individually
StaleElementException occurs when the the driver tries to perform an action on an element which was once present in the DOM but does not exist anymore. For example, if you store an element in a variable, perform some changes which introduces variation in the DOM structure and the original element is lost, and now your driver tries to access it, this would fail.
In your case, when you are running the tests individually, there is no effect of one scenario on the next one. This is why the tests pass. However, when you run all of them together, this can introduce a change in the DOM.
Try to debug the test which failed by running a few tests before it.

VS2012 - Why is my main UI thread showing green debugging statements?

Edit : If you're seeing this same problem (and you're accustomed to NOT seeing this under VS2010) please comment below so I know it's not just me - but be sure to check Han's answer to make sure none of those scenarios appear...
I've been updating my app to run with .NET 4.5 in VS2012 RTM and noticing something that I don't quite understand and that is unexpectedly green highlighted statements (instead of yellow).
Now I'm well aware of what this is supposed to mean, and the IDE is even showing me a little explanation tooltip.
This is the next statement to execute when this thread returns from
the current function
However there's absolutely nothing asynchronous or thread based about this code. In this simple example I'm sure you'll agree that string.ToUpper() won't be off in another thread. I can step through the code no issue.
There's nothing else going on and I am on the main thread as you can see here.
I am using async and await and MVVM-Light (the above method is the result of a RelayCommand) but I still get this behavior even when the code path is directly off an event handler such as PreviewKeyDown.
If I create a new app I cannot duplicate this - the coloring is yellow as expected - even when using await.
Anybody got any idea? It's starting to drive me crazy!!
It is green when the current instruction pointer is not exactly at the start of the statement. Some common causes:
Common in threaded code, setting a breakpoint in one thread and switching context to another. The other thread will have been interrupted by the debugger at an entirely random location. Often in code that you don't have source code or debugging info for, like String.ToUpper(), the debugger can only show the "closest" source code
Using Debugger + Break All to break into the debugger. Same idea as above, the instruction pointer will be at a random address
Getting an exception in code you don't have debugging info for. The editor shows the last entry in the Call Stack that it does have source code for. You need the call stack window to see where the actual exception was raised. Or the Exception Assistant, its reason for being
Debugging optimized code. The jitter optimizer scrambles the code pretty heavily, making it likely that the debugger can't show the current location accurately
Having out-dated debugging info or editing the code while debugging
Debugging code generated by the x64 jitter, happens when the project's Target Platform setting is AnyCPU. The x64 jitter has a number of chronic bugs that are not getting fixed, generating incorrect debugging info is one of them. Problems that were not addressed until it was completely rewritten, done by the RyuJIT project and first available in .NET version 4.6. Targeting x86 in your EXE project is the workaround.
I understand that this is old post yet I would like to answer the question with my experience.
I have encountered same issue recently in one of my WCF application. After debugging and closely looking service logs and I find out that my code was giving this error because service was hitting max allowed limit for code execution and once the service hit max allowed time limit it was trying to offload the current debugging session.
ERROR IN GREEN STATEMENT: this is the next statement to execute when thread return
So avoiding this issue you can try to look any potential code(Code/Service Timeout or any other code block) which is trying to offload your currently executing code context and try to fix it, furthermore original explanation given by #Hans is still very much relevant for trouble shooting this issue.
Actually, I am also facing this issue. This is because I missed some layout component in landscape mode, So check all the Id's and components and Run, you will not get this error.

Resources