angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.78k stars 11.98k forks source link

Support for jest-angular-test-verifier when using @angular-devkit/build-angular:jest #25696

Open Neizan93 opened 1 year ago

Neizan93 commented 1 year ago

Command

test

Description

As Angular CLI is starting to provide support for Jest in Angular 16, I would like to propose the addition of support for the jest-angular-test-verifier extension or a similar feature. This feature would enable developers to detect files that lack corresponding spec.ts files, helping to ensure comprehensive test coverage in Angular projects.

Benefits

jest-angular-test-verifier npmjs: https://www.npmjs.com/package/jest-angular-test-verifier

Describe the solution you'd like

The proposed solution is to integrate the functionality of jest-angular-test-verifier or a similar tool into Angular CLI. This would involve creating a built-in mechanism that can analyze the project's file structure and identify files that do not have associated spec.ts files. The tool should offer configuration options to customize the file extensions to check, define exclusions, and set exclusion rules based on content.

Describe alternatives you've considered

While the proposed solution suggests integrating jest-angular-test-verifier directly into Angular CLI, an alternative approach could involve developing a dedicated and more sophisticated solution tailored to Angular projects. By leveraging the power and familiarity of Angular's codebase, the CLI team could create an integrated tool that offers more advanced features and optimizations for detecting missing spec.ts files. This approach could lead to a more seamless and tightly integrated experience for Angular developers.

I appreciate your consideration of this feature proposal and look forward to the possibility of seeing this enhancement added to Angular CLI. If you have any questions or need further details, please let me know. Thank you!

dgp1130 commented 1 year ago

This is an interesting tool and I can definitely see the value of it to the Jest ecosystem. I certainly agree that (almost) every .ts file should have an associated spec.ts file and this isn't trivial to enforce today.

I'm hesitant to add this to Angular projects by default as we typically try to keep our dependencies as minimal as possible. That said, I think it should definitely be possible for applications to add this kind of tool if they choose to. Currently we're experimenting with not exposing the Jest configuration, so this is an interesting use case. I'm curious if there is a way to provide a similar tool without necessarily being coupled to Jest at all?

For example, if this is looking at file paths, could it just check the source file tree for spec.ts files and error for any missing files? That seems like something which could work for Karma and Web Test Runner in addition to Jest and wouldn't rely on a potentially brittle config file integration. Is there a particular reason you went with a Jest integration specifically?

The other thought which comes to mind is whether code coverage could help here. That would contain all the information about which files were tested and you could check that for any files missing a spec.ts file. I'm not sure that's better than just looking at the source tree, but it's one other avenue to consider.