I have been working through Mosh’s Node course. I have been using current libraries, instead of the versions he uses. So far, I have found plenty of little issues, but I have not found any major problems that I could not get past as a developer with some significant experience coding, debugging, and looking through docs.
However, I went through his sections on testing and added more Jest tests to get up to high test coverage. And I discovered major problems suppressed by the option “–detectOpenHandles,” which I had been after an error message recommended I use this to debug. When I removed the option to get ready to deploy, I got many errors, and the pattern of error changed each time I ran the tests together. The errors went away when I ran the tests each one on their own. NOT GOOD.
I was able to quickly get past errors about the address/port by using port = 0 for the test environment, so the ports could be assigned automatically. Many errors existed beyond this one. And they were, as I said, chaotic.
According to the docs, this option “implies —runInBand." That option means, the test run slowly, because they all run serially in the current process instead of creating a worker pool. So by default, instead of one at a time, they all run in a random pattern. This means that the cleanup code for database collections interferes with other setup code. Hence the chaotic failures.
Mosh does setup and teardown so that each test should have a clean database. That is not the way that Jest works. The performance loss of running tests on a single process is not recommended. I cannot fathom how folks are solving this issue in real development environments. They may be refactoring their setup and teardown. They may be using separate databases for each test suite.
The other parts of the course that were “outdated” were still highly useful in my opinion. But in this case, the lessons conflict with the way the actual software runs. There appears to be a design issue, a clash of principles. I will need to go and essentially “relearn” this, which I wish I had known before. I would not have spent nearly as much time on this part. I already had a lot of trust from doing prior courses with Mosh, so I was surprised and confused for a while. But I can see some folks on the forum had a much harder time with this experience, possibly because it was one of their first with his content.
I am wondering if this part of the course should be removed or updated. Or have at the very least a note added about this. Is this particular part still useful?