'Test passes locally, but consistently fails in a Jenkins job - Node, Express, Mocha
I have a Mocha integration test as a part of a Node test script. After merging the new functionality, the test passed consistently on a release branch locally. After merging the code into master and attempting to build a Jenkins job on a different environment (let's call it env B), the very same test consistently fails in that environment.
The test contains a single Chai shallowDeepEqual assertion. The test fails because (for some reason) expected and actual results have items in a different order. Obviously, editing the assertion is not an option.
What I've tried:
- Running npm install locally, some packages were indeed modified, but it had no effect on the test
- Checked node versions on local and on env B. Changing local version to exactly the one used on env B (I use nvm, node version is v12 LTS) had no effect on the test.
After some digging, I found that the problem could be related to Jenkins caching, but I found no trivial way to force-clear cache before a build.
Solution 1:[1]
After npm install (1), I noticed that the package-lock.json file had a diff from the current branch. After committing and merging the diff, the Jenkins job is now passing.
I assume that tests were failing because Jenkins was using cached dependencies. After I committed the fresh version of package-lock.json, Jenkins might have noticed a dependency change and rebuild cache.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DIRECTcut |
