简体   繁体   中英

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:

  1. Running npm install locally, some packages were indeed modified, but it had no effect on the test
  2. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM