I've been tackling a project in Angular and recently encountered an issue. Running 'npm run test' locally shows that my tests are passing without any problems.
it('should create', () => {
expect(component).toBeTruthy();});
However, when I push these changes to Bitbucket, the build fails on Jenkins.
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cfbfbda0a5aaacbb8fffe1ffe1ff">[email protected]</a> swb:test
[2024-01-23T15:09:14.375Z] > npm run test:ci
[2024-01-23T15:09:14.870Z]
[2024-01-23T15:09:14.870Z] > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c7c7e6366696f784c3c223c223c">[email protected]</a> test:ci
[2024-01-23T15:09:14.870Z] > ng test --watch false --code-coverage --browsers ChromeHeadlessForDocker --progress false
[2024-01-23T15:09:30.458Z]
[2024-01-23T15:09:30.458Z] START:
[2024-01-23T15:09:30.458Z]
[2024-01-23T15:09:30.458Z] Error: error TS2688: Cannot find type definition file for 'jest'.
[2024-01-23T15:09:30.458Z] The file is in the program because:
[2024-01-23T15:09:30.458Z] Entry point of type library 'jest' specified in compilerOptions
[2024-01-23T15:09:30.458Z]
[2024-01-23T15:09:30.458Z]
... (error details continue)
<script returned exit code 1
Why do my tests pass locally but fail on Jenkins? How can I resolve this issue? I'm really struggling to find a solution and it's becoming quite frustrating. :( Ps: I faced a similar error locally but managed to fix it using this link: Angular Unit Tests Property 'toBeTruthy' does not exist on type 'Assertion'
I've tried various suggestions from Stack Overflow! I even checked for any Docker-related issues and reviewed the Jenkinsfile, but couldn't identify anything unusual. To ensure compatibility between my local setup and Jenkins, I made the following adjustments:
npm_nodejs_version: 20.8.1
npm_version: 10.1.0